Commit Graph

915 Commits

Author SHA1 Message Date
KOBAYASHI Shuji 7ce5d33947 Integrate mrb_str_inspect and mrb_str_dump 2019-10-10 19:50:48 +09:00
KOBAYASHI Shuji 882bc80dd0 Add tests for #4746 2019-10-03 16:59:18 +09:00
KOBAYASHI Shuji 198683e914 Simplify arguments check in String#rindex
Also fix document about type of the first argument.
2019-09-27 17:13:57 +09:00
KOBAYASHI Shuji 549317a36b Fix Fixnum overflow test in Integer#<< test
- Skip when `MRB_WITHOUT_FLOAT` is defined.
- Make `Fixnum` overflow even when `MRB_INT64` is defined.
2019-09-23 21:59:35 +09:00
KOBAYASHI Shuji e61095426b Simplify arguments check in String#index
Also fix document about type of the first argument.
2019-09-19 20:19:38 +09:00
KOBAYASHI Shuji 2f7175442f Fix Fixnum#(to_s|inspect) argument specs
Before this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  trace (most recent call last):
    [0] -e:1
  -e:1: 'to_s': wrong number of arguments (1 for 0) (ArgumentError)

After this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  "11"
2019-09-17 09:28:51 +09:00
Yukihiro "Matz" Matsumoto 04b098d000 Move tests related to getbyte, setbyte, byteslice` to core. 2019-09-11 18:49:08 +09:00
Yukihiro "Matz" Matsumoto 9d08025b8b Revert part of #4225
Since in mruby, Integer and Float interchange frequently (mostly on
overflow), so adding explicit `.0` can cause problems sometimes.

For example:
https://github.com/mattn/mruby-json/pull/40
https://github.com/pepabo/mruby-msd/pull/13
https://github.com/mattn/mruby-json/pull/42
2019-09-07 22:27:30 +09:00
takumakume 6c4278144a add assert_not_nil method 2019-09-05 19:51:54 +09:00
dearblue 414ab682f3 Add String#rindex test for invalid UTF-8 string 2019-08-17 11:44:27 +09:00
dearblue cf5f290fa0 Fix String#rindex test for UTF-8 string 2019-08-17 11:44:27 +09:00
KOBAYASHI Shuji 1e9cb74cc6 Change second argument to %l of mrb_vformat() to size_t from mrb_int
- `size_t` is more commonly used.
- `len` argument of `mrb_str_new()` is `size_t`.

NOTE:

The test for `%l` is temporarily disabled because adding a new type to
`mrbgems/mruby-test/vformat.c` causes an error (memory error?) on Visual
Studio 2017 in AppVeyor.
2019-08-03 19:42:22 +09:00
KOBAYASHI Shuji a4243360a2 Fix mrb_vformat("%f") with MRB_USE_FLOAT
It potentially not work when `mrb_float` is `float` because `float` variable
in variable length arguments is promoted to `double`.

Also I fixed build with `MRB_WITHOUT_FLOAT`.
2019-08-03 11:54:45 +09:00
KOBAYASHI Shuji d1817e7791 Change the mrb_vformat specifier %d for int
It potentially breaks, for example, in the case of `mrb_int` is 64-bit
and more smaller type is passed by `%d`. In fact, the problem could
become apparent when I used `%d` to `backtrace_location::lineno` in
`src/backtrace.c:mrb_unpack_backtrace()` on AppVeyor.

Therefore, change `%d` for `int` (not `mrb_int`) so that it can be
used mostly without casting.
2019-08-02 19:22:08 +09:00
KOBAYASHI Shuji eea42e06af Add new specifiers/modifiers to format string of mrb_vfromat()
Format sequence syntax:

  %[modifier]specifier

Modifiers:

  ----------+------------------------------------------------------------
  Modifier  | Meaning
  ----------+------------------------------------------------------------
      !     | Convert to string by corresponding `inspect` instead of
            | corresponding `to_s`.
  ----------+------------------------------------------------------------

Specifiers:

  ----------+----------------+--------------------------------------------
  Specifier | Argument Type  | Note
  ----------+----------------+--------------------------------------------
      c     | char           |
     d,i    | mrb_int        |
      f     | mrb_float      |
      l     | char*, mrb_int | Arguments are string and length.
      n     | mrb_sym        |
      s     | char*          | Argument is NUL terminated string.
      t     | mrb_value      | Convert to type (class) of object.
     v,S    | mrb_value      |
      C     | struct RClass* |
      T     | mrb_value      | Convert to real type (class) of object.
      Y     | mrb_value      | Same as `!v` if argument is `true`, `false`
            |                | or `nil`, otherwise same as `T`.
      %     | -              | Convert to percent sign itself (no argument
            |                | taken).
  ----------+----------------+--------------------------------------------

This change will increase the binary size, but replacing all format strings
with new specifiers/modifiers will decrease the size because it reduces
inline expansion of `mrb_obj_value()`, etc. at the caller.
2019-08-01 13:24:52 +09:00
Yukihiro "Matz" Matsumoto 7dae0ec74c Merge pull request #4606 from shuujii/refine-message-to-skip-in-nested-assert
Refine message to `skip` in nested `assert`
2019-07-30 14:41:09 +09:00
KOBAYASHI Shuji 44381f0a0c Refine message to skip in nested assert
- I think "Info" is used only to `skip`, so change to "Skip".
- Changed the default value of `assert` and specify the argument explicitly
  at the caller of `assert` because it is unnatural "Assertion failed" is
  output even though the assertion doesn't fail.

== Example:

  def assert_foo(exp, act)
    assert do
      assert_equal exp[0], act[0]
      assert_equal exp[1], act[1]
    end
  end

  def assert_bar(exp, act)
    assert do
      skip
    end
  end

  def assert_baz(exp, act)
    assert do
      assert_equal exp, act
      assert_bar exp, act
    end
  end

  assert 'test#skip_in_nested_assert' do
    assert_baz 1, 1
  end

  === Before this patch:

    ?..
    Info: test#skip_in_nested_assert (core)
     - Assertion[1]
        Info: Assertion failed (core)
         - Assertion[1-2]
            Skip: Assertion failed (core)
      Total: 3
         OK: 2
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 1

  === After this patch:

    ???
    Skip: test#skip_in_nested_assert (core)
     - Assertion[1]
        Skip: assert (core)
         - Assertion[1-2]
            Skip: assert (core)
      Total: 3
         OK: 0
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 3
2019-07-30 13:05:01 +09:00
KOBAYASHI Shuji 5091d047c0 Fix "Warn if assertion is missing inside assert"; ref ff43b2b9 2019-07-29 21:40:58 +09:00
Yukihiro "Matz" Matsumoto ff43b2b97c Fixed a conflict between #4407 and #4540 2019-07-29 01:25:58 +09:00
Yukihiro "Matz" Matsumoto 2ebc6d5b6f Merge pull request #4407 from shuujii/add-assert_raise_with_message-and-assert_raise_with_message_pattern
Add `assert_raise_with_message` and `assert_raise_with_message_pattern`
2019-07-29 01:05:26 +09:00
Yukihiro "Matz" Matsumoto cd8fc9bcb8 Resolved conflicts in #4320 2019-07-29 01:02:03 +09:00
KOBAYASHI Shuji 7675fcb5d3 Fix Module#dup to frozen module
Before this patch:

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> true

After this patch (same as Ruby):

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> false
2019-07-20 22:41:57 +09:00
KOBAYASHI Shuji 9873d5e0b9 Fix String#* test with MRB_WITHOUT_FLOAT 2019-07-18 17:51:02 +09:00
KOBAYASHI Shuji 9d2272ec2c Fix String#[] test 2019-07-17 20:09:37 +09:00
Yukihiro "Matz" Matsumoto d605b72c1d Merge branch 'master' into i110/inspect-recursion 2019-07-17 10:35:41 +09:00
Yukihiro "Matz" Matsumoto b4cdced22f Enumerable#detect {and #find} should call ifnone; fix #4484
It's an error in ISO specification; 15.3.2.2.4 and 15.3.2.2.7
2019-07-13 18:05:01 +09:00
dearblue e4249b1b9e Add UTF-8 test for String#index 2019-07-11 22:09:16 +09:00
KOBAYASHI Shuji c8a7d0ab95 Fix the order of "expected" and "actual" in test/t/range.rb 2019-07-09 13:13:13 +09:00
KOBAYASHI Shuji 32c2aa10c7 Fix Numeric#step to infinity; ref. #4555 2019-07-07 22:10:32 +09:00
KOBAYASHI Shuji 97c9e6b000 Fix include, prepend and extend to frozen object 2019-06-30 15:06:39 +09:00
Yukihiro "Matz" Matsumoto cf69724083 Merge pull request #4540 from dearblue/assert-nesting
Nested `assert` for mrbtest
2019-06-29 21:38:32 +09:00
dearblue 40030a5dbc Add test for String#[]= 2019-06-29 14:41:43 +09:00
dearblue 5f9034e428 Nested assert for mrbtest
When nesting `assert` used in test, it is indented and displayed.
Assertion numbers are concatenated by `"-"` at this time.

The purpose is to match the apparent numbers when failing with `assert_mruby`
which is defined by `mrbgems/mruby-bin-mruby/bintest/mruby.rb` for example.

Child assertions "skip" and "info" are reported as parent assertions "info"
and `$ok_test += 1`. The child assertions "ko" and "crash" are reported as the
parent assertion "ko" and `$ko_test += 1`.

When child assertions are mixed, "ko" takes precedence.

Incompatibility:

- `$mrbtest_assert_idx` takes `nil` or an integer array object.
  So far it was `nil` or an integer.
- `$asserts` points to the top of the internal stack in the `assert`.
- `$mrbtest_assert` points to the top of the internal stack in `assert`.
2019-06-29 11:54:10 +09:00
KOBAYASHI Shuji bc3176da63 Use __ENCODING__ in tests
It cannot be used for `String#size` test if judging whether or not `MRB_UTF8_STRING` is defined by result of `String#size`.
2019-06-28 19:26:29 +09:00
KOBAYASHI Shuji ad8473bd66 Add modification tests for immediate value 2019-06-27 18:47:48 +09:00
dearblue 5af8a9777b Add test for one UTF-8 charactor 2019-06-22 22:58:08 +09:00
KOBAYASHI Shuji c43ff6fa40 Move Kernel#__send__ test to core from mruby-metaprog 2019-06-21 22:02:29 +09:00
KOBAYASHI Shuji 030dd6655e Fix cvar, ivar, const and method can be removed to frozen object 2019-06-16 20:43:23 +09:00
Yukihiro "Matz" Matsumoto 04999e969f Merge pull request #4495 from shuujii/remove-Kernel-global_variables-from-core
Remove `Kernel#global_variables` from core
2019-06-10 15:42:33 +09:00
KOBAYASHI Shuji ffb700dea0 Fix missing assertions in test/t/syntax.rb 2019-06-09 18:27:28 +09:00
KOBAYASHI Shuji 2e160f53db Remove "Check the usage of a NUL character" test
Because there is not assertion in this test and NUL character literal is
used in other tests.
2019-06-08 22:32:19 +09:00
KOBAYASHI Shuji 4b83fe8b04 Remove Kernel#global_variables from core
This method is defined in `mruby-metaprog` gem.
2019-06-07 22:02:43 +09:00
KOBAYASHI Shuji dc1905e1bd Fix missing assertions in test/t/module.rb 2019-06-05 19:13:36 +09:00
KOBAYASHI Shuji a97a455c03 Use $undefined.equal?(obj2) instead of obj2 == $undefined in assert.rb
In case `obj2.==` is broken.
2019-05-27 21:43:55 +09:00
Yukihiro "Matz" Matsumoto 7f1f499b22 Merge pull request #4400 from shuujii/fix-name-assignment-to-frozen-anonymous-class-module
Fix name assignment to frozen anonymous class/module
2019-05-15 15:47:02 +09:00
KOBAYASHI Shuji 0692f7916c Simplify conversion process for i in mrb_get_args() 2019-05-03 13:39:19 +09:00
KOBAYASHI Shuji 4bf6b8c136 Refine the default values of flunk
The default message for the second argument should be set to the first
argument because only one argument is normally specified.
2019-04-29 11:34:41 +09:00
KOBAYASHI Shuji 1fb635ac03 Add assert_raise_with_message and assert_raise_with_message_pattern 2019-04-26 21:48:40 +09:00
KOBAYASHI Shuji 8fa3995a1a Singleton class of frozen object should be frozen
Before this patch:

  p (class << Object.new.freeze; self end).frozen?                #=> false
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> false

After this patch / Ruby:

  p (class << Object.new.freeze; self end).frozen?                #=> true
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> true
2019-04-25 19:48:40 +09:00
KOBAYASHI Shuji 4720648137 Fix modiying class variable to frozen class/module 2019-04-24 21:05:44 +09:00