90 Commits

Author SHA1 Message Date
KOBAYASHI Shuji 7192429e83 Fix behavior of Kernel#Integer to numbers ending with _ and spaces
#### Before this patch:

  ```ruby
  Integer("1_ ")  #=> 1
  ```

#### After this patch (same as Ruby):

  ```ruby
  Integer("1_ ")  #=> ArgumentError
  ```
2019-12-11 16:40:39 +09:00
KOBAYASHI Shuji bf431e77b8 Fix behavior of String#to_i/Kernel#Integer to numbers starting with _
#### Before this patch:

  ```ruby
  Integer("_1")  #=> 1
  "_1".to_i      #=> 1
  ```

#### After this patch (same as Ruby):

  ```ruby
  Integer("_1")  #=> ArgumentError
  "_1".to_i      #=> 0
  ```
2019-12-10 21:31:30 +09:00
KOBAYASHI Shuji 0893ee492c Fix that String#to_f accepts consecutive _ as a numeric expression
Consecutive `_` is not allowed as a numeric expression:

  1_2__3             #=> SyntaxError
  Float("1_2__3")    #=> ArgumentError
  Integer("1_2__3")  #=> ArgumentError
  "1_2__3".to_i      #=> 12

But `String#to_f` accept it, so I fixed the issue.

Before this patch:

  "1_2__3".to_f      #=> 123

After this patch:

  "1_2__3".to_f      #=> 12
