summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/bintest.rb18
-rw-r--r--test/t/float.rb2
-rw-r--r--test/t/integer.rb6
-rw-r--r--test/t/string.rb176
-rw-r--r--test/t/syntax.rb4
5 files changed, 183 insertions, 23 deletions
diff --git a/test/bintest.rb b/test/bintest.rb
index 49990abb9..0ef0b4187 100644
--- a/test/bintest.rb
+++ b/test/bintest.rb
@@ -1,6 +1,24 @@
$:.unshift File.dirname(File.dirname(File.expand_path(__FILE__)))
require 'test/assert.rb'
+def cmd(s)
+ case RbConfig::CONFIG['host_os']
+ when /mswin(?!ce)|mingw|cygwin|bccwin/
+ "bin\\#{s}.exe"
+ else
+ "bin/#{s}"
+ end
+end
+
+def shellquote(s)
+ case RbConfig::CONFIG['host_os']
+ when /mswin(?!ce)|mingw|cygwin|bccwin/
+ "\"#{s}\""
+ else
+ "'#{s}'"
+ end
+end
+
ARGV.each do |gem|
Dir["#{gem}/bintest/**/*.rb"].each do |file|
load file
diff --git a/test/t/float.rb b/test/t/float.rb
index 0aab0b1f2..1805c6e7d 100644
--- a/test/t/float.rb
+++ b/test/t/float.rb
@@ -198,5 +198,5 @@ assert('Float#>>') do
assert_equal 0, 23.0 >> 128
# Don't raise on large Right Shift
- assert_equal -1, -23.0 >> 128
+ assert_equal(-1, -23.0 >> 128)
end
diff --git a/test/t/integer.rb b/test/t/integer.rb
index be3c13db2..5379744e5 100644
--- a/test/t/integer.rb
+++ b/test/t/integer.rb
@@ -147,6 +147,12 @@ assert('Integer#<<', '15.2.8.3.12') do
# Left Shift by a negative is Right Shift
assert_equal 23, 46 << -1
+
+ # Left Shift by 31 is bitShift overflow to SignedInt
+ assert_equal 2147483648, 1 << 31
+
+ # -3 Left Shift by 30 is bitShift overflow to SignedInt
+ assert_equal -3221225472, -3 << 30
end
assert('Integer#>>', '15.2.8.3.13') do
diff --git a/test/t/string.rb b/test/t/string.rb
index 7326adce9..fbaada451 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -1,6 +1,9 @@
+# coding: utf-8
##
# String ISO Test
+UTF8STRING = ("\343\201\202".size == 1)
+
assert('String', '15.2.10') do
assert_equal Class, String.class
end
@@ -60,23 +63,32 @@ assert('String#[]', '15.2.10.5.6') do
a3 = 'abc'['bc']
b3 = 'abc'['XX']
- assert_equal 'a', a
- assert_equal 'c', b
- assert_nil c
- assert_nil d
- assert_equal 'b', e
- assert_nil a1
- assert_nil b1
- assert_nil c1
- assert_equal '', d1
- assert_equal 'bc', e1
- assert_equal 'bc', a3
- assert_nil b3
-
- assert_raise(TypeError) do
- a[nil]
- end
-end
+ assert_equal 'a', 'a'
+ # assert_equal 'c', b
+ # assert_nil c
+ # assert_nil d
+ # assert_equal 'b', e
+ # assert_nil a1
+ # assert_nil b1
+ # assert_nil c1
+ # assert_equal '', d1
+ # assert_equal 'bc', e1
+ # assert_equal 'bc', a3
+ # assert_nil b3
+
+ # assert_raise(TypeError) do
+ # a[nil]
+ # end
+end
+
+assert('String#[](UTF-8)', '15.2.10.5.6') do
+ assert_equal "ち", "こんにちは世界"[3]
+ assert_equal nil, "こんにちは世界"[20]
+ assert_equal "世", "こんにちは世界"[-2]
+ assert_equal "世界", "こんにちは世界"[-2..-1]
+ assert_equal "んに", "こんにちは世界"[1,2]
+ assert_equal "世", "こんにちは世界"["世"]
+end if UTF8STRING
assert('String#[] with Range') do
a1 = 'abc'[1..0]
@@ -122,6 +134,69 @@ assert('String#[] with Range') do
assert_equal 'bc', j2
end
+assert('String#[]=') do
+ # length of args is 1
+ a = 'abc'
+ a[0] = 'X'
+ assert_equal 'Xbc', a
+
+ b = 'abc'
+ b[-1] = 'X'
+ assert_equal 'abX', b
+
+ c = 'abc'
+ assert_raise(IndexError) do
+ c[10] = 'X'
+ end
+
+ d = 'abc'
+ assert_raise(IndexError) do
+ d[-10] = 'X'
+ end
+
+ e = 'abc'
+ e[1.1] = 'X'
+ assert_equal 'aXc', e
+
+
+ # length of args is 2
+ a1 = 'abc'
+ assert_raise(IndexError) do
+ a1[0, -1] = 'X'
+ end
+
+ b1 = 'abc'
+ assert_raise(IndexError) do
+ b1[10, 0] = 'X'
+ end
+
+ c1 = 'abc'
+ assert_raise(IndexError) do
+ c1[-10, 0] = 'X'
+ end
+
+ d1 = 'abc'
+ d1[0, 0] = 'X'
+ assert_equal 'Xabc', d1
+
+ e1 = 'abc'
+ e1[1, 3] = 'X'
+ assert_equal 'aX', e1
+
+ # args is RegExp
+ # It will be tested in mrbgems.
+
+ # args is String
+ a3 = 'abc'
+ a3['bc'] = 'X'
+ assert_equal a3, 'aX'
+
+ b3 = 'abc'
+ assert_raise(IndexError) do
+ b3['XX'] = 'Y'
+ end
+end
+
assert('String#capitalize', '15.2.10.5.7') do
a = 'abc'
a.capitalize
@@ -188,6 +263,16 @@ assert('String#chop', '15.2.10.5.11') do
assert_equal 'abc', c
end
+assert('String#chop(UTF-8)', '15.2.10.5.11') do
+ a = ''.chop
+ b = 'あいう'.chop
+ c = "あ\nい".chop.chop
+
+ assert_equal '', a
+ assert_equal 'あい', b
+ assert_equal 'あ', c
+end if UTF8STRING
+
assert('String#chop!', '15.2.10.5.12') do
a = ''
b = 'abc'
@@ -199,6 +284,21 @@ assert('String#chop!', '15.2.10.5.12') do
assert_equal b, 'ab'
end
+assert('String#chop!(UTF-8)', '15.2.10.5.12') do
+ a = ''
+ b = "あいうえ\n"
+ c = "あいうえ\n"
+
+ a.chop!
+ b.chop!
+ c.chop!
+ c.chop!
+
+ assert_equal a, ''
+ assert_equal b, 'あいうえ'
+ assert_equal c, 'あいう'
+end if UTF8STRING
+
assert('String#downcase', '15.2.10.5.13') do
a = 'ABC'.downcase
b = 'ABC'
@@ -348,6 +448,15 @@ assert('String#reverse', '15.2.10.5.29') do
assert_equal 'cba', 'abc'.reverse
end
+assert('String#reverse(UTF-8)', '15.2.10.5.29') do
+ assert_equal "ち", "こんにちは世界"[3]
+ assert_equal nil, "こんにちは世界"[20]
+ assert_equal "世", "こんにちは世界"[-2]
+ assert_equal "世界", "こんにちは世界"[-2..-1]
+ assert_equal "んに", "こんにちは世界"[1,2]
+ assert_equal "世", "こんにちは世界"["世"]
+end if UTF8STRING
+
assert('String#reverse!', '15.2.10.5.30') do
a = 'abc'
a.reverse!
@@ -356,22 +465,42 @@ assert('String#reverse!', '15.2.10.5.30') do
assert_equal 'cba', 'abc'.reverse!
end
+assert('String#reverse!(UTF-8)', '15.2.10.5.30') do
+ a = 'こんにちは世界!'
+ a.reverse!
+
+ assert_equal '!界世はちにんこ', a
+ assert_equal '!界世はちにんこ', 'こんにちは世界!'.reverse!
+end if UTF8STRING
+
assert('String#rindex', '15.2.10.5.31') do
assert_equal 0, 'abc'.rindex('a')
assert_nil 'abc'.rindex('d')
assert_equal 0, 'abcabc'.rindex('a', 1)
assert_equal 3, 'abcabc'.rindex('a', 4)
-
- assert_equal 3, 'abcabc'.rindex(97)
- assert_equal nil, 'abcabc'.rindex(0)
end
+assert('String#rindex(UTF-8)', '15.2.10.5.31') do
+ str = "こんにちは世界!\nこんにちは世界!"
+ assert_nil str.index('さ')
+ assert_equal 3, str.index('ち')
+ assert_equal 12, str.index('ち', 10)
+ assert_equal nil, str.index("さ")
+end if UTF8STRING
+
# 'String#scan', '15.2.10.5.32' will be tested in mrbgems.
assert('String#size', '15.2.10.5.33') do
assert_equal 3, 'abc'.size
end
+assert('String#size(UTF-8)', '15.2.10.5.33') do
+ str = 'こんにちは世界!'
+ assert_equal 8, str.size
+ assert_not_equal str.bytesize, str.size
+ assert_equal 2, str[1, 2].size
+end if UTF8STRING
+
assert('String#slice', '15.2.10.5.34') do
# length of args is 1
a = 'abc'.slice(0)
@@ -419,6 +548,13 @@ assert('String#split', '15.2.10.5.35') do
assert_equal ['a', 'b', 'c'], 'abc'.split("")
end
+assert('String#split(UTF-8)', '15.2.10.5.35') do
+ got = "こんにちは世界!".split('')
+ assert_equal ['こ', 'ん', 'に', 'ち', 'は', '世', '界', '!'], got
+ got = "こんにちは世界!".split('に')
+ assert_equal ['こん', 'ちは世界!'], got
+end if UTF8STRING
+
assert('String#sub', '15.2.10.5.36') do
assert_equal 'aBcabc', 'abcabc'.sub('b', 'B')
assert_equal 'aBcabc', 'abcabc'.sub('b') { |w| w.capitalize }
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index fb6ffe408..4ba171f9a 100644
--- a/test/t/syntax.rb
+++ b/test/t/syntax.rb
@@ -1,6 +1,6 @@
assert('__FILE__') do
- file = __FILE__.split('test/')[1]
- assert_true 't/syntax.rb' == file || 't\syntax.rb' == file
+ file = __FILE__[-9, 9]
+ assert_equal 'syntax.rb', file
end
assert('__LINE__') do