Skip to content

Commit

Permalink
Merge pull request #36 from crstnbr/fix
Browse files Browse the repository at this point in the history
Fix import from Base warnings on Julia 1.0
  • Loading branch information
stevengj authored Nov 28, 2018
2 parents e8fb929 + 0ff52db commit 2f19dc2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
23 changes: 9 additions & 14 deletions src/LegacyStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,17 @@ import Base:
convert,
getindex,
isvalid,
lcfirst,
length,
lowercase,
map,
next,
nextind,
pointer,
prevind,
reverse,
reverseind,
rsearch,
search,
show,
sizeof,
string,
ucfirst,
unsafe_convert,
uppercase,
write
Expand All @@ -52,22 +47,22 @@ import Compat:
codeunit,
ncodeunits

if isdefined(Base, :iterate)
import Base: iterate
end

if isdefined(Base, :UnicodeError)
if VERSION < v"0.7-"
import Base: lcfirst
import Base: next
import Base: rsearch
import Base: search
import Base: ucfirst
import Base: UnicodeError
else
include("unicodeerror.jl")
end

if isdefined(Base, :DirectIndexString)
using Base: DirectIndexString
else
import Base: iterate
include("unicodeerror.jl")
include("directindex.jl")
end


struct ASCIIString <: DirectIndexString
data::Vector{UInt8}
ASCIIString(data::String) = new(Vector{UInt8}(codeunits(data)))
Expand Down
22 changes: 15 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ using Compat: view, String
using LegacyStrings
using LegacyStrings: ASCIIString, UTF8String # override Compat's version
import LegacyStrings:
ascii,
checkstring,
UnicodeError,
UTF_ERR_SHORT
Expand Down Expand Up @@ -208,13 +207,17 @@ let ch = 0x10000
end

let str = UTF8String(b"this is a test\xed\x80")
@test next(str, 15) == ('\ufffd', 16)
@static if VERSION < v"0.7-"
@test next(str, 15) == ('\ufffd', 16)
else
@test iterate(str, 15) == ('\ufffd', 16)
end
@test_throws BoundsError getindex(str, 0:3)
@test_throws BoundsError getindex(str, 17:18)
@test_throws BoundsError getindex(str, 2:17)
@test_throws UnicodeError getindex(str, 16:17)
# @test string(Char(0x110000)) == "\ufffd"
sa = SubString{ASCIIString}(ascii("This is a silly test"), 1, 14)
sa = SubString{ASCIIString}(LegacyStrings.ascii("This is a silly test"), 1, 14)
s8 = convert(SubString{UTF8String}, sa)
@test typeof(s8) == SubString{UTF8String}
@test s8 == "This is a sill"
Expand Down Expand Up @@ -283,7 +286,7 @@ function tstcvt(strUTF8::UTF8String, strUTF16::UTF16String, strUTF32::UTF32Strin
end

# Create some ASCII, UTF8, UTF16, and UTF32 strings
strAscii = ascii("abcdefgh")
strAscii = LegacyStrings.ascii("abcdefgh")
strA_UTF8 = utf8(("abcdefgh\uff")[1:8])
strL_UTF8 = utf8("abcdef\uff\uff")
str2_UTF8 = utf8("abcd\uff\uff\u7ff\u7ff")
Expand Down Expand Up @@ -464,7 +467,7 @@ end
@test reverse(utf32("abcd \uff\u7ff\u7fff\U7ffff")) == utf32("\U7ffff\u7fff\u7ff\uff dcba")

# Test pointer() functions
let str = ascii("this ")
let str = LegacyStrings.ascii("this ")
u8 = utf8(str)
u16 = utf16(str)
u32 = utf32(str)
Expand Down Expand Up @@ -545,8 +548,13 @@ let

@test lastindex(srep) == 7

@test next(srep, 3) == ('β',5)
@test next(srep, 7) == ('β',9)
@static if VERSION < v"0.7-"
@test next(srep, 3) == ('β',5)
@test next(srep, 7) == ('β',9)
else
@test iterate(srep, 3) == ('β',5)
@test iterate(srep, 7) == ('β',9)
end

@test srep[7] == 'β'
@static if VERSION < v"0.7.0-DEV.2924"
Expand Down

0 comments on commit 2f19dc2

Please sign in to comment.