Skip to content

Commit

Permalink
Added new tests for full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones committed Jun 22, 2015
1 parent 7e84bcf commit 3e591e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 4 additions & 2 deletions base/utf16.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ function map(fun, str::UTF16String)
sizehint!(buf, length(str.data))
for ch in str
c2 = fun(ch)
!isa(c2, Char) &&
if !isa(c2, Char)
throw(UnicodeError(UTF_ERR_MAP_CHAR, 0, 0))
end
uc = reinterpret(UInt32, c2)
if uc < 0x10000
utf16_is_surrogate(uc) &&
if utf16_is_surrogate(UInt16(uc))
throw(UnicodeError(UTF_ERR_INVALID_CHAR, 0, uc))
end
push!(buf, UInt16(uc))
elseif uc <= 0x10ffff
push!(buf, UInt16(0xd7c0 + (uc >> 10)))
Expand Down
22 changes: 12 additions & 10 deletions test/strings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1899,19 +1899,21 @@ end
@test [x for x in enumerate("ḟøøƀäṙ")] == [(1, ''), (2, 'ø'), (3, 'ø'), (4, 'ƀ'), (5, 'ä'), (6, '')]

# issue # 11464: uppercase/lowercase of UTF16String becomes a UTF8String
str = "abcdef\uff\uffff\u10ffffABCDEF"
@test typeof(uppercase("abcdef")) == ASCIIString
@test typeof(uppercase(utf8("abcdef"))) == UTF8String
@test typeof(uppercase(utf16("abcdef"))) == UTF16String
@test typeof(uppercase(utf32("abcdef"))) == UTF32String
@test typeof(uppercase(utf8(str))) == UTF8String
@test typeof(uppercase(utf16(str))) == UTF16String
@test typeof(uppercase(utf32(str))) == UTF32String
@test typeof(lowercase("ABCDEF")) == ASCIIString
@test typeof(lowercase(utf8("ABCDEF"))) == UTF8String
@test typeof(lowercase(utf16("ABCDEF"))) == UTF16String
@test typeof(lowercase(utf32("ABCDEF"))) == UTF32String
@test typeof(lowercase(utf8(str))) == UTF8String
@test typeof(lowercase(utf16(str))) == UTF16String
@test typeof(lowercase(utf32(str))) == UTF32String

foomap(ch) = (ch > 65)
foobar(ch) = Char(0xd800)
foobaz(ch) = Char(0x20000)
@test_throws UnicodeError map(foomap, utf16("abcdef"))
@test_throws UnicodeError map(foobar, utf16("abcdef"))
@test_throws UnicodeError map(foobaz, utf16("abcdef"))
foobaz(ch) = Char(0x200000)
@test_throws UnicodeError map(foomap, utf16(str))
@test_throws UnicodeError map(foobar, utf16(str))
@test_throws UnicodeError map(foobaz, utf16(str))


0 comments on commit 3e591e0

Please sign in to comment.