Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mrbgems/mruby-encoding/test/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,20 @@
assert('a byte-read string converted case') do
# Bytes read as bytes spell no characters, so a case conversion has nothing
# above ASCII to map and hands back the bytes it was given, still read as
# bytes. The same bytes read as UTF-8 spell "Ä", which does map.
# bytes. The same bytes read as UTF-8 spell "Ä", which maps where the
# build holds a table for it; where case follows ASCII there is nothing to
# map and the two readings answer alike.
if UTF8STRING
s = "\xC3\x84B".b
assert_equal [195, 132, 98], s.downcase.bytes
assert_equal [195, 132, 66], s.upcase.bytes
assert_equal [195, 132, 98], s.capitalize.bytes
assert_equal Encoding::BINARY, s.downcase.encoding
assert_equal [195, 164, 98], "\xC3\x84B".downcase.bytes if UNICODECASE
if UNICODECASE
assert_equal [195, 164, 98], "\xC3\x84B".downcase.bytes
else
assert_equal [195, 132, 98], "\xC3\x84B".downcase.bytes
end
end
end

Expand Down
23 changes: 23 additions & 0 deletions mrbgems/mruby-string-ext/test/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def assert_upto(exp, receiver, *args)
assert_nil "日本".swapcase!
end

assert('String#swapcase - ASCII only') do
skip if UNICODECASE
# Where case follows ASCII, a character above it has no case to swap and
# stands between the ASCII that does.
assert_equal "abÄCD", "ABÄcd".swapcase
assert_nil "Ä".swapcase!
end

assert('String#concat') do
assert_equal "Hello World!", "Hello " << "World" << 33
assert_equal "Hello World!", "Hello ".concat("World").concat(33)
Expand Down Expand Up @@ -354,6 +362,21 @@ def assert_upto(exp, receiver, *args)
assert_raise(ArgumentError) { "\xC3ABC".swapcase }
end

assert('String#casecmp? - ASCII only') do
skip if UNICODECASE
# Narrowed to ASCII, folding sees no further than `casecmp` does, so two
# spellings that differ above ASCII stay apart however they would fold.
assert_equal 1, "ä".casecmp("Ä")
assert_false "ä".casecmp?("Ä")
assert_false "ß".casecmp?("ss")
assert_false "fi".casecmp?("fi")
# What is left of the folding is the ASCII half, and a folding that reads
# nothing above ASCII has no bytes it must refuse.
assert_true "äB".casecmp?("äb")
assert_false "\xC3ABC".casecmp?("a")
assert_equal 0, "\xC3ABC".casecmp("\xC3abc")
end

assert('String#count') do
s = "abccdeff123"
assert_equal 0, s.count("")
Expand Down
21 changes: 21 additions & 0 deletions test/t/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,27 @@ def []=(*args)
end
end if UNICODECASE

assert('String case conversion - ASCII only') do
# The other reading of case: a build that converts by ASCII, whether by
# MRB_USE_ASCII_CASE or by reading its strings as bytes, has no mapping above
# ASCII, so a character that has one on the Unicode side stands as it was
# while the ASCII beside it still converts.
assert_equal 'Ä', 'Ä'.downcase
assert_equal 'ä', 'ä'.upcase
assert_equal 'Ä', 'Ä'.capitalize
assert_equal 'äb', 'äB'.downcase
assert_equal 'ÄB', 'Äb'.upcase
assert_equal 'Äb', 'ÄB'.capitalize
# A conversion that maps nothing is one that changed nothing.
assert_nil 'Ä'.downcase!
assert_nil 'ä'.upcase!
assert_nil 'Ä'.capitalize!
# Refusing a run of bytes that spells no character belongs to the walk over
# characters; a walk that only knows ASCII hands the bytes back untouched.
assert_equal [195, 97, 98, 99], "\xC3ABC".downcase.bytes
assert_equal [195, 65, 66, 67], "\xC3ABC".upcase.bytes
end unless UNICODECASE

assert('String#chomp', '15.2.10.5.9') do
a = 'abc'.chomp
b = ''.chomp
Expand Down
Loading