From 6ec149c4e3da3b991a860250b32ca79775639592 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 2 Jun 2012 16:44:16 +0800 Subject: Add string test for string interpolation --- test/t/string.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/t/string.rb') diff --git a/test/t/string.rb b/test/t/string.rb index f38790c17..ee969a696 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -319,3 +319,11 @@ assert('String#upcase!', '15.2.10.5.43') do a == 'ABC' end + +# Not ISO specified + +assert('String interpolation (mrb_str_concat for shared strings)') do + a = "A" * 32 + "#{a}:" == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:" +end + -- cgit v1.2.3 From 0c2d74020a925fa86235ae7c716aa0ede856e6e6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 3 Jun 2012 23:31:53 +0800 Subject: Add more superclass tests --- test/t/array.rb | 4 ++++ test/t/false.rb | 4 ++++ test/t/float.rb | 4 ++++ test/t/hash.rb | 4 ++++ test/t/integer.rb | 4 ++++ test/t/module.rb | 4 ++++ test/t/numeric.rb | 4 ++++ test/t/object.rb | 5 +++++ test/t/proc.rb | 4 ++++ test/t/range.rb | 4 ++++ test/t/string.rb | 4 ++++ test/t/struct.rb | 5 +++++ test/t/symbol.rb | 4 ++++ test/t/time.rb | 4 ++++ test/t/true.rb | 4 ++++ 15 files changed, 62 insertions(+) (limited to 'test/t/string.rb') diff --git a/test/t/array.rb b/test/t/array.rb index dba1b035d..4e53f1120 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -5,6 +5,10 @@ assert('Array', '15.2.12') do Array.class == Class end +assert('Array superclass', '15.2.12.2') do + Array.superclass == Object +end + assert('Array.[]', '15.2.12.4.1') do Array.[](1,2,3) == [1, 2, 3] end diff --git a/test/t/false.rb b/test/t/false.rb index c2db283c8..ae605205d 100644 --- a/test/t/false.rb +++ b/test/t/false.rb @@ -5,6 +5,10 @@ assert('FalseClass', '15.2.6') do FalseClass.class == Class end +assert('FalseClass superclass', '15.2.6.2') do + FalseClass.superclass == Object +end + assert('FalseClass false', '15.2.6.1') do not false end diff --git a/test/t/float.rb b/test/t/float.rb index fc87a5b22..5c5245c73 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -5,6 +5,10 @@ assert('Float', '15.2.9') do Float.class == Class end +assert('Float superclass', '15.2.9.2') do + Float.superclass == Numeric +end + assert('Float#+', '15.2.9.3.1') do a = 3.123456788 + 0.000000001 b = 3.123456789 + 1 diff --git a/test/t/hash.rb b/test/t/hash.rb index df21dd1fa..04a9a1c24 100644 --- a/test/t/hash.rb +++ b/test/t/hash.rb @@ -5,6 +5,10 @@ assert('Hash', '15.2.13') do Hash.class == Class end +assert('Hash superclass', '15.2.13.2') do + Hash.superclass == Object +end + assert('Hash#==', '15.2.13.4.1') do ({ 'abc' => 'abc' } == { 'abc' => 'abc' }) and not ({ 'abc' => 'abc' } == { 'cba' => 'cba' }) diff --git a/test/t/integer.rb b/test/t/integer.rb index 8c112861a..872723445 100644 --- a/test/t/integer.rb +++ b/test/t/integer.rb @@ -5,6 +5,10 @@ assert('Integer', '15.2.8') do Integer.class == Class end +assert('Integer superclass', '15.2.8.2') do + Integer.superclass == Numeric +end + assert('Integer#+', '15.2.8.3.1') do a = 1+1 b = 1+1.0 diff --git a/test/t/module.rb b/test/t/module.rb index a5331e96d..95fbb7a86 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -5,6 +5,10 @@ assert('Module', '15.2.2') do Module.class == Class end +assert('Module superclass', '15.2.2.2') do + Module.superclass == Object +end + assert('Module#const_defined?', '15.2.2.4.20') do module Test4ConstDefined Const4Test4ConstDefined = true diff --git a/test/t/numeric.rb b/test/t/numeric.rb index 924889a0e..3cdb9a8cf 100644 --- a/test/t/numeric.rb +++ b/test/t/numeric.rb @@ -5,6 +5,10 @@ assert('Numeric', '15.2.7') do Numeric.class == Class end +assert('Numeric superclass', '15.2.7.2') do + Numeric.superclass == Object +end + assert('Numeric#+@', '15.2.7.4.1') do +1 == +1 end diff --git a/test/t/object.rb b/test/t/object.rb index 96929031b..7dfaf6589 100644 --- a/test/t/object.rb +++ b/test/t/object.rb @@ -4,3 +4,8 @@ assert('Object', '15.2.1') do Object.class == Class end + +assert('Object superclass', '15.2.1.2') do + Object.superclass == BasicObject +end + diff --git a/test/t/proc.rb b/test/t/proc.rb index 6d98cb40c..c0a1cf90f 100644 --- a/test/t/proc.rb +++ b/test/t/proc.rb @@ -5,6 +5,10 @@ assert('Proc', '15.2.17') do Proc.class == Class end +assert('Proc superclass', '15.2.17.2') do + Proc.superclass == Object +end + assert('Proc.new', '15.2.17.3.1') do a = nil diff --git a/test/t/range.rb b/test/t/range.rb index 05bac8779..691ca7898 100644 --- a/test/t/range.rb +++ b/test/t/range.rb @@ -5,6 +5,10 @@ assert('Range', '15.2.14') do Range.class == Class end +assert('Range superclass', '15.2.14.2') do + Range.superclass == Object +end + assert('Range#==', '15.2.14.4.1') do (1..10) == (1..10) and not (1..10) == (1..100) end diff --git a/test/t/string.rb b/test/t/string.rb index ee969a696..964ec0e63 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -5,6 +5,10 @@ assert('String', '15.2.10') do String.class == Class end +assert('String superclass', '15.2.10.2') do + String.superclass == Object +end + assert('String#*', '15.2.10.5.1') do 'a' * 5 == 'aaaaa' end diff --git a/test/t/struct.rb b/test/t/struct.rb index c41319f8a..798cf6728 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -4,3 +4,8 @@ assert('Struct', '15.2.18') do Struct.class == Class end + +assert('Struct superclass', '15.2.18.2') do + Struct.superclass == Object +end + diff --git a/test/t/symbol.rb b/test/t/symbol.rb index e9c310971..b28573e92 100644 --- a/test/t/symbol.rb +++ b/test/t/symbol.rb @@ -5,6 +5,10 @@ assert('Symbol', '15.2.11') do Symbol.class == Class end +assert('Symbol superclass', '15.2.11.2') do + Symbol.superclass == Object +end + assert('Symbol#===', '15.2.11.3.1') do :abc === :abc and not :abc === :cba end diff --git a/test/t/time.rb b/test/t/time.rb index 22fc2e7c3..7d1519f63 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -5,6 +5,10 @@ assert('Time', '15.2.19') do Time.class == Class end +assert('Time superclass', '15.2.19.2') do + Time.superclass == Object +end + assert('Time.at', '15.2.19.6.1') do Time.at(1300000000.0) end diff --git a/test/t/true.rb b/test/t/true.rb index bb648a7cd..2662f7cd8 100644 --- a/test/t/true.rb +++ b/test/t/true.rb @@ -5,6 +5,10 @@ assert('TrueClass', '15.2.5') do TrueClass.class == Class end +assert('TrueClass superclass', '15.2.5.2') do + TrueClass.superclass == Object +end + assert('TrueClass true', '15.2.5.1') do true end -- cgit v1.2.3 From 46c9260305a7acc7ee2e1bd1d2441b56cee89f3f Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Mon, 11 Jun 2012 01:39:45 +0900 Subject: Add test for slice of shared string. --- test/t/string.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/t/string.rb') diff --git a/test/t/string.rb b/test/t/string.rb index 964ec0e63..d7182fc38 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -256,6 +256,9 @@ assert('String#slice', '15.2.10.5.34') do d1 = 'abc'.slice(0, 0) e1 = 'abc'.slice(1, 2) + # slice of shared string + e11 = e1.slice(0) + # args is RegExp # TODO SEGFAULT ATM @@ -265,7 +268,7 @@ assert('String#slice', '15.2.10.5.34') do a == 'a' and b == 'c' and c == nil and d == nil and a1 == nil and b1 == nil and c1 == nil and d1 == '' and - e1 == 'bc' and + e1 == 'bc' and e11 == 'b' and a3 == 'bc' and b3 == nil end -- cgit v1.2.3 From 6987ba02f8ea14531d55a8a44f8d68667076ebe8 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 09:51:10 +0900 Subject: String#split now understands string sep --- src/string.c | 43 ++++++++++++++++++++++++------------------- test/t/string.rb | 4 +++- 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'test/t/string.rb') diff --git a/src/string.c b/src/string.c index 1de0d9592..340402e26 100644 --- a/src/string.c +++ b/src/string.c @@ -2122,27 +2122,16 @@ static const char isspacetable[256] = { static mrb_value mrb_str_split_m(mrb_state *mrb, mrb_value str) { - mrb_value *argv; int argc; mrb_value spat = mrb_nil_value(); - mrb_value limit; enum {awk, string, regexp} split_type = string; long beg, end, i = 0; - int lim = 0; + int lim = -1; mrb_value result, tmp; - mrb_get_args(mrb, "*", &argv, &argc); - if (argc > 0) - spat = argv[0]; - if (argc > 1) - limit = argv[1]; - else - limit = mrb_nil_value(); - + argc = mrb_get_args(mrb, "|oi", &spat, &lim); if (argc == 2) { - lim = mrb_fixnum(limit); - if (lim <= 0) limit = mrb_nil_value(); - else if (lim == 1) { + if (lim == 1) { if (RSTRING_LEN(str) == 0) return mrb_ary_new_capa(mrb, 0); return mrb_ary_new_from_values(mrb, 1, &str); @@ -2201,20 +2190,36 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) else { end = ptr - bptr; skip = 0; - if (!mrb_nil_p(limit) && lim <= i) break; + if (lim >= 0 && lim <= i) break; } } else if (ascii_isspace(c)) { mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, beg, end-beg)); skip = 1; beg = ptr - bptr; - if (!mrb_nil_p(limit)) ++i; + if (lim >= 0) ++i; } else { end = ptr - bptr; } } } + else if (split_type == string) { + char *ptr = RSTRING_PTR(str); + char *temp = ptr; + char *eptr = RSTRING_END(str); + char *sptr = RSTRING_PTR(spat); + long slen = RSTRING_LEN(spat); + + while (ptr < eptr && + (end = mrb_memsearch(sptr, slen, ptr, eptr - ptr)) >= 0) { + /* Check we are at the start of a char */ + mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr - temp, end)); + ptr += end + slen; + if (lim >= 0 && lim <= ++i) break; + } + beg = ptr - temp; + } else { #ifdef INCLUDE_REGEXP char *ptr = RSTRING_PTR(str); @@ -2258,20 +2263,20 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) tmp = mrb_str_subseq(mrb, str, BEG(idx), END(idx)-BEG(idx)); mrb_ary_push(mrb, result, tmp); } - if (!mrb_nil_p(limit) && lim <= ++i) break; + if (lim >= 0 && lim <= ++i) break; } #else mrb_raise(mrb, E_TYPE_ERROR, "Regexp Class not supported"); #endif //INCLUDE_REGEXP } - if (RSTRING_LEN(str) > 0 && (!mrb_nil_p(limit) || RSTRING_LEN(str) > beg || lim < 0)) { + if (RSTRING_LEN(str) > 0 && (lim >= 0 || RSTRING_LEN(str) > beg || lim < 0)) { if (RSTRING_LEN(str) == beg) tmp = mrb_str_new_empty(mrb, str); else tmp = mrb_str_subseq(mrb, str, beg, RSTRING_LEN(str)-beg); mrb_ary_push(mrb, result, tmp); } - if (mrb_nil_p(limit) && lim == 0) { + if (lim < 0) { long len; while ((len = RARRAY_LEN(result)) > 0 && (tmp = RARRAY_PTR(result)[len-1], RSTRING_LEN(tmp) == 0)) diff --git a/test/t/string.rb b/test/t/string.rb index d7182fc38..718b005a9 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -276,8 +276,10 @@ end assert('String#split', '15.2.10.5.35') do # without RegExp behavior is actually unspecified a = 'abc abc abc'.split + b = 'a,b,c,,d'.split(',') - a == ['abc', 'abc', 'abc'] + a == ['abc', 'abc', 'abc'] and + b == ["a", "b", "c", "", "d"] end # TODO ATM broken assert('String#sub', '15.2.10.5.36') do -- cgit v1.2.3 From 5937c29281d9bf51ca85b79c8f3dea204909a073 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 12:29:20 +0900 Subject: s.split(nil) should work like s.split() --- src/string.c | 2 +- test/t/string.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'test/t/string.rb') diff --git a/src/string.c b/src/string.c index 172b8422c..fae3392cf 100644 --- a/src/string.c +++ b/src/string.c @@ -2139,7 +2139,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) i = 1; } - if (argc == 0) { + if (argc == 0 || mrb_nil_p(spat)) { split_type = awk; } else { diff --git a/test/t/string.rb b/test/t/string.rb index 718b005a9..c422133e3 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -277,9 +277,11 @@ assert('String#split', '15.2.10.5.35') do # without RegExp behavior is actually unspecified a = 'abc abc abc'.split b = 'a,b,c,,d'.split(',') + c = 'abc abc abc'.split(nil) a == ['abc', 'abc', 'abc'] and - b == ["a", "b", "c", "", "d"] + b == ["a", "b", "c", "", "d"] and + c == ['abc', 'abc', 'abc'] end # TODO ATM broken assert('String#sub', '15.2.10.5.36') do -- cgit v1.2.3 From 30a062c165f31f31f8be65bd51d313a2d25f0bd9 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 12 Jun 2012 12:58:49 +0900 Subject: String#split("") should split per character (byte for now) --- src/string.c | 22 ++++++++++++++++------ test/t/string.rb | 11 ++++------- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'test/t/string.rb') diff --git a/src/string.c b/src/string.c index fcd68a2f2..14041127a 100644 --- a/src/string.c +++ b/src/string.c @@ -2208,14 +2208,24 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) char *ptr = RSTRING_PTR(str); char *temp = ptr; char *eptr = RSTRING_END(str); - char *sptr = RSTRING_PTR(spat); long slen = RSTRING_LEN(spat); - while (ptr < eptr && - (end = mrb_memsearch(sptr, slen, ptr, eptr - ptr)) >= 0) { - mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr - temp, end)); - ptr += end + slen; - if (lim >= 0 && lim <= ++i) break; + if (slen == 0) { + while (ptr < eptr) { + mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr-temp, 1)); + ptr++; + if (lim >= 0 && lim <= ++i) break; + } + } + else { + char *sptr = RSTRING_PTR(spat); + + while (ptr < eptr && + (end = mrb_memsearch(sptr, slen, ptr, eptr - ptr)) >= 0) { + mrb_ary_push(mrb, result, mrb_str_subseq(mrb, str, ptr - temp, end)); + ptr += end + slen; + if (lim >= 0 && lim <= ++i) break; + } } beg = ptr - temp; } diff --git a/test/t/string.rb b/test/t/string.rb index c422133e3..3338e4318 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -275,13 +275,10 @@ end # TODO Broken ATM assert('String#split', '15.2.10.5.35') do # without RegExp behavior is actually unspecified - a = 'abc abc abc'.split - b = 'a,b,c,,d'.split(',') - c = 'abc abc abc'.split(nil) - - a == ['abc', 'abc', 'abc'] and - b == ["a", "b", "c", "", "d"] and - c == ['abc', 'abc', 'abc'] + 'abc abc abc'.split == ['abc', 'abc', 'abc'] and + 'a,b,c,,d'.split(',') == ["a", "b", "c", "", "d"] and + 'abc abc abc'.split(nil) == ['abc', 'abc', 'abc'] and + 'abc'.split("") == ['a', 'b', 'c'] end # TODO ATM broken assert('String#sub', '15.2.10.5.36') do -- cgit v1.2.3