diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-07-23 23:36:50 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-23 23:36:50 +0900 |
| commit | e968bdf6298e6f2e567e414862792d5ad7aff4ad (patch) | |
| tree | 59e08a25785f3a36b1a586e322dc9e023b004720 /mrbgems/mruby-string-ext/test | |
| parent | 5166e316efc9bd211b3d950d3586a45b22a5f9d5 (diff) | |
| parent | e86aa61f203ec1589d37798ceb8b40385c7f85e0 (diff) | |
| download | mruby-e968bdf6298e6f2e567e414862792d5ad7aff4ad.tar.gz mruby-e968bdf6298e6f2e567e414862792d5ad7aff4ad.zip | |
Merge pull request #4593 from shuujii/add-encoding-argument-to-Integral-chr
Add encoding argument to `Integral#chr`
Diffstat (limited to 'mrbgems/mruby-string-ext/test')
| -rw-r--r-- | mrbgems/mruby-string-ext/test/numeric.rb | 24 | ||||
| -rw-r--r-- | mrbgems/mruby-string-ext/test/string.rb | 9 |
2 files changed, 32 insertions, 1 deletions
diff --git a/mrbgems/mruby-string-ext/test/numeric.rb b/mrbgems/mruby-string-ext/test/numeric.rb index cae562fc1..dfcb9ebf4 100644 --- a/mrbgems/mruby-string-ext/test/numeric.rb +++ b/mrbgems/mruby-string-ext/test/numeric.rb @@ -1,5 +1,29 @@ +# coding: utf-8 + assert('Integer#chr') do assert_equal("A", 65.chr) assert_equal("B", 0x42.chr) + assert_equal("\xab", 171.chr) assert_raise(RangeError) { -1.chr } + assert_raise(RangeError) { 256.chr } + + assert_equal("A", 65.chr("ASCII-8BIT")) + assert_equal("B", 0x42.chr("BINARY")) + assert_equal("\xab", 171.chr("ascii-8bit")) + assert_raise(RangeError) { -1.chr("binary") } + assert_raise(RangeError) { 256.chr("Ascii-8bit") } + assert_raise(ArgumentError) { 65.chr("ASCII") } + assert_raise(ArgumentError) { 65.chr("ASCII-8BIT", 2) } + assert_raise(TypeError) { 65.chr(:BINARY) } + + if __ENCODING__ == "ASCII-8BIT" + assert_raise(ArgumentError) { 65.chr("UTF-8") } + else + assert_equal("A", 65.chr("UTF-8")) + assert_equal("B", 0x42.chr("UTF-8")) + assert_equal("«", 171.chr("utf-8")) + assert_equal("あ", 12354.chr("Utf-8")) + assert_raise(RangeError) { -1.chr("utf-8") } + assert_raise(RangeError) { 0x110000.chr.chr("UTF-8") } + end end diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb index 2eb35f840..8f1d25f29 100644 --- a/mrbgems/mruby-string-ext/test/string.rb +++ b/mrbgems/mruby-string-ext/test/string.rb @@ -167,8 +167,15 @@ end assert('String#concat') do assert_equal "Hello World!", "Hello " << "World" << 33 assert_equal "Hello World!", "Hello ".concat("World").concat(33) - assert_raise(TypeError) { "".concat(Object.new) } + + if UTF8STRING + assert_equal "H«", "H" << 0xab + assert_equal "Hは", "H" << 12399 + else + assert_equal "H\xab", "H" << 0xab + assert_raise(RangeError) { "H" << 12399 } + end end assert('String#casecmp') do |
