diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-07-23 20:16:46 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-07-23 20:16:46 +0900 |
| commit | e86aa61f203ec1589d37798ceb8b40385c7f85e0 (patch) | |
| tree | 59e08a25785f3a36b1a586e322dc9e023b004720 /mrbgems/mruby-string-ext/test/string.rb | |
| parent | 5166e316efc9bd211b3d950d3586a45b22a5f9d5 (diff) | |
| download | mruby-e86aa61f203ec1589d37798ceb8b40385c7f85e0.tar.gz mruby-e86aa61f203ec1589d37798ceb8b40385c7f85e0.zip | |
Add encoding argument to `Integral#chr`
Currently, `Integral#chr` in mruby changes behavior by `MRB_UTF8_STRING`
setting.
before this patch:
$ bin/mruby -e 'p 171.chr' #=> "\xab" (`MRB_UTF8_STRING` is disabled)
$ bin/mruby -e 'p 171.chr' #=> "«" (`MRB_UTF8_STRING` is enabled)
This behavior is incompatible with Ruby, and a little inconvenient because
it can't be interpreted as ASCII-8BIT with `MRB_UTF8_STRING`, I think.
So add encoding argument according to Ruby.
after this patch:
$ bin/mruby -e 'p 171.chr' #=> "\xab"
$ bin/mruby -e 'p 171.chr("ASCII-8BIT")' #=> "\xab"
$ bin/mruby -e 'p 171.chr("UTF-8")' #=> "«"
Allow only `String` for encoding because mruby doesn't have `Encoding`
class, and `"ASCII-8BIT"` (`"BINARY"`) and `"UTF-8"` (only with
`MRB_UTF8_STRING`) are valid value (default is `"ASCII-8BIT"`).
Diffstat (limited to 'mrbgems/mruby-string-ext/test/string.rb')
| -rw-r--r-- | mrbgems/mruby-string-ext/test/string.rb | 9 |
1 files changed, 8 insertions, 1 deletions
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 |
