From e9c3c9f649db87712ba59a9fff0bb62f409763ce Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Sat, 18 Aug 2018 09:50:25 -0600 Subject: [PATCH 1/3] Only import deprecated functions in defined --- src/LegacyStrings.jl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/LegacyStrings.jl b/src/LegacyStrings.jl index 684fe0f..625babe 100644 --- a/src/LegacyStrings.jl +++ b/src/LegacyStrings.jl @@ -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 @@ -52,6 +47,26 @@ import Compat: codeunit, ncodeunits +if isdefined(Base, :lcfirst) + import Base: lcfirst +end + +if isdefined(Base, :next) + import Base: next +end + +if isdefined(Base, :rsearch) + import Base: rsearch +end + +if isdefined(Base, :search) + import Base: search +end + +if isdefined(Base, :ucfirst) + import Base: ucfirst +end + if isdefined(Base, :iterate) import Base: iterate end From 4fed1659b7abce6ba228054799f4cd1f3ffb3986 Mon Sep 17 00:00:00 2001 From: Carsten Bauer Date: Mon, 26 Nov 2018 19:56:03 +0100 Subject: [PATCH 2/3] fix cannot import from Base warnings and tests --- src/LegacyStrings.jl | 30 +++++------------------------- test/runtests.jl | 13 ++++++------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/LegacyStrings.jl b/src/LegacyStrings.jl index 625babe..02c0542 100644 --- a/src/LegacyStrings.jl +++ b/src/LegacyStrings.jl @@ -47,42 +47,22 @@ import Compat: codeunit, ncodeunits -if isdefined(Base, :lcfirst) - import Base: lcfirst -end -if isdefined(Base, :next) +if VERSION <= v"0.7-" + import Base: lcfirst import Base: next -end - -if isdefined(Base, :rsearch) import Base: rsearch -end - -if isdefined(Base, :search) import Base: search -end - -if isdefined(Base, :ucfirst) import Base: ucfirst -end - -if isdefined(Base, :iterate) - import Base: iterate -end - -if isdefined(Base, :UnicodeError) 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))) diff --git a/test/runtests.jl b/test/runtests.jl index 1755cdf..8e64d12 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -208,13 +207,13 @@ let ch = 0x10000 end let str = UTF8String(b"this is a test\xed\x80") - @test next(str, 15) == ('\ufffd', 16) + @test iterate(str, 15) == ('\ufffd', 16) @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" @@ -283,7 +282,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") @@ -464,7 +463,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) @@ -545,8 +544,8 @@ let @test lastindex(srep) == 7 - @test next(srep, 3) == ('β',5) - @test next(srep, 7) == ('β',9) + @test iterate(srep, 3) == ('β',5) + @test iterate(srep, 7) == ('β',9) @test srep[7] == 'β' @static if VERSION < v"0.7.0-DEV.2924" From 0ff52db87ccb4c5908200fd2590ceb4e63d8649f Mon Sep 17 00:00:00 2001 From: Carsten Bauer Date: Mon, 26 Nov 2018 20:06:13 +0100 Subject: [PATCH 3/3] fixed tests on 0.6 --- src/LegacyStrings.jl | 2 +- test/runtests.jl | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/LegacyStrings.jl b/src/LegacyStrings.jl index 02c0542..c65196c 100644 --- a/src/LegacyStrings.jl +++ b/src/LegacyStrings.jl @@ -48,7 +48,7 @@ import Compat: ncodeunits -if VERSION <= v"0.7-" +if VERSION < v"0.7-" import Base: lcfirst import Base: next import Base: rsearch diff --git a/test/runtests.jl b/test/runtests.jl index 8e64d12..6f69b81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -207,7 +207,11 @@ let ch = 0x10000 end let str = UTF8String(b"this is a test\xed\x80") - @test iterate(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) @@ -544,8 +548,13 @@ let @test lastindex(srep) == 7 - @test iterate(srep, 3) == ('β',5) - @test iterate(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"