iij/mrubyとmruby/mrubyとの差分解消 (test/t編) #142

Closed
opened this Issue Jun 25, 2013 · 0 comments

2 participants

```--- a/test/t/integer.rb
+++ b/test/t/integer.rb
@@ -207,6 +207,16 @@ end

# Not ISO specified

+assert('Integer#div') do
+  0.div(1) == 0 and
+  1.div(3) == 0 and
+  3.div(1) == 3 and
+  20.div(7) == 2 and
+  -3.div(5) == -1 and
+  25.div(-13) == -2 and
+  -13.div(-7) == 1
+end
+
assert('Integer#step') do
a = []
b = []
diff --git a/test/t/string.rb b/test/t/string.rb
index ddae92d..4e40259 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -370,6 +370,58 @@ assert('String#slice', '15.2.10.5.34') do
assert_nil b3
end

+assert('String#slice!', '15.2.10.5.X') do
+  x1 = 'abc'
+  x2 = x1.clone
+  x3 = x1.clone
+  y1 = x1.slice!(0)
+  y2 = x2.slice!(1)
+  y3 = x3.slice!(-1)
+
+  u1 = 'abc'
+  u2 = u1.clone
+  u3 = u1.clone
+  v1 = u1.slice!(0, 0)
+  v2 = u2.slice!(0, 1)
+  v3 = u3.slice!(0, -1)
+
+  x1 == 'bc' and x2 == 'ac' and x3 == 'ab' and
+    y1 == 'a' and y2 == 'b' and y3 == 'c' and
+    u1 == 'abc' and u2 == 'bc' and u3 == 'abc' and
+    v1 == '' and v2 == 'a' and v3 == nil
+end
+
+assert('String#split with non-Regexp separator') do
+  r = false
+  oldsep = \$;
+  begin
+    \$; = ','
+    r = (
+      ''.split(',', 1)          == []                    and  # not ['']
+      'abc'.split(',', 1)       == ['abc']               and
+      'abc'.split('')           == ['a', 'b', 'c']       and
+      'a,b,,c,,'.split(',')     == ['a', 'b', '', 'c']   and
+      # Not implemented yet(\$; variable).
+      #'a,b,,c,,'.split          == ['a', 'b', '', 'c']   and
+      'a,b,,c,,'.split(',', 0)  == ['a', 'b', '', 'c']   and
+      'a,b,,c,,'.split(',', 1)  == ['a,b,,c,,']          and
+      'a,b,,c,,'.split(',', 4)  == ['a', 'b', '', 'c,,'] and
+      'a,b,,c,,'.split(',', -4) == ['a', 'b', '', 'c', '', ''] and
+      '      abc'.split(' ')    == ['abc']               and
+      'abc      '.split(' ')    == ['abc']               and
+      ' a  bc d '.split(' ')    == ['a', 'bc', 'd']      and
+      ' a  bc d '.split(' ')    == ['a', 'bc', 'd']      and
+      # failed case(ruby 2.0.0).
+      #' a  bc d '.split(nil)    == ['a', 'bc', 'd']      and
+      ' a  bc d '.split(' ', 1) == [' a  bc d ']         and
+      ' a  bc d '.split(' ', 2) == ['a', 'bc d ']
+    )
+  ensure
+    \$; = oldsep
+  end
+  r
+end
+
# TODO Broken ATM
assert('String#split', '15.2.10.5.35') do
# without RegExp behavior is actually unspecified
@@ -396,7 +448,6 @@ assert('String#sub!', '15.2.10.5.37') do
assert_equal b, 'aBcabc'
end

-
assert('String#to_i', '15.2.10.5.38') do
a = ''.to_i
b = '123456789'.to_i
@@ -477,6 +528,16 @@ assert('String#each_byte') do
assert_equal bytes1, bytes2
end

+assert('String#%') do
+  "%05d" % 123 == "00123" and
+    "%-5s: %08x" % [ "ID", 123 ] == "ID   : 0000007b" and
+    "foo = %{foo}" % { :foo => 'bar' } == "foo = bar"
+end
+
+assert('String#dump') do
+  ("\1" * 100).dump     # should not raise an exception - regress #1210
+end
+
assert('String#inspect') do
("\1" * 100).inspect  # should not raise an exception - regress #1210
assert_equal "\0".inspect, "\"\\000\""
diff --git a/test/t/variable.rb b/test/t/variable.rb
new file mode 100644
index 0000000..4e53a9b
--- /dev/null
+++ b/test/t/variable.rb
@@ -0,0 +1,24 @@
+##
+# variable
+
+assert('\$LOAD_PATH should be same \$: (1)') do
+  orig = \$:  # setup
+  \$: = ["hoge"]
+  result = (\$: == \$LOAD_PATH)
+  \$: = orig  # restore
+
+  result
+end
+
+assert('\$LOAD_PATH should be same \$: (2)') do
+  orig = \$:  # setup
+  \$: = ["hoge"]
+  result0 = (\$: == \$LOAD_PATH)