summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-symbol-ext/test
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-02-04 18:11:22 +0900
committerKOBAYASHI Shuji <[email protected]>2019-02-04 18:11:22 +0900
commit69fd1a592560d321061790c94f93532db93dccb9 (patch)
treeb7a94cb0998d7cdb6739dc550bf26ad1fe3e6513 /mrbgems/mruby-symbol-ext/test
parent3f7137feaeb3a86df01ae080b4d8826250f4ef29 (diff)
downloadmruby-69fd1a592560d321061790c94f93532db93dccb9.tar.gz
mruby-69fd1a592560d321061790c94f93532db93dccb9.zip
Fix `Symbol#size` for multi-byte characters with `MRB_UTF8_STRING`
Before: p :あ.size #=> 3 After: p :あ.size #=> 1
Diffstat (limited to 'mrbgems/mruby-symbol-ext/test')
-rw-r--r--mrbgems/mruby-symbol-ext/test/symbol.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/mrbgems/mruby-symbol-ext/test/symbol.rb b/mrbgems/mruby-symbol-ext/test/symbol.rb
index 63c1bd826..2c7a62b0c 100644
--- a/mrbgems/mruby-symbol-ext/test/symbol.rb
+++ b/mrbgems/mruby-symbol-ext/test/symbol.rb
@@ -7,9 +7,18 @@ assert('Symbol.all_symbols') do
assert_equal foo, symbols
end
-assert("Symbol#length") do
- assert_equal 5, :hello.size
- assert_equal 5, :mruby.length
+%w[size length].each do |n|
+ assert("Symbol##{n}") do
+ assert_equal 5, :hello.__send__(n)
+ assert_equal 4, :"aA\0b".__send__(n)
+ if "あ".size == 1 # enable MRB_UTF8_STRING?
+ assert_equal 8, :"こんにちは世界!".__send__(n)
+ assert_equal 4, :"aあ\0b".__send__(n)
+ else
+ assert_equal 22, :"こんにちは世界!".__send__(n)
+ assert_equal 6, :"aあ\0b".__send__(n)
+ end
+ end
end
assert("Symbol#capitalize") do