2019-12-09 21:47:59 +09:00
KOBAYASHI Shuji 7ce5d33947 Integrate mrb_str_inspect and mrb_str_dump 2019-10-10 19:50:48 +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 e61095426b Simplify arguments check in String#index
Also fix document about type of the first argument.
2019-09-19 20:19:38 +09:00
Yukihiro "Matz" Matsumoto 04b098d000 Move tests related to getbyte, setbyte, byteslice` to core. 2019-09-11 18:49:08 +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 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
dearblue e4249b1b9e Add UTF-8 test for String#index 2019-07-11 22:09:16 +09:00
dearblue 40030a5dbc Add test for String#[]= 2019-06-29 14:41:43 +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
dearblue 5af8a9777b Add test for one UTF-8 charactor 2019-06-22 22:58:08 +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 0692f7916c Simplify conversion process for i in mrb_get_args() 2019-05-03 13:39:19 +09:00
KOBAYASHI Shuji cdb458ed4e Commented out String#scan because it is not implemented yet 2019-04-21 20:34:39 +09:00
KOBAYASHI Shuji 4a8b88f775 Add type check (conversion) in String#[]=
Before this patch:

  'a'[0] = 1        #=> 1
  'a'[:a] = '1'     #=> ArgumentError
  'a'[:a, 0] = '1'  #=> ArgumentError
  'a'[0, :a] = '1'  #=> ArgumentError
  'a'[0, 1] = 1     #=> 1

After this patch / Ruby:

  'a'[0] = 1        #=> TypeError
  'a'[:a] = '1'     #=> TypeError
  'a'[:a, 0] = '1'  #=> TypeError
  'a'[0, :a] = '1'  #=> TypeError
  'a'[0, 1] = 1     #=> TypeError
2019-04-19 20:14:23 +09:00
KOBAYASHI Shuji fbad7a1595 Use FrozenError instead of RuntimeError in frozen object modification test 2019-03-19 20:48:32 +09:00
Yukihiro "Matz" Matsumoto f1fb2bf29e Remove ?A style string literals from string tests; #4303
We have a plan to obsolete this style in the future.
2019-02-28 12:55:44 +09:00
dearblue f9a568adcb Add test for string literal concatenation 2019-02-27 22:58:13 +09:00
KOBAYASHI Shuji 6d5a62cf5f Fix tests for String#reverse with MRB_UTF8_STRING 2019-01-22 19:37:14 +09:00
KOBAYASHI Shuji 6f395a58d2 Add assert_same and assert_not_same 2019-01-05 20:41:09 +09:00
Yukihiro "Matz" Matsumoto cca19532c5 Remove Kernel#class_defined? which is not available in CRuby; #3829 2019-01-03 11:34:35 +09:00
Yukihiro "Matz" Matsumoto ff08856fe3 Remove implicit conversion using to_str method; fix #3854
We have added internal convenience method `__to_str` which
does string type check.

The issue #3854 was fixed but fundamental flaw of lack of stack
depth check along with fibers still remains. Use `MRB_GC_FIXED_ARENA`
for workaround.
2018-11-19 12:05:46 +09:00
Takeshi Watanabe 77a3863a3d Return nil if type differ in String#<=>. 2018-03-24 16:18:44 +09:00
Yukihiro "Matz" Matsumoto 1d55260423 String#inspect to use hexadecimal, not octal to print unprintable. 2018-02-12 22:56:24 +09:00
Yukihiro "Matz" Matsumoto b4f9b031de Some cosmetic changes 2017-11-22 16:09:50 +09:00
YAMAMOTO Masaya dcd5d0ffec Test for MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
ksss 63c0044b11 Fix result if pattern is empty 2017-03-22 22:19:34 +09:00
ksss 7a74a617ea Callback should yield with pattern every time 2017-03-19 23:04:22 +09:00
ksss 673ce237c4 Suuport custom separator 2017-03-15 16:58:28 +09:00
Yukihiro "Matz" Matsumoto 7590482d48 Merge branch 'master' into string-gsub 2017-03-11 10:22:17 +09:00
ksss b56ad8d122 \1 sequences as empty strings 2017-03-10 22:22:06 +09:00
ksss 4b3e6cf169 Avoid infinity loop when empty string pattern 2017-03-10 13:26:15 +09:00
ksss 76e10351fa String#index shouldn't return nil when "".index "" 2017-03-05 14:15:18 +09:00
Clayton Smith 868d2e528f Fix crash when exponent is -2147483648 2016-12-15 09:36:22 -05:00
Clayton Smith 76a1bdfa29 Get String length after args in String#chomp!
Fixes RCE issue
Reported by @bouk
2016-11-24 10:28:21 -05:00
Yukihiro "Matz" Matsumoto 57900d809f String#include? does not take integers 2016-11-17 18:02:10 +09:00
Yukihiro "Matz" Matsumoto 6b3fd18262 clarify asserts to UTF-8 test suites; ref #2971 2015-10-01 19:32:29 +09:00
Yasuhiro Matsumoto 7ad75a4a19 fix tests 2015-09-30 13:08:11 +09:00
Yasuhiro Matsumoto d5f145076c chop with utf-8. fix #2967 2015-09-29 21:22:45 +09:00
Yukihiro "Matz" Matsumoto 798ec3aff4 UTF-8 string support in core
define MRB_UTF8_STRING (in mrbconf.h) to enable UTF-8 support.
2015-09-24 02:37:33 +09:00
Yukihiro "Matz" Matsumoto 6a06a3e48d String#rindex should no longer take integer argument 2015-09-23 01:06:26 +09:00
takahashim f1c23a0f75 support String#[]= with 3 args 2015-09-16 18:50:03 +09:00
Jun Hiroe 69e835cd0f Add String#freeze test 2015-08-27 21:44:56 +09:00
Tomoyuki Sahara 5dd2b8e16f gsub/sub supports back references in substitutes. fixes #2816.
This implementation is compatible with CRuby's String#gsub/sub
except \1 ... \9 and \+.  They are useless without Regexp library.
2015-06-08 17:32:14 +09:00
h2so5 05b00a14c5 String#[] should reject nil index 2014-12-17 14:01:39 +09:00
Robert Mosolgo 0133d9ac70 fix(String) String#[] accepts float; close #2650 #2651 2014-11-26 01:03:38 +09:00