Add: julia-0.6.2
Former-commit-id: ccc667cf67d569f3fb3df39aa57c2134755a7551
This commit is contained in:
		
							
								
								
									
										484
									
								
								julia-0.6.2/share/julia/test/strings/basic.jl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										484
									
								
								julia-0.6.2/share/julia/test/strings/basic.jl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,484 @@
 | 
			
		||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
 | 
			
		||||
 | 
			
		||||
# constructors
 | 
			
		||||
@test String([0x61,0x62,0x63,0x21]) == "abc!"
 | 
			
		||||
@test String("abc!") == "abc!"
 | 
			
		||||
 | 
			
		||||
@test isempty(string())
 | 
			
		||||
@test eltype(GenericString) == Char
 | 
			
		||||
@test start("abc") == 1
 | 
			
		||||
@test cmp("ab","abc") == -1
 | 
			
		||||
 | 
			
		||||
# {starts,ends}with
 | 
			
		||||
@test startswith("abcd", 'a')
 | 
			
		||||
@test startswith("abcd", "a")
 | 
			
		||||
@test startswith("abcd", "ab")
 | 
			
		||||
@test !startswith("ab", "abcd")
 | 
			
		||||
@test !startswith("abcd", "bc")
 | 
			
		||||
@test endswith("abcd", 'd')
 | 
			
		||||
@test endswith("abcd", "d")
 | 
			
		||||
@test endswith("abcd", "cd")
 | 
			
		||||
@test !endswith("abcd", "dc")
 | 
			
		||||
@test !endswith("cd", "abcd")
 | 
			
		||||
@test startswith("ab\0cd", "ab\0c")
 | 
			
		||||
@test !startswith("ab\0cd", "ab\0d")
 | 
			
		||||
 | 
			
		||||
@test filter(x -> x ∈ ['f', 'o'], "foobar") == "foo"
 | 
			
		||||
 | 
			
		||||
# string iteration, and issue #1454
 | 
			
		||||
str = "é"
 | 
			
		||||
str_a = vcat(str...)
 | 
			
		||||
@test length(str_a)==1
 | 
			
		||||
@test str_a[1] == str[1]
 | 
			
		||||
 | 
			
		||||
str = "s\u2200"
 | 
			
		||||
@test str[1:end] == str
 | 
			
		||||
 | 
			
		||||
# sizeof
 | 
			
		||||
@test sizeof("abc") == 3
 | 
			
		||||
@test sizeof("\u2222") == 3
 | 
			
		||||
 | 
			
		||||
# issue #3597
 | 
			
		||||
@test string(GenericString("Test")[1:1], "X") == "TX"
 | 
			
		||||
 | 
			
		||||
for T = (UInt8,Int8,UInt16,Int16,UInt32,Int32,UInt64,Int64,UInt128,Int128,BigInt),
 | 
			
		||||
    b = 2:62, _ = 1:10
 | 
			
		||||
    n = T != BigInt ? rand(T) : BigInt(rand(Int128))
 | 
			
		||||
    @test parse(T,base(b,n),b) == n
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# issue #6027
 | 
			
		||||
let
 | 
			
		||||
    # make symbol with invalid char
 | 
			
		||||
    sym = Symbol(Char(0xdcdb))
 | 
			
		||||
    @test string(sym) == string(Char(0xdcdb))
 | 
			
		||||
    @test String(sym) == string(Char(0xdcdb))
 | 
			
		||||
    @test expand(sym) === sym
 | 
			
		||||
    res = string(parse(string(Char(0xdcdb)," = 1"),1,raise=false)[1])
 | 
			
		||||
    @test res == """\$(Expr(:error, "invalid character \\\"\\udcdb\\\"\"))"""
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@test Symbol("asdf") === :asdf
 | 
			
		||||
@test Symbol(:abc,"def",'g',"hi",0) === :abcdefghi0
 | 
			
		||||
@test :a < :b
 | 
			
		||||
@test startswith(string(gensym("asdf")),"##asdf#")
 | 
			
		||||
@test gensym("asdf") != gensym("asdf")
 | 
			
		||||
@test gensym() != gensym()
 | 
			
		||||
@test startswith(string(gensym()),"##")
 | 
			
		||||
@test_throws ArgumentError Symbol("ab\0")
 | 
			
		||||
@test_throws ArgumentError gensym("ab\0")
 | 
			
		||||
 | 
			
		||||
# issue #6949
 | 
			
		||||
let f =IOBuffer(),
 | 
			
		||||
    x = split("1 2 3")
 | 
			
		||||
    @test write(f, x) == 3
 | 
			
		||||
    @test String(take!(f)) == "123"
 | 
			
		||||
    @test invoke(write, Tuple{IO, AbstractArray}, f, x) == 3
 | 
			
		||||
    @test String(take!(f)) == "123"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# issue #7248
 | 
			
		||||
@test_throws BoundsError ind2chr("hello", -1)
 | 
			
		||||
@test_throws BoundsError chr2ind("hello", -1)
 | 
			
		||||
@test_throws BoundsError ind2chr("hellø", -1)
 | 
			
		||||
@test_throws BoundsError chr2ind("hellø", -1)
 | 
			
		||||
@test_throws BoundsError ind2chr("hello", 10)
 | 
			
		||||
@test_throws BoundsError chr2ind("hello", 10)
 | 
			
		||||
@test_throws BoundsError ind2chr("hellø", 10)
 | 
			
		||||
@test_throws BoundsError chr2ind("hellø", 10)
 | 
			
		||||
@test_throws BoundsError checkbounds("hello", 0)
 | 
			
		||||
@test_throws BoundsError checkbounds("hello", 6)
 | 
			
		||||
@test_throws BoundsError checkbounds("hello", 0:3)
 | 
			
		||||
@test_throws BoundsError checkbounds("hello", 4:6)
 | 
			
		||||
@test_throws BoundsError checkbounds("hello", [0:3;])
 | 
			
		||||
@test_throws BoundsError checkbounds("hello", [4:6;])
 | 
			
		||||
@test checkbounds("hello", 2)
 | 
			
		||||
@test checkbounds("hello", 1:5)
 | 
			
		||||
@test checkbounds("hello", [1:5;])
 | 
			
		||||
 | 
			
		||||
# issue #15624 (indexing with out of bounds empty range)
 | 
			
		||||
@test ""[10:9] == ""
 | 
			
		||||
@test "hello"[10:9] == ""
 | 
			
		||||
@test "hellø"[10:9] == ""
 | 
			
		||||
@test SubString("hello", 1, 6)[10:9] == ""
 | 
			
		||||
@test SubString("hello", 1, 0)[10:9] == ""
 | 
			
		||||
@test SubString("hellø", 1, 6)[10:9] == ""
 | 
			
		||||
@test SubString("hellø", 1, 0)[10:9] == ""
 | 
			
		||||
@test SubString("", 1, 6)[10:9] == ""
 | 
			
		||||
@test SubString("", 1, 0)[10:9] == ""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#=
 | 
			
		||||
# issue #7764
 | 
			
		||||
let
 | 
			
		||||
    srep = repeat("Σβ",2)
 | 
			
		||||
    s="Σβ"
 | 
			
		||||
    ss=SubString(s,1,endof(s))
 | 
			
		||||
 | 
			
		||||
    @test repeat(ss,2) == "ΣβΣβ"
 | 
			
		||||
 | 
			
		||||
    @test endof(srep) == 7
 | 
			
		||||
 | 
			
		||||
    @test next(srep, 3) == ('β',5)
 | 
			
		||||
    @test next(srep, 7) == ('β',9)
 | 
			
		||||
 | 
			
		||||
    @test srep[7] == 'β'
 | 
			
		||||
    @test_throws BoundsError srep[8]
 | 
			
		||||
end
 | 
			
		||||
=#
 | 
			
		||||
 | 
			
		||||
# This caused JuliaLang/JSON.jl#82
 | 
			
		||||
@test first('\x00':'\x7f') === '\x00'
 | 
			
		||||
@test last('\x00':'\x7f') === '\x7f'
 | 
			
		||||
 | 
			
		||||
# make sure substrings handle last code unit even if not start of codepoint
 | 
			
		||||
let s = "x\u0302"
 | 
			
		||||
    @test s[1:3] == s
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# issue #9781
 | 
			
		||||
# float(SubString) wasn't tolerant of trailing whitespace, which was different
 | 
			
		||||
# to "normal" strings. This also checks we aren't being too tolerant and allowing
 | 
			
		||||
# any arbitrary trailing characters.
 | 
			
		||||
@test parse(Float64,"1\n") == 1.0
 | 
			
		||||
@test [parse(Float64,x) for x in split("0,1\n",",")][2] == 1.0
 | 
			
		||||
@test_throws ArgumentError parse(Float64,split("0,1 X\n",",")[2])
 | 
			
		||||
@test parse(Float32,"1\n") == 1.0
 | 
			
		||||
@test [parse(Float32,x) for x in split("0,1\n",",")][2] == 1.0
 | 
			
		||||
@test_throws ArgumentError parse(Float32,split("0,1 X\n",",")[2])
 | 
			
		||||
 | 
			
		||||
@test ucfirst("Hola")=="Hola"
 | 
			
		||||
@test ucfirst("hola")=="Hola"
 | 
			
		||||
@test ucfirst("")==""
 | 
			
		||||
@test ucfirst("*")=="*"
 | 
			
		||||
 | 
			
		||||
@test lcfirst("Hola")=="hola"
 | 
			
		||||
@test lcfirst("hola")=="hola"
 | 
			
		||||
@test lcfirst("")==""
 | 
			
		||||
@test lcfirst("*")=="*"
 | 
			
		||||
 | 
			
		||||
# test AbstractString functions at beginning of string.jl
 | 
			
		||||
struct tstStringType <: AbstractString
 | 
			
		||||
    data::Array{UInt8,1}
 | 
			
		||||
end
 | 
			
		||||
tstr = tstStringType("12")
 | 
			
		||||
@test_throws ErrorException endof(tstr)
 | 
			
		||||
@test_throws ErrorException next(tstr, Bool(1))
 | 
			
		||||
 | 
			
		||||
gstr = GenericString("12")
 | 
			
		||||
@test typeof(string(gstr))==GenericString
 | 
			
		||||
 | 
			
		||||
@test convert(Array{UInt8}, gstr) ==[49;50]
 | 
			
		||||
@test convert(Array{Char,1}, gstr) ==['1';'2']
 | 
			
		||||
@test convert(Symbol, gstr)==Symbol("12")
 | 
			
		||||
 | 
			
		||||
@test gstr[1] == '1'
 | 
			
		||||
@test gstr[1:1] == "1"
 | 
			
		||||
@test gstr[[1]] == "1"
 | 
			
		||||
 | 
			
		||||
@test done(eachindex("foobar"),7)
 | 
			
		||||
@test eltype(Base.EachStringIndex) == Int
 | 
			
		||||
@test map(uppercase, "foó") == "FOÓ"
 | 
			
		||||
@test chr2ind("fóobar",3) == 4
 | 
			
		||||
 | 
			
		||||
@test Symbol(gstr)==Symbol("12")
 | 
			
		||||
 | 
			
		||||
@test_throws ErrorException sizeof(gstr)
 | 
			
		||||
 | 
			
		||||
@test length(GenericString(""))==0
 | 
			
		||||
 | 
			
		||||
@test nextind(1:1, 1) == 2
 | 
			
		||||
@test nextind([1], 1) == 2
 | 
			
		||||
 | 
			
		||||
@test ind2chr(gstr,2)==2
 | 
			
		||||
 | 
			
		||||
# issue #10307
 | 
			
		||||
@test typeof(map(Int16,AbstractString[])) == Vector{Int16}
 | 
			
		||||
 | 
			
		||||
for T in [Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128]
 | 
			
		||||
    for i in [typemax(T), typemin(T)]
 | 
			
		||||
        s = "$i"
 | 
			
		||||
        @test get(tryparse(T, s)) == i
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
for T in [Int8, Int16, Int32, Int64, Int128]
 | 
			
		||||
    for i in [typemax(T), typemin(T)]
 | 
			
		||||
        f = "$(i)0"
 | 
			
		||||
        @test isnull(tryparse(T, f))
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# issue #11142
 | 
			
		||||
s = "abcdefghij"
 | 
			
		||||
sp = pointer(s)
 | 
			
		||||
@test unsafe_string(sp) == s
 | 
			
		||||
@test unsafe_string(sp,5) == "abcde"
 | 
			
		||||
@test typeof(unsafe_string(sp)) == String
 | 
			
		||||
s = "abcde\uff\u2000\U1f596"
 | 
			
		||||
sp = pointer(s)
 | 
			
		||||
@test unsafe_string(sp) == s
 | 
			
		||||
@test unsafe_string(sp,5) == "abcde"
 | 
			
		||||
@test typeof(unsafe_string(sp)) == String
 | 
			
		||||
 | 
			
		||||
@test get(tryparse(BigInt, "1234567890")) == BigInt(1234567890)
 | 
			
		||||
@test isnull(tryparse(BigInt, "1234567890-"))
 | 
			
		||||
 | 
			
		||||
@test get(tryparse(Float64, "64")) == 64.0
 | 
			
		||||
@test isnull(tryparse(Float64, "64o"))
 | 
			
		||||
@test get(tryparse(Float32, "32")) == 32.0f0
 | 
			
		||||
@test isnull(tryparse(Float32, "32o"))
 | 
			
		||||
 | 
			
		||||
# issue #10994: handle embedded NUL chars for string parsing
 | 
			
		||||
for T in [BigInt, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128]
 | 
			
		||||
    @test_throws ArgumentError parse(T, "1\0")
 | 
			
		||||
end
 | 
			
		||||
for T in [BigInt, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128, Float64, Float32]
 | 
			
		||||
    @test isnull(tryparse(T, "1\0"))
 | 
			
		||||
end
 | 
			
		||||
let s = normalize_string("tést",:NFKC)
 | 
			
		||||
    @test unsafe_string(Base.unsafe_convert(Cstring, Base.cconvert(Cstring, s))) == s
 | 
			
		||||
    @test unsafe_string(convert(Cstring, Symbol(s))) == s
 | 
			
		||||
end
 | 
			
		||||
@test_throws ArgumentError Base.unsafe_convert(Cstring, Base.cconvert(Cstring, "ba\0d"))
 | 
			
		||||
 | 
			
		||||
cstrdup(s) = @static is_windows() ? ccall(:_strdup, Cstring, (Cstring,), s) : ccall(:strdup, Cstring, (Cstring,), s)
 | 
			
		||||
let p = cstrdup("hello")
 | 
			
		||||
    @test unsafe_string(p) == "hello"
 | 
			
		||||
    Libc.free(p)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# iteration
 | 
			
		||||
@test [c for c in "ḟøøƀäṙ"] == ['ḟ', 'ø', 'ø', 'ƀ', 'ä', 'ṙ']
 | 
			
		||||
@test [i for i in eachindex("ḟøøƀäṙ")] == [1, 4, 6, 8, 10, 12]
 | 
			
		||||
@test [x for x in enumerate("ḟøøƀäṙ")] == [(1, 'ḟ'), (2, 'ø'), (3, 'ø'), (4, 'ƀ'), (5, 'ä'), (6, 'ṙ')]
 | 
			
		||||
 | 
			
		||||
# test all edge conditions
 | 
			
		||||
for (val, pass) in (
 | 
			
		||||
        (0, true), (0xd7ff, true),
 | 
			
		||||
        (0xd800, false), (0xdfff, false),
 | 
			
		||||
        (0xe000, true), (0xffff, true),
 | 
			
		||||
        (0x10000, true), (0x10ffff, true),
 | 
			
		||||
        (0x110000, false)
 | 
			
		||||
    )
 | 
			
		||||
    @test isvalid(Char, val) == pass
 | 
			
		||||
end
 | 
			
		||||
for (val, pass) in (
 | 
			
		||||
        (b"\x00", true),
 | 
			
		||||
        (b"\x7f", true),
 | 
			
		||||
        (b"\x80", false),
 | 
			
		||||
        (b"\xbf", false),
 | 
			
		||||
        (b"\xc0", false),
 | 
			
		||||
        (b"\xff", false),
 | 
			
		||||
        (b"\xc0\x80", false),
 | 
			
		||||
        (b"\xc1\x80", false),
 | 
			
		||||
        (b"\xc2\x80", true),
 | 
			
		||||
        (b"\xc2\xc0", false),
 | 
			
		||||
        (b"\xed\x9f\xbf", true),
 | 
			
		||||
        (b"\xed\xa0\x80", false),
 | 
			
		||||
        (b"\xed\xbf\xbf", false),
 | 
			
		||||
        (b"\xee\x80\x80", true),
 | 
			
		||||
        (b"\xef\xbf\xbf", true),
 | 
			
		||||
        (b"\xf0\x90\x80\x80", true),
 | 
			
		||||
        (b"\xf4\x8f\xbf\xbf", true),
 | 
			
		||||
        (b"\xf4\x90\x80\x80", false),
 | 
			
		||||
        (b"\xf5\x80\x80\x80", false),
 | 
			
		||||
        (b"\ud800\udc00", false),
 | 
			
		||||
        (b"\udbff\udfff", false),
 | 
			
		||||
        (b"\ud800\u0100", false),
 | 
			
		||||
        (b"\udc00\u0100", false),
 | 
			
		||||
        (b"\udc00\ud800", false)
 | 
			
		||||
        )
 | 
			
		||||
    @test isvalid(String, val) == pass == isvalid(String(val))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Issue #11203
 | 
			
		||||
@test isvalid(String, UInt8[]) == true == isvalid("")
 | 
			
		||||
 | 
			
		||||
# Check UTF-8 characters
 | 
			
		||||
# Check ASCII range (true),
 | 
			
		||||
# then single continuation bytes and lead bytes with no following continuation bytes (false)
 | 
			
		||||
for (rng,flg) in ((0:0x7f, true), (0x80:0xff, false))
 | 
			
		||||
    for byt in rng
 | 
			
		||||
        @test isvalid(String, UInt8[byt]) == flg
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
# Check overlong lead bytes for 2-character sequences (false)
 | 
			
		||||
for byt = 0xc0:0xc1
 | 
			
		||||
    @test isvalid(String, UInt8[byt,0x80]) == false
 | 
			
		||||
end
 | 
			
		||||
# Check valid lead-in to two-byte sequences (true)
 | 
			
		||||
for byt = 0xc2:0xdf
 | 
			
		||||
    for (rng,flg) in ((0x00:0x7f, false), (0x80:0xbf, true), (0xc0:0xff, false))
 | 
			
		||||
        for cont in rng
 | 
			
		||||
            @test isvalid(String, UInt8[byt, cont]) == flg
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
# Check three-byte sequences
 | 
			
		||||
for r1 in (0xe0:0xec, 0xee:0xef)
 | 
			
		||||
    for byt = r1
 | 
			
		||||
        # Check for short sequence
 | 
			
		||||
        @test isvalid(String, UInt8[byt]) == false
 | 
			
		||||
        for (rng,flg) in ((0x00:0x7f, false), (0x80:0xbf, true), (0xc0:0xff, false))
 | 
			
		||||
            for cont in rng
 | 
			
		||||
                @test isvalid(String, UInt8[byt, cont]) == false
 | 
			
		||||
                @test isvalid(String, UInt8[byt, cont, 0x80]) == flg
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
# Check hangul characters (0xd000-0xd7ff) hangul
 | 
			
		||||
# Check for short sequence, or start of surrogate pair
 | 
			
		||||
for (rng,flg) in ((0x00:0x7f, false), (0x80:0x9f, true), (0xa0:0xff, false))
 | 
			
		||||
    for cont in rng
 | 
			
		||||
        @test isvalid(String, UInt8[0xed, cont]) == false
 | 
			
		||||
        @test isvalid(String, UInt8[0xed, cont, 0x80]) == flg
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
# Check valid four-byte sequences
 | 
			
		||||
for byt = 0xf0:0xf4
 | 
			
		||||
    if (byt == 0xf0)
 | 
			
		||||
        r0 = ((0x00:0x8f, false), (0x90:0xbf, true), (0xc0:0xff, false))
 | 
			
		||||
    elseif byt == 0xf4
 | 
			
		||||
        r0 = ((0x00:0x7f, false), (0x80:0x8f, true), (0x90:0xff, false))
 | 
			
		||||
    else
 | 
			
		||||
        r0 = ((0x00:0x7f, false), (0x80:0xbf, true), (0xc0:0xff, false))
 | 
			
		||||
    end
 | 
			
		||||
    for (rng,flg) in r0
 | 
			
		||||
        for cont in rng
 | 
			
		||||
            @test isvalid(String, UInt8[byt, cont]) == false
 | 
			
		||||
            @test isvalid(String, UInt8[byt, cont, 0x80]) == false
 | 
			
		||||
            @test isvalid(String, UInt8[byt, cont, 0x80, 0x80]) == flg
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
# Check five-byte sequences, should be invalid
 | 
			
		||||
for byt = 0xf8:0xfb
 | 
			
		||||
    @test isvalid(String, UInt8[byt, 0x80, 0x80, 0x80, 0x80]) == false
 | 
			
		||||
end
 | 
			
		||||
# Check six-byte sequences, should be invalid
 | 
			
		||||
for byt = 0xfc:0xfd
 | 
			
		||||
    @test isvalid(String, UInt8[byt, 0x80, 0x80, 0x80, 0x80, 0x80]) == false
 | 
			
		||||
end
 | 
			
		||||
# Check seven-byte sequences, should be invalid
 | 
			
		||||
@test isvalid(String, UInt8[0xfe, 0x80, 0x80, 0x80, 0x80, 0x80]) == false
 | 
			
		||||
 | 
			
		||||
# 11482
 | 
			
		||||
 | 
			
		||||
# lower and upper
 | 
			
		||||
@test uppercase("aBc") == "ABC"
 | 
			
		||||
@test uppercase('A') == 'A'
 | 
			
		||||
@test uppercase('a') == 'A'
 | 
			
		||||
@test lowercase("AbC") == "abc"
 | 
			
		||||
@test lowercase('A') == 'a'
 | 
			
		||||
@test lowercase('a') == 'a'
 | 
			
		||||
@test uppercase('α') == '\u0391'
 | 
			
		||||
@test lowercase('Δ') == 'δ'
 | 
			
		||||
@test lowercase('\U118bf') == '\U118df'
 | 
			
		||||
@test uppercase('\U1044d') == '\U10425'
 | 
			
		||||
@test ucfirst("Abc") == "Abc"
 | 
			
		||||
@test ucfirst("abc") == "Abc"
 | 
			
		||||
@test lcfirst("ABC") == "aBC"
 | 
			
		||||
@test lcfirst("aBC") == "aBC"
 | 
			
		||||
@test ucfirst(GenericString("")) == ""
 | 
			
		||||
@test lcfirst(GenericString("")) == ""
 | 
			
		||||
@test ucfirst(GenericString("a")) == "A"
 | 
			
		||||
@test lcfirst(GenericString("A")) == "a"
 | 
			
		||||
@test lcfirst(GenericString("a")) == "a"
 | 
			
		||||
@test ucfirst(GenericString("A")) == "A"
 | 
			
		||||
 | 
			
		||||
# titlecase
 | 
			
		||||
@test titlecase('lj') == 'Lj'
 | 
			
		||||
@test titlecase("ljubljana") == "Ljubljana"
 | 
			
		||||
@test titlecase("aBc ABC") == "ABc ABC"
 | 
			
		||||
@test titlecase("abcD   EFG\n\thij") == "AbcD   EFG\n\tHij"
 | 
			
		||||
 | 
			
		||||
# issue # 11464: uppercase/lowercase of GenericString becomes a String
 | 
			
		||||
str = "abcdef\uff\uffff\u10ffffABCDEF"
 | 
			
		||||
@test typeof(uppercase("abcdef")) == String
 | 
			
		||||
@test typeof(uppercase(GenericString(str))) == String
 | 
			
		||||
@test typeof(lowercase("ABCDEF")) == String
 | 
			
		||||
@test typeof(lowercase(GenericString(str))) == String
 | 
			
		||||
 | 
			
		||||
foomap(ch) = (ch > Char(65))
 | 
			
		||||
foobar(ch) = Char(0xd800)
 | 
			
		||||
foobaz(ch) = reinterpret(Char, typemax(UInt32))
 | 
			
		||||
@test_throws ArgumentError map(foomap, GenericString(str))
 | 
			
		||||
@test map(foobar, GenericString(str)) == String(repeat(b"\ud800", outer=[17]))
 | 
			
		||||
@test map(foobaz, GenericString(str)) == String(repeat(b"\ufffd", outer=[17]))
 | 
			
		||||
 | 
			
		||||
@test "a".*["b","c"] == ["ab","ac"]
 | 
			
		||||
@test ["b","c"].*"a" == ["ba","ca"]
 | 
			
		||||
@test ["a","b"].*["c" "d"] == ["ac" "ad"; "bc" "bd"]
 | 
			
		||||
 | 
			
		||||
@test one(String) == ""
 | 
			
		||||
@test prod(["*" for i in 1:3]) == "***"
 | 
			
		||||
@test prod(["*" for i in 1:0]) == ""
 | 
			
		||||
 | 
			
		||||
# Make sure NULL pointers are handled consistently by String
 | 
			
		||||
@test_throws ArgumentError unsafe_string(Ptr{UInt8}(0))
 | 
			
		||||
@test_throws ArgumentError unsafe_string(Ptr{UInt8}(0), 10)
 | 
			
		||||
 | 
			
		||||
# ascii works on ASCII strings and fails on non-ASCII strings
 | 
			
		||||
@test ascii("Hello, world") == "Hello, world"
 | 
			
		||||
@test typeof(ascii("Hello, world")) == String
 | 
			
		||||
@test ascii(GenericString("Hello, world")) == "Hello, world"
 | 
			
		||||
@test typeof(ascii(GenericString("Hello, world"))) == String
 | 
			
		||||
@test_throws ArgumentError ascii("Hello, ∀")
 | 
			
		||||
@test_throws ArgumentError ascii(GenericString("Hello, ∀"))
 | 
			
		||||
 | 
			
		||||
# issue #17271: endof() doesn't throw an error even with invalid strings
 | 
			
		||||
@test endof(String(b"\x90")) == 0
 | 
			
		||||
@test endof(String(b"\xce")) == 1
 | 
			
		||||
 | 
			
		||||
# issue #17624, missing getindex method for String
 | 
			
		||||
@test "abc"[:] == "abc"
 | 
			
		||||
 | 
			
		||||
# issue #18280: next/nextind must return past String's underlying data
 | 
			
		||||
for s in ("Hello", "Σ", "こんにちは", "😊😁")
 | 
			
		||||
    @test next(s, endof(s))[2] > sizeof(s)
 | 
			
		||||
    @test nextind(s, endof(s)) > sizeof(s)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Test cmp with AbstractStrings that don't index the same as UTF-8, which would include
 | 
			
		||||
# (LegacyString.)UTF16String and (LegacyString.)UTF32String, among others.
 | 
			
		||||
 | 
			
		||||
mutable struct CharStr <: AbstractString
 | 
			
		||||
    chars::Vector{Char}
 | 
			
		||||
    CharStr(x) = new(collect(x))
 | 
			
		||||
end
 | 
			
		||||
Base.start(x::CharStr) = start(x.chars)
 | 
			
		||||
Base.next(x::CharStr, i::Int) = next(x.chars, i)
 | 
			
		||||
Base.done(x::CharStr, i::Int) = done(x.chars, i)
 | 
			
		||||
Base.endof(x::CharStr) = endof(x.chars)
 | 
			
		||||
 | 
			
		||||
# Simple case, with just ANSI Latin 1 characters
 | 
			
		||||
@test "áB" != CharStr("áá") # returns false with bug
 | 
			
		||||
@test cmp("áB", CharStr("áá")) == -1 # returns 0 with bug
 | 
			
		||||
 | 
			
		||||
# Case with Unicode characters
 | 
			
		||||
@test cmp("\U1f596\U1f596", CharStr("\U1f596")) == 1   # Gives BoundsError with bug
 | 
			
		||||
@test cmp(CharStr("\U1f596"), "\U1f596\U1f596") == -1
 | 
			
		||||
 | 
			
		||||
# repeat function
 | 
			
		||||
@test repeat("xx",3) == repeat("x",6) == "xxxxxx"
 | 
			
		||||
@test repeat("αα",3) == repeat("α",6) == "αααααα"
 | 
			
		||||
 | 
			
		||||
# issue #12495: check that logical indexing attempt raises ArgumentError
 | 
			
		||||
@test_throws ArgumentError "abc"[[true, false, true]]
 | 
			
		||||
@test_throws ArgumentError "abc"[BitArray([true, false, true])]
 | 
			
		||||
 | 
			
		||||
@testset "invalid code point" begin
 | 
			
		||||
    s = String([0x61, 0xba, 0x41])
 | 
			
		||||
    @test !isvalid(s)
 | 
			
		||||
    @test_throws UnicodeError s[2]
 | 
			
		||||
    e = try
 | 
			
		||||
        s[2]
 | 
			
		||||
    catch e
 | 
			
		||||
        e
 | 
			
		||||
    end
 | 
			
		||||
    b = IOBuffer()
 | 
			
		||||
    show(b, e)
 | 
			
		||||
    @test String(take!(b)) == "UnicodeError: invalid character index 2 (0xba is a continuation byte)"
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										276
									
								
								julia-0.6.2/share/julia/test/strings/io.jl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										276
									
								
								julia-0.6.2/share/julia/test/strings/io.jl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,276 @@
 | 
			
		||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
 | 
			
		||||
 | 
			
		||||
# string escaping & unescaping
 | 
			
		||||
cx = Any[
 | 
			
		||||
    0x00000000      '\0'        "\\0"
 | 
			
		||||
    0x00000001      '\x01'      "\\x01"
 | 
			
		||||
    0x00000006      '\x06'      "\\x06"
 | 
			
		||||
    0x00000007      '\a'        "\\a"
 | 
			
		||||
    0x00000008      '\b'        "\\b"
 | 
			
		||||
    0x00000009      '\t'        "\\t"
 | 
			
		||||
    0x0000000a      '\n'        "\\n"
 | 
			
		||||
    0x0000000b      '\v'        "\\v"
 | 
			
		||||
    0x0000000c      '\f'        "\\f"
 | 
			
		||||
    0x0000000d      '\r'        "\\r"
 | 
			
		||||
    0x0000000e      '\x0e'      "\\x0e"
 | 
			
		||||
    0x0000001a      '\x1a'      "\\x1a"
 | 
			
		||||
    0x0000001b      '\e'        "\\e"
 | 
			
		||||
    0x0000001c      '\x1c'      "\\x1c"
 | 
			
		||||
    0x0000001f      '\x1f'      "\\x1f"
 | 
			
		||||
    0x00000020      ' '         " "
 | 
			
		||||
    0x0000002f      '/'         "/"
 | 
			
		||||
    0x00000030      '0'         "0"
 | 
			
		||||
    0x00000039      '9'         "9"
 | 
			
		||||
    0x0000003a      ':'         ":"
 | 
			
		||||
    0x00000040      '@'         "@"
 | 
			
		||||
    0x00000041      'A'         "A"
 | 
			
		||||
    0x0000005a      'Z'         "Z"
 | 
			
		||||
    0x0000005b      '['         "["
 | 
			
		||||
    0x00000060      '`'         "`"
 | 
			
		||||
    0x00000061      'a'         "a"
 | 
			
		||||
    0x0000007a      'z'         "z"
 | 
			
		||||
    0x0000007b      '{'         "{"
 | 
			
		||||
    0x0000007e      '~'         "~"
 | 
			
		||||
    0x0000007f      '\x7f'      "\\x7f"
 | 
			
		||||
    0x000000bf      '\ubf'      "\\ubf"
 | 
			
		||||
    0x000000ff      '\uff'      "\\uff"
 | 
			
		||||
    0x00000100      '\u100'     "\\u100"
 | 
			
		||||
    0x000001ff      '\u1ff'     "\\u1ff"
 | 
			
		||||
    0x00000fff      '\ufff'     "\\ufff"
 | 
			
		||||
    0x00001000      '\u1000'    "\\u1000"
 | 
			
		||||
    0x00001fff      '\u1fff'    "\\u1fff"
 | 
			
		||||
    0x0000ffff      '\uffff'    "\\uffff"
 | 
			
		||||
    0x00010000      '\U10000'   "\\U10000"
 | 
			
		||||
    0x0001ffff      '\U1ffff'   "\\U1ffff"
 | 
			
		||||
    0x0002ffff      '\U2ffff'   "\\U2ffff"
 | 
			
		||||
    0x00030000      '\U30000'   "\\U30000"
 | 
			
		||||
    0x000dffff      '\Udffff'   "\\Udffff"
 | 
			
		||||
    0x000e0000      '\Ue0000'   "\\Ue0000"
 | 
			
		||||
    0x000effff      '\Ueffff'   "\\Ueffff"
 | 
			
		||||
    0x000f0000      '\Uf0000'   "\\Uf0000"
 | 
			
		||||
    0x000fffff      '\Ufffff'   "\\Ufffff"
 | 
			
		||||
    0x00100000      '\U100000'  "\\U100000"
 | 
			
		||||
    0x0010ffff      '\U10ffff'  "\\U10ffff"
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
for i = 1:size(cx,1)
 | 
			
		||||
    cp, ch, st = cx[i,:]
 | 
			
		||||
    @test cp == convert(UInt32, ch)
 | 
			
		||||
    @test string(ch) == unescape_string(st)
 | 
			
		||||
    if isascii(ch) || !isprint(ch)
 | 
			
		||||
        @test st == escape_string(string(ch))
 | 
			
		||||
    end
 | 
			
		||||
    for j = 1:size(cx,1)
 | 
			
		||||
        str = string(ch, cx[j,2])
 | 
			
		||||
        @test str == unescape_string(escape_string(str))
 | 
			
		||||
    end
 | 
			
		||||
    @test repr(ch) == "'$(isprint(ch) ? ch : st)'"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
for i = 0:0x7f, p = ["","\0","x","xxx","\x7f","\uFF","\uFFF",
 | 
			
		||||
                     "\uFFFF","\U10000","\U10FFF","\U10FFFF"]
 | 
			
		||||
    c = Char(i)
 | 
			
		||||
    cp = string(c,p)
 | 
			
		||||
    op = string(Char(div(i,8)), oct(i%8), p)
 | 
			
		||||
    hp = string(Char(div(i,16)), hex(i%16), p)
 | 
			
		||||
    @test string(unescape_string(string("\\",oct(i,1),p))) == cp
 | 
			
		||||
    @test string(unescape_string(string("\\",oct(i,2),p))) == cp
 | 
			
		||||
    @test string(unescape_string(string("\\",oct(i,3),p))) == cp
 | 
			
		||||
    @test string(unescape_string(string("\\",oct(i,4),p))) == op
 | 
			
		||||
    @test string(unescape_string(string("\\x",hex(i,1),p))) == cp
 | 
			
		||||
    @test string(unescape_string(string("\\x",hex(i,2),p))) == cp
 | 
			
		||||
    @test string(unescape_string(string("\\x",hex(i,3),p))) == hp
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@test "\z" == unescape_string("\z") == "z"
 | 
			
		||||
@test "\X" == unescape_string("\X") == "X"
 | 
			
		||||
@test "\AbC" == unescape_string("\AbC") == "AbC"
 | 
			
		||||
 | 
			
		||||
@test "\0" == unescape_string("\\0")
 | 
			
		||||
@test "\1" == unescape_string("\\1")
 | 
			
		||||
@test "\7" == unescape_string("\\7")
 | 
			
		||||
@test "\0x" == unescape_string("\\0x")
 | 
			
		||||
@test "\1x" == unescape_string("\\1x")
 | 
			
		||||
@test "\7x" == unescape_string("\\7x")
 | 
			
		||||
@test "\00" == unescape_string("\\00")
 | 
			
		||||
@test "\01" == unescape_string("\\01")
 | 
			
		||||
@test "\07" == unescape_string("\\07")
 | 
			
		||||
@test "\70" == unescape_string("\\70")
 | 
			
		||||
@test "\71" == unescape_string("\\71")
 | 
			
		||||
@test "\77" == unescape_string("\\77")
 | 
			
		||||
@test "\00x" == unescape_string("\\00x")
 | 
			
		||||
@test "\01x" == unescape_string("\\01x")
 | 
			
		||||
@test "\07x" == unescape_string("\\07x")
 | 
			
		||||
@test "\70x" == unescape_string("\\70x")
 | 
			
		||||
@test "\71x" == unescape_string("\\71x")
 | 
			
		||||
@test "\77x" == unescape_string("\\77x")
 | 
			
		||||
@test "\000" == unescape_string("\\000")
 | 
			
		||||
@test "\001" == unescape_string("\\001")
 | 
			
		||||
@test "\007" == unescape_string("\\007")
 | 
			
		||||
@test "\070" == unescape_string("\\070")
 | 
			
		||||
@test "\071" == unescape_string("\\071")
 | 
			
		||||
@test "\077" == unescape_string("\\077")
 | 
			
		||||
@test "\170" == unescape_string("\\170")
 | 
			
		||||
@test "\171" == unescape_string("\\171")
 | 
			
		||||
@test "\177" == unescape_string("\\177")
 | 
			
		||||
@test "\0001" == unescape_string("\\0001")
 | 
			
		||||
@test "\0011" == unescape_string("\\0011")
 | 
			
		||||
@test "\0071" == unescape_string("\\0071")
 | 
			
		||||
@test "\0701" == unescape_string("\\0701")
 | 
			
		||||
@test "\0711" == unescape_string("\\0711")
 | 
			
		||||
@test "\0771" == unescape_string("\\0771")
 | 
			
		||||
@test "\1701" == unescape_string("\\1701")
 | 
			
		||||
@test "\1711" == unescape_string("\\1711")
 | 
			
		||||
@test "\1771" == unescape_string("\\1771")
 | 
			
		||||
 | 
			
		||||
@test "\x0" == unescape_string("\\x0")
 | 
			
		||||
@test "\x1" == unescape_string("\\x1")
 | 
			
		||||
@test "\xf" == unescape_string("\\xf")
 | 
			
		||||
@test "\xF" == unescape_string("\\xF")
 | 
			
		||||
@test "\x0x" == unescape_string("\\x0x")
 | 
			
		||||
@test "\x1x" == unescape_string("\\x1x")
 | 
			
		||||
@test "\xfx" == unescape_string("\\xfx")
 | 
			
		||||
@test "\xFx" == unescape_string("\\xFx")
 | 
			
		||||
@test "\x00" == unescape_string("\\x00")
 | 
			
		||||
@test "\x01" == unescape_string("\\x01")
 | 
			
		||||
@test "\x0f" == unescape_string("\\x0f")
 | 
			
		||||
@test "\x0F" == unescape_string("\\x0F")
 | 
			
		||||
 | 
			
		||||
# Tests of join()
 | 
			
		||||
@test join([]) == ""
 | 
			
		||||
@test join(["a"],"?") == "a"
 | 
			
		||||
@test join("HELLO",'-') == "H-E-L-L-O"
 | 
			
		||||
@test join(1:5, ", ", " and ") == "1, 2, 3, 4 and 5"
 | 
			
		||||
@test join(["apples", "bananas", "pineapples"], ", ", " and ") == "apples, bananas and pineapples"
 | 
			
		||||
 | 
			
		||||
# issue #9178 `join` calls `done()` twice on the iterables
 | 
			
		||||
mutable struct i9178
 | 
			
		||||
    nnext::Int64
 | 
			
		||||
    ndone::Int64
 | 
			
		||||
end
 | 
			
		||||
Base.start(jt::i9178) = (jt.nnext=0 ; jt.ndone=0 ; 0)
 | 
			
		||||
Base.done(jt::i9178, n) = (jt.ndone += 1 ; n > 3)
 | 
			
		||||
Base.next(jt::i9178, n) = (jt.nnext += 1 ; ("$(jt.nnext),$(jt.ndone)", n+1))
 | 
			
		||||
@test join(i9178(0,0), ";") == "1,1;2,2;3,3;4,4"
 | 
			
		||||
 | 
			
		||||
# quotes + interpolation (issue #455)
 | 
			
		||||
@test "$("string")" == "string"
 | 
			
		||||
arr = ["a","b","c"]
 | 
			
		||||
@test "[$(join(arr, " - "))]" == "[a - b - c]"
 | 
			
		||||
 | 
			
		||||
# join with empty input
 | 
			
		||||
myio = IOBuffer()
 | 
			
		||||
join(myio, "", "", 1)
 | 
			
		||||
@test isempty(take!(myio))
 | 
			
		||||
 | 
			
		||||
# unescape_chars
 | 
			
		||||
@test Base.unescape_chars("\\t","t") == "t"
 | 
			
		||||
@test_throws ArgumentError unescape_string(IOBuffer(), string('\\',"xZ"))
 | 
			
		||||
@test_throws ArgumentError unescape_string(IOBuffer(), string('\\',"777"))
 | 
			
		||||
 | 
			
		||||
# 11659
 | 
			
		||||
# The indentation code was not correctly counting tab stops
 | 
			
		||||
@test Base.indentation("      \t") == (8, true)
 | 
			
		||||
@test Base.indentation("  \tfoob") == (8, false)
 | 
			
		||||
@test Base.indentation(" \t \t")   == (16, true)
 | 
			
		||||
 | 
			
		||||
@test Base.unindent("\tfoo",0) == "\tfoo"
 | 
			
		||||
@test Base.unindent("\tfoo",4) == "    foo"
 | 
			
		||||
@test Base.unindent("    \tfoo",4) == "    foo"
 | 
			
		||||
@test Base.unindent("\t\n    \tfoo",4) == "    \n    foo"
 | 
			
		||||
@test Base.unindent("\tfoo\tbar",4) == "    foo     bar"
 | 
			
		||||
@test Base.unindent("\n\tfoo",4) == "\n    foo"
 | 
			
		||||
@test Base.unindent("\n    \tfoo",4) == "\n    foo"
 | 
			
		||||
@test Base.unindent("\n\t\n    \tfoo",4) == "\n    \n    foo"
 | 
			
		||||
@test Base.unindent("\n\tfoo\tbar",4) == "\n    foo     bar"
 | 
			
		||||
 | 
			
		||||
# Tests of raw_str macro
 | 
			
		||||
@test raw"$" == "\$"
 | 
			
		||||
@test raw"\n" == "\\n"
 | 
			
		||||
@test raw"\t" == "\\t"
 | 
			
		||||
 | 
			
		||||
s1 = raw"""
 | 
			
		||||
     lorem ipsum\n
 | 
			
		||||
     $x = 1$
 | 
			
		||||
     """
 | 
			
		||||
 | 
			
		||||
s2 = """
 | 
			
		||||
     lorem ipsum\\n
 | 
			
		||||
     \$x = 1\$
 | 
			
		||||
     """
 | 
			
		||||
 | 
			
		||||
@test s1 == s2
 | 
			
		||||
 | 
			
		||||
# issue #22021, string realloc bug with join
 | 
			
		||||
s22021 = String["\"\"\"
 | 
			
		||||
     non_max_suppression(boxes, scores, max_output_size; iou_threshold=nothing)
 | 
			
		||||
 | 
			
		||||
Greedily selects a subset of bounding boxes in descending order of score,
 | 
			
		||||
 | 
			
		||||
pruning away boxes that have high intersection-over-union (IOU) overlap
 | 
			
		||||
with previously selected boxes.  Bounding boxes are supplied as
 | 
			
		||||
[y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any
 | 
			
		||||
diagonal pair of box corners and the coordinates can be provided as normalized
 | 
			
		||||
(i.e., lying in the interval [0, 1]) or absolute.  Note that this algorithm
 | 
			
		||||
is agnostic to where the origin is in the coordinate system.  Note that this
 | 
			
		||||
algorithm is invariant to orthogonal transformations and translations
 | 
			
		||||
of the coordinate system; thus translating or reflections of the coordinate
 | 
			
		||||
system result in the same boxes being selected by the algorithm.
 | 
			
		||||
 | 
			
		||||
The output of this operation is a set of integers indexing into the input
 | 
			
		||||
collection of bounding boxes representing the selected boxes.  The bounding
 | 
			
		||||
box coordinates corresponding to the selected indices can then be obtained
 | 
			
		||||
using the `tf.gather operation`.  For example:
 | 
			
		||||
 | 
			
		||||
  selected_indices = tf.image.non_max_suppression(
 | 
			
		||||
      boxes, scores, max_output_size, iou_threshold)
 | 
			
		||||
  selected_boxes = tf.gather(boxes, selected_indices)
 | 
			
		||||
\"\"\"",
 | 
			
		||||
    "    tf.@op function non_max_suppression(v13566, v13567, v13568; name=nothing, iou_threshold=nothing) ",
 | 
			
		||||
    "            local desc ",
 | 
			
		||||
    "            tf.with_op_name((()->begin  ",
 | 
			
		||||
    "                        desc = tf.NodeDescription(\"NonMaxSuppression\") ",
 | 
			
		||||
    "                        begin  ",
 | 
			
		||||
    "                            begin  ",
 | 
			
		||||
    "                                v13566 = convert(TensorFlow.Tensor{Float32}, v13566) ",
 | 
			
		||||
    "                                begin  ",
 | 
			
		||||
    "                                end",
 | 
			
		||||
    "                            end",
 | 
			
		||||
    "                            begin  ",
 | 
			
		||||
    "                                v13567 = convert(TensorFlow.Tensor{Float32}, v13567) ",
 | 
			
		||||
    "                                begin  ",
 | 
			
		||||
    "                                end",
 | 
			
		||||
    "                            end",
 | 
			
		||||
    "                            begin  ",
 | 
			
		||||
    "                                v13568 = convert(TensorFlow.Tensor{Int32}, v13568) ",
 | 
			
		||||
    "                                begin  ",
 | 
			
		||||
    "                                end",
 | 
			
		||||
    "                            end",
 | 
			
		||||
    "                        end ",
 | 
			
		||||
    "                        begin  ",
 | 
			
		||||
    "                            begin  ",
 | 
			
		||||
    "                                tf.add_input(desc, v13566)",
 | 
			
		||||
    "                            end",
 | 
			
		||||
    "                            begin  ",
 | 
			
		||||
    "                                tf.add_input(desc, v13567)",
 | 
			
		||||
    "                            end",
 | 
			
		||||
    "                            begin  ",
 | 
			
		||||
    "                                tf.add_input(desc, v13568)",
 | 
			
		||||
    "                            end",
 | 
			
		||||
    "                        end ",
 | 
			
		||||
    "                        begin  ",
 | 
			
		||||
    "                            begin  ",
 | 
			
		||||
    "                                if iou_threshold !== nothing ",
 | 
			
		||||
    "                                    desc[\"iou_threshold\"] = Base.identity(iou_threshold)",
 | 
			
		||||
    "                                end",
 | 
			
		||||
    "                            end",
 | 
			
		||||
    "                        end",
 | 
			
		||||
    "                    end), name, \"NonMaxSuppression\") ",
 | 
			
		||||
    "            tf.Tensor(tf.Operation(desc))",
 | 
			
		||||
    "        end"]
 | 
			
		||||
 | 
			
		||||
for i = 1:10
 | 
			
		||||
    buf = IOBuffer()
 | 
			
		||||
    print(buf, join(s22021, "\n"))
 | 
			
		||||
    @test isvalid(String, take!(buf))
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										377
									
								
								julia-0.6.2/share/julia/test/strings/search.jl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										377
									
								
								julia-0.6.2/share/julia/test/strings/search.jl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,377 @@
 | 
			
		||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
 | 
			
		||||
 | 
			
		||||
# some test strings
 | 
			
		||||
astr = "Hello, world.\n"
 | 
			
		||||
u8str = "∀ ε > 0, ∃ δ > 0: |x-y| < δ ⇒ |f(x)-f(y)| < ε"
 | 
			
		||||
 | 
			
		||||
# I think these should give error on 4 also, and "" is not treated
 | 
			
		||||
# consistently with SubString("",1,1), nor with Char[]
 | 
			
		||||
for ind in (0, 5)
 | 
			
		||||
    @test_throws BoundsError search("foo", SubString("",1,1), ind)
 | 
			
		||||
    @test_throws BoundsError rsearch("foo", SubString("",1,1), ind)
 | 
			
		||||
    @test_throws BoundsError searchindex("foo", SubString("",1,1), ind)
 | 
			
		||||
    @test_throws BoundsError rsearchindex("foo", SubString("",1,1), ind)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Note: the commented out tests will be enabled after fixes to make
 | 
			
		||||
# sure that search/rsearch/searchindex/rsearchindex are consistent
 | 
			
		||||
# no matter what type of AbstractString the second argument is
 | 
			
		||||
@test_throws BoundsError search("foo", Char[], 0)
 | 
			
		||||
@test_throws BoundsError search("foo", Char[], 5)
 | 
			
		||||
# @test_throws BoundsError rsearch("foo", Char[], 0)
 | 
			
		||||
@test_throws BoundsError rsearch("foo", Char[], 5)
 | 
			
		||||
 | 
			
		||||
# @test_throws BoundsError searchindex("foo", Char[], 0)
 | 
			
		||||
# @test_throws BoundsError searchindex("foo", Char[], 5)
 | 
			
		||||
# @test_throws BoundsError rsearchindex("foo", Char[], 0)
 | 
			
		||||
# @test_throws BoundsError rsearchindex("foo", Char[], 5)
 | 
			
		||||
 | 
			
		||||
# @test_throws ErrorException in("foobar","bar")
 | 
			
		||||
@test_throws BoundsError search(b"\x1\x2",0x1,0)
 | 
			
		||||
@test rsearchindex(b"foo",b"o",0) == 0
 | 
			
		||||
@test rsearchindex(SubString("",1,1),SubString("",1,1)) == 1
 | 
			
		||||
 | 
			
		||||
@test search(b"foo",'o') == 2
 | 
			
		||||
@test rsearch(b"foo",'o') == 3
 | 
			
		||||
@test search(b"foó",'ó') == 3
 | 
			
		||||
@test rsearch(b"foó",'ó') == 3
 | 
			
		||||
 | 
			
		||||
# ascii search
 | 
			
		||||
for str in [astr, GenericString(astr)]
 | 
			
		||||
    @test_throws BoundsError search(str, 'z', 0)
 | 
			
		||||
    @test_throws BoundsError search(str, '∀', 0)
 | 
			
		||||
    @test search(str, 'x') == 0
 | 
			
		||||
    @test search(str, '\0') == 0
 | 
			
		||||
    @test search(str, '\u80') == 0
 | 
			
		||||
    @test search(str, '∀') == 0
 | 
			
		||||
    @test search(str, 'H') == 1
 | 
			
		||||
    @test search(str, 'l') == 3
 | 
			
		||||
    @test search(str, 'l', 4) == 4
 | 
			
		||||
    @test search(str, 'l', 5) == 11
 | 
			
		||||
    @test search(str, 'l', 12) == 0
 | 
			
		||||
    @test search(str, ',') == 6
 | 
			
		||||
    @test search(str, ',', 7) == 0
 | 
			
		||||
    @test search(str, '\n') == 14
 | 
			
		||||
    @test search(str, '\n', 15) == 0
 | 
			
		||||
    @test_throws BoundsError search(str, 'ε', nextind(str,endof(str))+1)
 | 
			
		||||
    @test_throws BoundsError search(str, 'a', nextind(str,endof(str))+1)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# ascii rsearch
 | 
			
		||||
for str in [astr]
 | 
			
		||||
    @test rsearch(str, 'x') == 0
 | 
			
		||||
    @test rsearch(str, '\0') == 0
 | 
			
		||||
    @test rsearch(str, '\u80') == 0
 | 
			
		||||
    @test rsearch(str, '∀') == 0
 | 
			
		||||
    @test rsearch(str, 'H') == 1
 | 
			
		||||
    @test rsearch(str, 'H', 0) == 0
 | 
			
		||||
    @test rsearch(str, 'l') == 11
 | 
			
		||||
    @test rsearch(str, 'l', 5) == 4
 | 
			
		||||
    @test rsearch(str, 'l', 4) == 4
 | 
			
		||||
    @test rsearch(str, 'l', 3) == 3
 | 
			
		||||
    @test rsearch(str, 'l', 2) == 0
 | 
			
		||||
    @test rsearch(str, ',') == 6
 | 
			
		||||
    @test rsearch(str, ',', 5) == 0
 | 
			
		||||
    @test rsearch(str, '\n') == 14
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# utf-8 search
 | 
			
		||||
for str in (u8str, GenericString(u8str))
 | 
			
		||||
    @test_throws BoundsError search(str, 'z', 0)
 | 
			
		||||
    @test_throws BoundsError search(str, '∀', 0)
 | 
			
		||||
    @test search(str, 'z') == 0
 | 
			
		||||
    @test search(str, '\0') == 0
 | 
			
		||||
    @test search(str, '\u80') == 0
 | 
			
		||||
    @test search(str, '∄') == 0
 | 
			
		||||
    @test search(str, '∀') == 1
 | 
			
		||||
    @test_throws UnicodeError search(str, '∀', 2)
 | 
			
		||||
    @test search(str, '∀', 4) == 0
 | 
			
		||||
    @test search(str, '∃') == 13
 | 
			
		||||
    @test_throws UnicodeError search(str, '∃', 15)
 | 
			
		||||
    @test search(str, '∃', 16) == 0
 | 
			
		||||
    @test search(str, 'x') == 26
 | 
			
		||||
    @test search(str, 'x', 27) == 43
 | 
			
		||||
    @test search(str, 'x', 44) == 0
 | 
			
		||||
    @test search(str, 'δ') == 17
 | 
			
		||||
    @test_throws UnicodeError search(str, 'δ', 18)
 | 
			
		||||
    @test search(str, 'δ', nextind(str,17)) == 33
 | 
			
		||||
    @test search(str, 'δ', nextind(str,33)) == 0
 | 
			
		||||
    @test search(str, 'ε') == 5
 | 
			
		||||
    @test search(str, 'ε', nextind(str,5)) == 54
 | 
			
		||||
    @test search(str, 'ε', nextind(str,54)) == 0
 | 
			
		||||
    @test search(str, 'ε', nextind(str,endof(str))) == 0
 | 
			
		||||
    @test search(str, 'a', nextind(str,endof(str))) == 0
 | 
			
		||||
    @test_throws BoundsError search(str, 'ε', nextind(str,endof(str))+1)
 | 
			
		||||
    @test_throws BoundsError search(str, 'a', nextind(str,endof(str))+1)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# utf-8 rsearch
 | 
			
		||||
for str in [u8str]
 | 
			
		||||
    @test rsearch(str, 'z') == 0
 | 
			
		||||
    @test rsearch(str, '\0') == 0
 | 
			
		||||
    @test rsearch(str, '\u80') == 0
 | 
			
		||||
    @test rsearch(str, '∄') == 0
 | 
			
		||||
    @test rsearch(str, '∀') == 1
 | 
			
		||||
    @test rsearch(str, '∀', 0) == 0
 | 
			
		||||
    @test rsearch(str, '∃') == 13
 | 
			
		||||
    @test rsearch(str, '∃', 14) == 13
 | 
			
		||||
    @test rsearch(str, '∃', 13) == 13
 | 
			
		||||
    @test rsearch(str, '∃', 12) == 0
 | 
			
		||||
    @test rsearch(str, 'x') == 43
 | 
			
		||||
    @test rsearch(str, 'x', 42) == 26
 | 
			
		||||
    @test rsearch(str, 'x', 25) == 0
 | 
			
		||||
    @test rsearch(str, 'δ') == 33
 | 
			
		||||
    @test rsearch(str, 'δ', 32) == 17
 | 
			
		||||
    @test rsearch(str, 'δ', 16) == 0
 | 
			
		||||
    @test rsearch(str, 'ε') == 54
 | 
			
		||||
    @test rsearch(str, 'ε', 53) == 5
 | 
			
		||||
    @test rsearch(str, 'ε', 4) == 0
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# string search with a single-char string
 | 
			
		||||
@test search(astr, "x") == 0:-1
 | 
			
		||||
@test search(astr, "H") == 1:1
 | 
			
		||||
@test search(astr, "H", 2) == 0:-1
 | 
			
		||||
@test search(astr, "l") == 3:3
 | 
			
		||||
@test search(astr, "l", 4) == 4:4
 | 
			
		||||
@test search(astr, "l", 5) == 11:11
 | 
			
		||||
@test search(astr, "l", 12) == 0:-1
 | 
			
		||||
@test search(astr, "\n") == 14:14
 | 
			
		||||
@test search(astr, "\n", 15) == 0:-1
 | 
			
		||||
 | 
			
		||||
@test search(u8str, "z") == 0:-1
 | 
			
		||||
@test search(u8str, "∄") == 0:-1
 | 
			
		||||
@test search(u8str, "∀") == 1:1
 | 
			
		||||
@test search(u8str, "∀", 4) == 0:-1
 | 
			
		||||
@test search(u8str, "∃") == 13:13
 | 
			
		||||
@test search(u8str, "∃", 16) == 0:-1
 | 
			
		||||
@test search(u8str, "x") == 26:26
 | 
			
		||||
@test search(u8str, "x", 27) == 43:43
 | 
			
		||||
@test search(u8str, "x", 44) == 0:-1
 | 
			
		||||
@test search(u8str, "ε") == 5:5
 | 
			
		||||
@test search(u8str, "ε", 7) == 54:54
 | 
			
		||||
@test search(u8str, "ε", 56) == 0:-1
 | 
			
		||||
 | 
			
		||||
# string rsearch with a single-char string
 | 
			
		||||
@test rsearch(astr, "x") == 0:-1
 | 
			
		||||
@test rsearch(astr, "H") == 1:1
 | 
			
		||||
@test rsearch(astr, "H", 2) == 1:1
 | 
			
		||||
@test rsearch(astr, "H", 0) == 0:-1
 | 
			
		||||
@test rsearch(astr, "l") == 11:11
 | 
			
		||||
@test rsearch(astr, "l", 10) == 4:4
 | 
			
		||||
@test rsearch(astr, "l", 4) == 4:4
 | 
			
		||||
@test rsearch(astr, "l", 3) == 3:3
 | 
			
		||||
@test rsearch(astr, "l", 2) == 0:-1
 | 
			
		||||
@test rsearch(astr, "\n") == 14:14
 | 
			
		||||
@test rsearch(astr, "\n", 13) == 0:-1
 | 
			
		||||
 | 
			
		||||
@test rsearch(u8str, "z") == 0:-1
 | 
			
		||||
@test rsearch(u8str, "∄") == 0:-1
 | 
			
		||||
@test rsearch(u8str, "∀") == 1:1
 | 
			
		||||
@test rsearch(u8str, "∀", 0) == 0:-1
 | 
			
		||||
#TODO: setting the limit in the middle of a wide char
 | 
			
		||||
#      makes search fail but rsearch succeed.
 | 
			
		||||
#      Should rsearch fail as well?
 | 
			
		||||
#@test rsearch(u8str, "∀", 2) == 0:-1 # gives 1:3
 | 
			
		||||
@test rsearch(u8str, "∃") == 13:13
 | 
			
		||||
@test rsearch(u8str, "∃", 12) == 0:-1
 | 
			
		||||
@test rsearch(u8str, "x") == 43:43
 | 
			
		||||
@test rsearch(u8str, "x", 42) == 26:26
 | 
			
		||||
@test rsearch(u8str, "x", 25) == 0:-1
 | 
			
		||||
@test rsearch(u8str, "ε") == 54:54
 | 
			
		||||
@test rsearch(u8str, "ε", 53) == 5:5
 | 
			
		||||
@test rsearch(u8str, "ε", 4) == 0:-1
 | 
			
		||||
 | 
			
		||||
# string search with a single-char regex
 | 
			
		||||
@test search(astr, r"x") == 0:-1
 | 
			
		||||
@test search(astr, r"H") == 1:1
 | 
			
		||||
@test search(astr, r"H", 2) == 0:-1
 | 
			
		||||
@test search(astr, r"l") == 3:3
 | 
			
		||||
@test search(astr, r"l", 4) == 4:4
 | 
			
		||||
@test search(astr, r"l", 5) == 11:11
 | 
			
		||||
@test search(astr, r"l", 12) == 0:-1
 | 
			
		||||
@test search(astr, r"\n") == 14:14
 | 
			
		||||
@test search(astr, r"\n", 15) == 0:-1
 | 
			
		||||
@test search(u8str, r"z") == 0:-1
 | 
			
		||||
@test search(u8str, r"∄") == 0:-1
 | 
			
		||||
@test search(u8str, r"∀") == 1:1
 | 
			
		||||
@test search(u8str, r"∀", 4) == 0:-1
 | 
			
		||||
@test search(u8str, r"∀") == search(u8str, r"\u2200")
 | 
			
		||||
@test search(u8str, r"∀", 4) == search(u8str, r"\u2200", 4)
 | 
			
		||||
@test search(u8str, r"∃") == 13:13
 | 
			
		||||
@test search(u8str, r"∃", 16) == 0:-1
 | 
			
		||||
@test search(u8str, r"x") == 26:26
 | 
			
		||||
@test search(u8str, r"x", 27) == 43:43
 | 
			
		||||
@test search(u8str, r"x", 44) == 0:-1
 | 
			
		||||
@test search(u8str, r"ε") == 5:5
 | 
			
		||||
@test search(u8str, r"ε", 7) == 54:54
 | 
			
		||||
@test search(u8str, r"ε", 56) == 0:-1
 | 
			
		||||
for i = 1:endof(astr)
 | 
			
		||||
    @test search(astr, r"."s, i) == i:i
 | 
			
		||||
end
 | 
			
		||||
for i = 1:endof(u8str)
 | 
			
		||||
    if isvalid(u8str,i)
 | 
			
		||||
        @test search(u8str, r"."s, i) == i:i
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# string search with a zero-char string
 | 
			
		||||
for i = 1:endof(astr)
 | 
			
		||||
    @test search(astr, "", i) == i:i-1
 | 
			
		||||
end
 | 
			
		||||
for i = 1:endof(u8str)
 | 
			
		||||
    @test search(u8str, "", i) == i:i-1
 | 
			
		||||
end
 | 
			
		||||
@test search("", "") == 1:0
 | 
			
		||||
 | 
			
		||||
# string rsearch with a zero-char string
 | 
			
		||||
for i = 1:endof(astr)
 | 
			
		||||
    @test rsearch(astr, "", i) == i:i-1
 | 
			
		||||
end
 | 
			
		||||
for i = 1:endof(u8str)
 | 
			
		||||
    @test rsearch(u8str, "", i) == i:i-1
 | 
			
		||||
end
 | 
			
		||||
@test rsearch("", "") == 1:0
 | 
			
		||||
 | 
			
		||||
# string search with a zero-char regex
 | 
			
		||||
for i = 1:endof(astr)
 | 
			
		||||
    @test search(astr, r"", i) == i:i-1
 | 
			
		||||
end
 | 
			
		||||
for i = 1:endof(u8str)
 | 
			
		||||
    # TODO: should regex search fast-forward invalid indices?
 | 
			
		||||
    if isvalid(u8str,i)
 | 
			
		||||
        @test search(u8str, r""s, i) == i:i-1
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# string search with a two-char string literal
 | 
			
		||||
@test search("foo,bar,baz", "xx") == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", "fo") == 1:2
 | 
			
		||||
@test search("foo,bar,baz", "fo", 3) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", "oo") == 2:3
 | 
			
		||||
@test search("foo,bar,baz", "oo", 4) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", "o,") == 3:4
 | 
			
		||||
@test search("foo,bar,baz", "o,", 5) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", ",b") == 4:5
 | 
			
		||||
@test search("foo,bar,baz", ",b", 6) == 8:9
 | 
			
		||||
@test search("foo,bar,baz", ",b", 10) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", "az") == 10:11
 | 
			
		||||
@test search("foo,bar,baz", "az", 12) == 0:-1
 | 
			
		||||
 | 
			
		||||
# issue #9365
 | 
			
		||||
# string search with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test search("ééé", "éé") == 1:3
 | 
			
		||||
@test search("ééé", "éé", 1) == 1:3
 | 
			
		||||
# string search with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test search("€€€", "€€") == 1:4
 | 
			
		||||
@test search("€€€", "€€", 1) == 1:4
 | 
			
		||||
# string search with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test search("\U1f596\U1f596\U1f596", "\U1f596\U1f596") == 1:5
 | 
			
		||||
@test search("\U1f596\U1f596\U1f596", "\U1f596\U1f596", 1) == 1:5
 | 
			
		||||
 | 
			
		||||
# string search with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test search("éé", "éé") == 1:3
 | 
			
		||||
@test search("éé", "éé", 1) == 1:3
 | 
			
		||||
# string search with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test search("€€", "€€") == 1:4
 | 
			
		||||
@test search("€€", "€€", 1) == 1:4
 | 
			
		||||
# string search with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test search("\U1f596\U1f596", "\U1f596\U1f596") == 1:5
 | 
			
		||||
@test search("\U1f596\U1f596", "\U1f596\U1f596", 1) == 1:5
 | 
			
		||||
 | 
			
		||||
# string rsearch with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test rsearch("ééé", "éé") == 3:5
 | 
			
		||||
@test rsearch("ééé", "éé", endof("ééé")) == 3:5
 | 
			
		||||
# string rsearch with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test rsearch("€€€", "€€") == 4:7
 | 
			
		||||
@test rsearch("€€€", "€€", endof("€€€")) == 4:7
 | 
			
		||||
# string rsearch with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test rsearch("\U1f596\U1f596\U1f596", "\U1f596\U1f596") == 5:9
 | 
			
		||||
@test rsearch("\U1f596\U1f596\U1f596", "\U1f596\U1f596", endof("\U1f596\U1f596\U1f596")) == 5:9
 | 
			
		||||
 | 
			
		||||
# string rsearch with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test rsearch("éé", "éé") == 1:3        # should really be 1:4!
 | 
			
		||||
@test rsearch("éé", "éé", endof("ééé")) == 1:3
 | 
			
		||||
# string search with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test rsearch("€€", "€€") == 1:4        # should really be 1:6!
 | 
			
		||||
@test rsearch("€€", "€€", endof("€€€")) == 1:4
 | 
			
		||||
# string search with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test rsearch("\U1f596\U1f596", "\U1f596\U1f596") == 1:5        # should really be 1:8!
 | 
			
		||||
@test rsearch("\U1f596\U1f596", "\U1f596\U1f596", endof("\U1f596\U1f596\U1f596")) == 1:5
 | 
			
		||||
 | 
			
		||||
# string rsearch with a two-char string literal
 | 
			
		||||
@test rsearch("foo,bar,baz", "xx") == 0:-1
 | 
			
		||||
@test rsearch("foo,bar,baz", "fo") == 1:2
 | 
			
		||||
@test rsearch("foo,bar,baz", "fo", 1) == 0:-1
 | 
			
		||||
@test rsearch("foo,bar,baz", "oo") == 2:3
 | 
			
		||||
@test rsearch("foo,bar,baz", "oo", 2) == 0:-1
 | 
			
		||||
@test rsearch("foo,bar,baz", "o,") == 3:4
 | 
			
		||||
@test rsearch("foo,bar,baz", "o,", 1) == 0:-1
 | 
			
		||||
@test rsearch("foo,bar,baz", ",b") == 8:9
 | 
			
		||||
@test rsearch("foo,bar,baz", ",b", 6) == 4:5
 | 
			
		||||
@test rsearch("foo,bar,baz", ",b", 3) == 0:-1
 | 
			
		||||
@test rsearch("foo,bar,baz", "az") == 10:11
 | 
			
		||||
@test rsearch("foo,bar,baz", "az", 10) == 0:-1
 | 
			
		||||
 | 
			
		||||
# array rsearch
 | 
			
		||||
@test rsearch(UInt8[1,2,3],UInt8[2,3],3) == 2:3
 | 
			
		||||
@test rsearch(UInt8[1,2,3],UInt8[2,3],1) == 0:-1
 | 
			
		||||
 | 
			
		||||
# string search with a two-char regex
 | 
			
		||||
@test search("foo,bar,baz", r"xx") == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", r"fo") == 1:2
 | 
			
		||||
@test search("foo,bar,baz", r"fo", 3) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", r"oo") == 2:3
 | 
			
		||||
@test search("foo,bar,baz", r"oo", 4) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", r"o,") == 3:4
 | 
			
		||||
@test search("foo,bar,baz", r"o,", 5) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", r",b") == 4:5
 | 
			
		||||
@test search("foo,bar,baz", r",b", 6) == 8:9
 | 
			
		||||
@test search("foo,bar,baz", r",b", 10) == 0:-1
 | 
			
		||||
@test search("foo,bar,baz", r"az") == 10:11
 | 
			
		||||
@test search("foo,bar,baz", r"az", 12) == 0:-1
 | 
			
		||||
 | 
			
		||||
@test searchindex("foo", 'o') == 2
 | 
			
		||||
@test searchindex("foo", 'o', 3) == 3
 | 
			
		||||
 | 
			
		||||
# string searchindex with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test searchindex("ééé", "éé") == 1
 | 
			
		||||
@test searchindex("ééé", "éé", 1) == 1
 | 
			
		||||
# string searchindex with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test searchindex("€€€", "€€") == 1
 | 
			
		||||
@test searchindex("€€€", "€€", 1) == 1
 | 
			
		||||
# string searchindex with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test searchindex("\U1f596\U1f596\U1f596", "\U1f596\U1f596") == 1
 | 
			
		||||
@test searchindex("\U1f596\U1f596\U1f596", "\U1f596\U1f596", 1) == 1
 | 
			
		||||
 | 
			
		||||
# string searchindex with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test searchindex("éé", "éé") == 1
 | 
			
		||||
@test searchindex("éé", "éé", 1) == 1
 | 
			
		||||
# string searchindex with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test searchindex("€€", "€€") == 1
 | 
			
		||||
@test searchindex("€€", "€€", 1) == 1
 | 
			
		||||
# string searchindex with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test searchindex("\U1f596\U1f596", "\U1f596\U1f596") == 1
 | 
			
		||||
@test searchindex("\U1f596\U1f596", "\U1f596\U1f596", 1) == 1
 | 
			
		||||
 | 
			
		||||
# string rsearchindex with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test rsearchindex("ééé", "éé") == 3
 | 
			
		||||
@test rsearchindex("ééé", "éé", endof("ééé")) == 3
 | 
			
		||||
# string rsearchindex with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test rsearchindex("€€€", "€€") == 4
 | 
			
		||||
@test rsearchindex("€€€", "€€", endof("€€€")) == 4
 | 
			
		||||
# string rsearchindex with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test rsearchindex("\U1f596\U1f596\U1f596", "\U1f596\U1f596") == 5
 | 
			
		||||
@test rsearchindex("\U1f596\U1f596\U1f596", "\U1f596\U1f596", endof("\U1f596\U1f596\U1f596")) == 5
 | 
			
		||||
 | 
			
		||||
# string rsearchindex with a two-char UTF-8 (2 byte) string literal
 | 
			
		||||
@test rsearchindex("éé", "éé") == 1
 | 
			
		||||
@test rsearchindex("éé", "éé", endof("ééé")) == 1
 | 
			
		||||
# string searchindex with a two-char UTF-8 (3 byte) string literal
 | 
			
		||||
@test rsearchindex("€€", "€€") == 1
 | 
			
		||||
@test rsearchindex("€€", "€€", endof("€€€")) == 1
 | 
			
		||||
# string searchindex with a two-char UTF-8 (4 byte) string literal
 | 
			
		||||
@test rsearchindex("\U1f596\U1f596", "\U1f596\U1f596") == 1
 | 
			
		||||
@test rsearchindex("\U1f596\U1f596", "\U1f596\U1f596", endof("\U1f596\U1f596\U1f596")) == 1
 | 
			
		||||
 | 
			
		||||
@test_throws ErrorException "ab" ∈ "abc"
 | 
			
		||||
							
								
								
									
										212
									
								
								julia-0.6.2/share/julia/test/strings/types.jl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										212
									
								
								julia-0.6.2/share/julia/test/strings/types.jl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,212 @@
 | 
			
		||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
 | 
			
		||||
 | 
			
		||||
## SubString, RevString and Cstring tests ##
 | 
			
		||||
 | 
			
		||||
## SubString tests ##
 | 
			
		||||
u8str = "∀ ε > 0, ∃ δ > 0: |x-y| < δ ⇒ |f(x)-f(y)| < ε"
 | 
			
		||||
u8str2 = u8str^2
 | 
			
		||||
len_u8str = length(u8str)
 | 
			
		||||
slen_u8str = length(u8str)
 | 
			
		||||
len_u8str2 = length(u8str2)
 | 
			
		||||
slen_u8str2 = length(u8str2)
 | 
			
		||||
 | 
			
		||||
@test len_u8str2 == 2 * len_u8str
 | 
			
		||||
@test slen_u8str2 == 2 * slen_u8str
 | 
			
		||||
 | 
			
		||||
u8str2plain = String(u8str2)
 | 
			
		||||
 | 
			
		||||
for i1 = 1:length(u8str2)
 | 
			
		||||
    if !isvalid(u8str2, i1); continue; end
 | 
			
		||||
    for i2 = i1:length(u8str2)
 | 
			
		||||
        if !isvalid(u8str2, i2); continue; end
 | 
			
		||||
        @test length(u8str2[i1:i2]) == length(u8str2plain[i1:i2])
 | 
			
		||||
        @test length(u8str2[i1:i2]) == length(u8str2plain[i1:i2])
 | 
			
		||||
        @test u8str2[i1:i2] == u8str2plain[i1:i2]
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
str="tempus fugit"              #length(str)==12
 | 
			
		||||
ss=SubString(str,1,length(str)) #match source string
 | 
			
		||||
@test length(ss)==length(str)
 | 
			
		||||
 | 
			
		||||
ss=SubString(str,1,0)    #empty SubString
 | 
			
		||||
@test length(ss)==0
 | 
			
		||||
 | 
			
		||||
ss=SubString(str,14,20)  #start indexed beyond source string length
 | 
			
		||||
@test length(ss)==0
 | 
			
		||||
 | 
			
		||||
ss=SubString(str,10,16)  #end indexed beyond source string length
 | 
			
		||||
@test length(ss)==3
 | 
			
		||||
 | 
			
		||||
str2=""
 | 
			
		||||
ss=SubString(str2,1,4)  #empty source string
 | 
			
		||||
@test length(ss)==0
 | 
			
		||||
 | 
			
		||||
ss=SubString(str2,1,1)  #empty source string, identical start and end index
 | 
			
		||||
@test length(ss)==0
 | 
			
		||||
 | 
			
		||||
@test SubString("foobar",big(1),big(3)) == "foo"
 | 
			
		||||
 | 
			
		||||
str = "aa\u2200\u2222bb"
 | 
			
		||||
u = SubString(str, 3, 6)
 | 
			
		||||
@test length(u)==2
 | 
			
		||||
b = IOBuffer()
 | 
			
		||||
write(b, u)
 | 
			
		||||
@test String(take!(b)) == "\u2200\u2222"
 | 
			
		||||
 | 
			
		||||
@test_throws ArgumentError SubString(str, 4, 5)
 | 
			
		||||
@test_throws BoundsError next(u, 0)
 | 
			
		||||
@test_throws BoundsError next(u, 7)
 | 
			
		||||
@test_throws BoundsError getindex(u, 0)
 | 
			
		||||
@test_throws BoundsError getindex(u, 7)
 | 
			
		||||
@test_throws BoundsError getindex(u, 0:1)
 | 
			
		||||
@test_throws BoundsError getindex(u, 7:7)
 | 
			
		||||
@test reverseind(u, 1) == 4
 | 
			
		||||
@test typeof(Base.cconvert(Ptr{Int8},u)) == SubString{String}
 | 
			
		||||
@test Base.cconvert(Ptr{Int8},u) == u
 | 
			
		||||
 | 
			
		||||
str = "føøbar"
 | 
			
		||||
u = SubString(str, 4, 3)
 | 
			
		||||
@test length(u)==0
 | 
			
		||||
b = IOBuffer()
 | 
			
		||||
write(b, u)
 | 
			
		||||
@test String(take!(b)) == ""
 | 
			
		||||
 | 
			
		||||
str = "føøbar"
 | 
			
		||||
u = SubString(str, 10, 10)
 | 
			
		||||
@test length(u)==0
 | 
			
		||||
b = IOBuffer()
 | 
			
		||||
write(b, u)
 | 
			
		||||
@test String(take!(b)) == ""
 | 
			
		||||
 | 
			
		||||
# search and SubString (issue #5679)
 | 
			
		||||
str = "Hello, world!"
 | 
			
		||||
u = SubString(str, 1, 5)
 | 
			
		||||
@test rsearch(u, "World") == 0:-1
 | 
			
		||||
@test rsearch(u, 'z') == 0
 | 
			
		||||
@test rsearch(u, "ll") == 3:4
 | 
			
		||||
 | 
			
		||||
# sizeof
 | 
			
		||||
@test sizeof(SubString("abc\u2222def",4,4)) == 3
 | 
			
		||||
 | 
			
		||||
# issue #3710
 | 
			
		||||
@test prevind(SubString("{var}",2,4),4) == 3
 | 
			
		||||
 | 
			
		||||
# issue #4183
 | 
			
		||||
@test split(SubString("x", 2, 0), "y") == AbstractString[""]
 | 
			
		||||
 | 
			
		||||
# issue #6772
 | 
			
		||||
@test float(SubString("10",1,1)) === 1.0
 | 
			
		||||
@test float(SubString("1 0",1,1)) === 1.0
 | 
			
		||||
@test parse(Float32,SubString("10",1,1)) === 1.0f0
 | 
			
		||||
 | 
			
		||||
# issue #5870
 | 
			
		||||
@test !ismatch(Regex("aa"), SubString("",1,0))
 | 
			
		||||
@test ismatch(Regex(""), SubString("",1,0))
 | 
			
		||||
 | 
			
		||||
# isvalid(), chr2ind() and ind2chr() for SubString{DirectIndexString}
 | 
			
		||||
let s="lorem ipsum",
 | 
			
		||||
    sdict=Dict(SubString(s,1,11)=>s,
 | 
			
		||||
               SubString(s,1,6)=>"lorem ",
 | 
			
		||||
               SubString(s,1,0)=>"",
 | 
			
		||||
               SubString(s,2,4)=>"ore",
 | 
			
		||||
               SubString(s,2,16)=>"orem ipsum",
 | 
			
		||||
               SubString(s,12,14)=>""
 | 
			
		||||
               )
 | 
			
		||||
    for (ss,s) in sdict
 | 
			
		||||
        for i in -1:12
 | 
			
		||||
            @test isvalid(ss,i)==isvalid(s,i)
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    for (ss,s) in sdict
 | 
			
		||||
        for i in 1:length(ss)
 | 
			
		||||
            @test ind2chr(ss,i)==ind2chr(s,i)
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    for (ss,s) in sdict
 | 
			
		||||
        for i in 1:length(ss)
 | 
			
		||||
            @test chr2ind(ss,i)==chr2ind(s,i)
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end #let
 | 
			
		||||
 | 
			
		||||
#for isvalid(SubString{String})
 | 
			
		||||
let s = "Σx + βz - 2"
 | 
			
		||||
  for i in -1:length(s)+2
 | 
			
		||||
      ss=SubString(s,1,i)
 | 
			
		||||
      @test isvalid(ss,i)==isvalid(s,i)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
ss=SubString("hello",1,5)
 | 
			
		||||
@test_throws BoundsError ind2chr(ss, -1)
 | 
			
		||||
@test_throws BoundsError chr2ind(ss, -1)
 | 
			
		||||
@test_throws BoundsError chr2ind(ss, 10)
 | 
			
		||||
@test_throws BoundsError ind2chr(ss, 10)
 | 
			
		||||
 | 
			
		||||
# length(SubString{String}) performance specialization
 | 
			
		||||
let s = "|η(α)-ϕ(κ)| < ε"
 | 
			
		||||
    @test length(SubString(s,1,0))==length(s[1:0])
 | 
			
		||||
    @test length(SubString(s,4,4))==length(s[4:4])
 | 
			
		||||
    @test length(SubString(s,1,7))==length(s[1:7])
 | 
			
		||||
    @test length(SubString(s,4,11))==length(s[4:11])
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
## Reverse strings ##
 | 
			
		||||
 | 
			
		||||
rs = RevString("foobar")
 | 
			
		||||
@test length(rs) == 6
 | 
			
		||||
@test sizeof(rs) == 6
 | 
			
		||||
@test isascii(rs)
 | 
			
		||||
 | 
			
		||||
# issue #4586
 | 
			
		||||
@test rsplit(RevString("ailuj"),'l') == ["ju","ia"]
 | 
			
		||||
@test parse(Float64,RevString("64")) === 46.0
 | 
			
		||||
 | 
			
		||||
# reverseind
 | 
			
		||||
for T in (String, GenericString)
 | 
			
		||||
    for prefix in ("", "abcd", "\U0001d6a4\U0001d4c1", "\U0001d6a4\U0001d4c1c", " \U0001d6a4\U0001d4c1")
 | 
			
		||||
        for suffix in ("", "abcde", "\U0001d4c1β\U0001d6a4", "\U0001d4c1β\U0001d6a4c", " \U0001d4c1β\U0001d6a4")
 | 
			
		||||
            for c in ('X', 'δ', '\U0001d6a5')
 | 
			
		||||
                s = convert(T, string(prefix, c, suffix))
 | 
			
		||||
                r = reverse(s)
 | 
			
		||||
                ri = search(r, c)
 | 
			
		||||
                @test r == RevString(s)
 | 
			
		||||
                @test c == s[reverseind(s, ri)] == r[ri]
 | 
			
		||||
                s = RevString(s)
 | 
			
		||||
                r = reverse(s)
 | 
			
		||||
                ri = search(r, c)
 | 
			
		||||
                @test c == s[reverseind(s, ri)] == r[ri]
 | 
			
		||||
                s = convert(T, string(prefix, prefix, c, suffix, suffix))
 | 
			
		||||
                pre = convert(T, prefix)
 | 
			
		||||
                sb = SubString(s, nextind(pre, endof(pre)), endof(convert(T, string(prefix, prefix, c, suffix))))
 | 
			
		||||
                r = reverse(sb)
 | 
			
		||||
                ri = search(r, c)
 | 
			
		||||
                @test c == sb[reverseind(sb, ri)] == r[ri]
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
## Cstring tests ##
 | 
			
		||||
 | 
			
		||||
# issue #13974: comparison against pointers
 | 
			
		||||
 | 
			
		||||
str = String("foobar")
 | 
			
		||||
ptr = pointer(str)
 | 
			
		||||
cstring = Cstring(ptr)
 | 
			
		||||
@test ptr == cstring
 | 
			
		||||
@test cstring == ptr
 | 
			
		||||
 | 
			
		||||
# convenient NULL string creation from Ptr{Void}
 | 
			
		||||
nullstr = Cstring(C_NULL)
 | 
			
		||||
 | 
			
		||||
# Comparisons against NULL strings
 | 
			
		||||
@test ptr != nullstr
 | 
			
		||||
@test nullstr != ptr
 | 
			
		||||
 | 
			
		||||
# Short-hand comparison against C_NULL
 | 
			
		||||
@test nullstr == C_NULL
 | 
			
		||||
@test C_NULL == nullstr
 | 
			
		||||
@test cstring != C_NULL
 | 
			
		||||
@test C_NULL != cstring
 | 
			
		||||
							
								
								
									
										237
									
								
								julia-0.6.2/share/julia/test/strings/util.jl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										237
									
								
								julia-0.6.2/share/julia/test/strings/util.jl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,237 @@
 | 
			
		||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
 | 
			
		||||
 | 
			
		||||
# padding (lpad and rpad)
 | 
			
		||||
@test lpad("foo", 3) == "foo"
 | 
			
		||||
@test rpad("foo", 3) == "foo"
 | 
			
		||||
@test lpad("foo", 5) == "  foo"
 | 
			
		||||
@test rpad("foo", 5) == "foo  "
 | 
			
		||||
@test lpad("foo", 5, "  ") == "  foo"
 | 
			
		||||
@test rpad("foo", 5, "  ") == "foo  "
 | 
			
		||||
@test lpad("foo", 6, "  ") == "   foo"
 | 
			
		||||
@test rpad("foo", 6, "  ") == "foo   "
 | 
			
		||||
 | 
			
		||||
# string manipulation
 | 
			
		||||
@test strip("") == ""
 | 
			
		||||
@test strip(" ") == ""
 | 
			
		||||
@test strip("  ") == ""
 | 
			
		||||
@test strip("   ") == ""
 | 
			
		||||
@test strip("\t  hi   \n") == "hi"
 | 
			
		||||
@test strip("foobarfoo", ['f','o']) == "bar"
 | 
			
		||||
@test strip("foobarfoo", ('f','o')) == "bar"
 | 
			
		||||
 | 
			
		||||
for s in ("", " ", " abc", "abc ", "  abc  "), f in (lstrip, rstrip, strip)
 | 
			
		||||
    fs = f(s)
 | 
			
		||||
    for T = (String, GenericString)
 | 
			
		||||
        t = convert(T,s)
 | 
			
		||||
        ft = f(t)
 | 
			
		||||
        @test s == t
 | 
			
		||||
        @test fs == ft
 | 
			
		||||
        @test typeof(ft) == typeof(t[1:end])
 | 
			
		||||
 | 
			
		||||
        b = convert(SubString{T}, t)
 | 
			
		||||
        fb = f(b)
 | 
			
		||||
        @test s == b
 | 
			
		||||
        @test fs == fb
 | 
			
		||||
        @test typeof(fb) == SubString{T}
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# split
 | 
			
		||||
@test isequal(split("foo,bar,baz", 'x'), ["foo,bar,baz"])
 | 
			
		||||
@test isequal(split("foo,bar,baz", ','), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(split("foo,bar,baz", ","), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(split("foo,bar,baz", r","), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(split("foo,bar,baz", ','; limit=0), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(split("foo,bar,baz", ','; limit=1), ["foo,bar,baz"])
 | 
			
		||||
@test isequal(split("foo,bar,baz", ','; limit=2), ["foo","bar,baz"])
 | 
			
		||||
@test isequal(split("foo,bar,baz", ','; limit=3), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(split("foo,bar", "o,b"), ["fo","ar"])
 | 
			
		||||
 | 
			
		||||
@test isequal(split("", ','), [""])
 | 
			
		||||
@test isequal(split(",", ','), ["",""])
 | 
			
		||||
@test isequal(split(",,", ','), ["","",""])
 | 
			
		||||
@test isequal(split("", ','  ; keep=false), [])
 | 
			
		||||
@test isequal(split(",", ',' ; keep=false), [])
 | 
			
		||||
@test isequal(split(",,", ','; keep=false), [])
 | 
			
		||||
 | 
			
		||||
@test isequal(split("a b c"), ["a","b","c"])
 | 
			
		||||
@test isequal(split("a  b \t c\n"), ["a","b","c"])
 | 
			
		||||
 | 
			
		||||
@test isequal(rsplit("foo,bar,baz", 'x'), ["foo,bar,baz"])
 | 
			
		||||
@test isequal(rsplit("foo,bar,baz", ','), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(rsplit("foo,bar,baz", ","), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(rsplit("foo,bar,baz", ','; limit=0), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(rsplit("foo,bar,baz", ','; limit=1), ["foo,bar,baz"])
 | 
			
		||||
@test isequal(rsplit("foo,bar,baz", ','; limit=2), ["foo,bar","baz"])
 | 
			
		||||
@test isequal(rsplit("foo,bar,baz", ','; limit=3), ["foo","bar","baz"])
 | 
			
		||||
@test isequal(rsplit("foo,bar", "o,b"), ["fo","ar"])
 | 
			
		||||
 | 
			
		||||
@test isequal(rsplit("", ','), [""])
 | 
			
		||||
@test isequal(rsplit(",", ','), ["",""])
 | 
			
		||||
@test isequal(rsplit(",,", ','), ["","",""])
 | 
			
		||||
@test isequal(rsplit(",,", ','; limit=2), [",",""])
 | 
			
		||||
@test isequal(rsplit("", ','  ; keep=false), [])
 | 
			
		||||
@test isequal(rsplit(",", ',' ; keep=false), [])
 | 
			
		||||
@test isequal(rsplit(",,", ','; keep=false), [])
 | 
			
		||||
 | 
			
		||||
#@test isequal(rsplit("a b c"), ["a","b","c"])
 | 
			
		||||
#@test isequal(rsplit("a  b \t c\n"), ["a","b","c"])
 | 
			
		||||
 | 
			
		||||
let str = "a.:.ba..:..cba.:.:.dcba.:."
 | 
			
		||||
@test isequal(split(str, ".:."), ["a","ba.",".cba",":.dcba",""])
 | 
			
		||||
@test isequal(split(str, ".:."; keep=false), ["a","ba.",".cba",":.dcba"])
 | 
			
		||||
@test isequal(split(str, ".:."), ["a","ba.",".cba",":.dcba",""])
 | 
			
		||||
@test isequal(split(str, r"\.(:\.)+"), ["a","ba.",".cba","dcba",""])
 | 
			
		||||
@test isequal(split(str, r"\.(:\.)+"; keep=false), ["a","ba.",".cba","dcba"])
 | 
			
		||||
@test isequal(split(str, r"\.+:\.+"), ["a","ba","cba",":.dcba",""])
 | 
			
		||||
@test isequal(split(str, r"\.+:\.+"; keep=false), ["a","ba","cba",":.dcba"])
 | 
			
		||||
 | 
			
		||||
@test isequal(rsplit(str, ".:."), ["a","ba.",".cba.:","dcba",""])
 | 
			
		||||
@test isequal(rsplit(str, ".:."; keep=false), ["a","ba.",".cba.:","dcba"])
 | 
			
		||||
@test isequal(rsplit(str, ".:."; limit=2), ["a.:.ba..:..cba.:.:.dcba", ""])
 | 
			
		||||
@test isequal(rsplit(str, ".:."; limit=3), ["a.:.ba..:..cba.:", "dcba", ""])
 | 
			
		||||
@test isequal(rsplit(str, ".:."; limit=4), ["a.:.ba.", ".cba.:", "dcba", ""])
 | 
			
		||||
@test isequal(rsplit(str, ".:."; limit=5), ["a", "ba.", ".cba.:", "dcba", ""])
 | 
			
		||||
@test isequal(rsplit(str, ".:."; limit=6), ["a", "ba.", ".cba.:", "dcba", ""])
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# zero-width splits
 | 
			
		||||
@test isequal(rsplit("", ""), [""])
 | 
			
		||||
 | 
			
		||||
@test isequal(split("", ""), [""])
 | 
			
		||||
@test isequal(split("", r""), [""])
 | 
			
		||||
@test isequal(split("abc", ""), ["a","b","c"])
 | 
			
		||||
@test isequal(split("abc", r""), ["a","b","c"])
 | 
			
		||||
@test isequal(split("abcd", r"b?"), ["a","c","d"])
 | 
			
		||||
@test isequal(split("abcd", r"b*"), ["a","c","d"])
 | 
			
		||||
@test isequal(split("abcd", r"b+"), ["a","cd"])
 | 
			
		||||
@test isequal(split("abcd", r"b?c?"), ["a","d"])
 | 
			
		||||
@test isequal(split("abcd", r"[bc]?"), ["a","","d"])
 | 
			
		||||
@test isequal(split("abcd", r"a*"), ["","b","c","d"])
 | 
			
		||||
@test isequal(split("abcd", r"a+"), ["","bcd"])
 | 
			
		||||
@test isequal(split("abcd", r"d*"), ["a","b","c",""])
 | 
			
		||||
@test isequal(split("abcd", r"d+"), ["abc",""])
 | 
			
		||||
@test isequal(split("abcd", r"[ad]?"), ["","b","c",""])
 | 
			
		||||
 | 
			
		||||
# replace
 | 
			
		||||
@test replace("\u2202", '*', '\0') == "\u2202"
 | 
			
		||||
 | 
			
		||||
@test replace("foobar", 'o', '0') == "f00bar"
 | 
			
		||||
@test replace("foobar", 'o', '0', 1) == "f0obar"
 | 
			
		||||
@test replace("foobar", 'o', "") == "fbar"
 | 
			
		||||
@test replace("foobar", 'o', "", 1) == "fobar"
 | 
			
		||||
@test replace("foobar", 'f', 'F') == "Foobar"
 | 
			
		||||
@test replace("foobar", 'r', 'R') == "foobaR"
 | 
			
		||||
 | 
			
		||||
@test replace("foofoofoo", "foo", "bar") == "barbarbar"
 | 
			
		||||
@test replace("foobarfoo", "foo", "baz") == "bazbarbaz"
 | 
			
		||||
@test replace("barfoofoo", "foo", "baz") == "barbazbaz"
 | 
			
		||||
 | 
			
		||||
@test replace("", "", "") == ""
 | 
			
		||||
@test replace("", "", "x") == "x"
 | 
			
		||||
@test replace("", "x", "y") == ""
 | 
			
		||||
 | 
			
		||||
@test replace("abcd", "", "^") == "^a^b^c^d^"
 | 
			
		||||
@test replace("abcd", "b", "^") == "a^cd"
 | 
			
		||||
@test replace("abcd", r"b?", "^") == "^a^c^d^"
 | 
			
		||||
@test replace("abcd", r"b+", "^") == "a^cd"
 | 
			
		||||
@test replace("abcd", r"b?c?", "^") == "^a^d^"
 | 
			
		||||
@test replace("abcd", r"[bc]?", "^") == "^a^^d^"
 | 
			
		||||
 | 
			
		||||
@test replace("foobarfoo", r"(fo|ba)", "xx") == "xxoxxrxxo"
 | 
			
		||||
@test replace("foobarfoo", r"(foo|ba)", "bar") == "barbarrbar"
 | 
			
		||||
 | 
			
		||||
@test replace("foobar", 'o', 'ø') == "føøbar"
 | 
			
		||||
@test replace("foobar", 'o', 'ø', 1) == "føobar"
 | 
			
		||||
@test replace("føøbar", 'ø', 'o') == "foobar"
 | 
			
		||||
@test replace("føøbar", 'ø', 'o', 1) == "foøbar"
 | 
			
		||||
@test replace("føøbar", 'ø', 'ö') == "fööbar"
 | 
			
		||||
@test replace("føøbar", 'ø', 'ö', 1) == "föøbar"
 | 
			
		||||
@test replace("føøbar", 'ø', "") == "fbar"
 | 
			
		||||
@test replace("føøbar", 'ø', "", 1) == "føbar"
 | 
			
		||||
@test replace("føøbar", 'f', 'F') == "Føøbar"
 | 
			
		||||
@test replace("ḟøøbar", 'ḟ', 'F') == "Føøbar"
 | 
			
		||||
@test replace("føøbar", 'f', 'Ḟ') == "Ḟøøbar"
 | 
			
		||||
@test replace("ḟøøbar", 'ḟ', 'Ḟ') == "Ḟøøbar"
 | 
			
		||||
@test replace("føøbar", 'r', 'R') == "føøbaR"
 | 
			
		||||
@test replace("føøbaṙ", 'ṙ', 'R') == "føøbaR"
 | 
			
		||||
@test replace("føøbar", 'r', 'Ṙ') == "føøbaṘ"
 | 
			
		||||
@test replace("føøbaṙ", 'ṙ', 'Ṙ') == "føøbaṘ"
 | 
			
		||||
 | 
			
		||||
@test replace("ḟøøḟøøḟøø", "ḟøø", "bar") == "barbarbar"
 | 
			
		||||
@test replace("ḟøøbarḟøø", "ḟøø", "baz") == "bazbarbaz"
 | 
			
		||||
@test replace("barḟøøḟøø", "ḟøø", "baz") == "barbazbaz"
 | 
			
		||||
 | 
			
		||||
@test replace("foofoofoo", "foo", "ƀäṙ") == "ƀäṙƀäṙƀäṙ"
 | 
			
		||||
@test replace("fooƀäṙfoo", "foo", "baz") == "bazƀäṙbaz"
 | 
			
		||||
@test replace("ƀäṙfoofoo", "foo", "baz") == "ƀäṙbazbaz"
 | 
			
		||||
 | 
			
		||||
@test replace("foofoofoo", "foo", "bar") == "barbarbar"
 | 
			
		||||
@test replace("foobarfoo", "foo", "ƀäż") == "ƀäżbarƀäż"
 | 
			
		||||
@test replace("barfoofoo", "foo", "ƀäż") == "barƀäżƀäż"
 | 
			
		||||
 | 
			
		||||
@test replace("ḟøøḟøøḟøø", "ḟøø", "ƀäṙ") == "ƀäṙƀäṙƀäṙ"
 | 
			
		||||
@test replace("ḟøøƀäṙḟøø", "ḟøø", "baz") == "bazƀäṙbaz"
 | 
			
		||||
@test replace("ƀäṙḟøøḟøø", "ḟøø", "baz") == "ƀäṙbazbaz"
 | 
			
		||||
 | 
			
		||||
@test replace("ḟøøḟøøḟøø", "ḟøø", "bar") == "barbarbar"
 | 
			
		||||
@test replace("ḟøøbarḟøø", "ḟøø", "ƀäż") == "ƀäżbarƀäż"
 | 
			
		||||
@test replace("barḟøøḟøø", "ḟøø", "ƀäż") == "barƀäżƀäż"
 | 
			
		||||
 | 
			
		||||
@test replace("ḟøøḟøøḟøø", "ḟøø", "ƀäṙ") == "ƀäṙƀäṙƀäṙ"
 | 
			
		||||
@test replace("ḟøøƀäṙḟøø", "ḟøø", "ƀäż") == "ƀäżƀäṙƀäż"
 | 
			
		||||
@test replace("ƀäṙḟøøḟøø", "ḟøø", "ƀäż") == "ƀäṙƀäżƀäż"
 | 
			
		||||
 | 
			
		||||
@test replace("", "", "ẍ") == "ẍ"
 | 
			
		||||
@test replace("", "ẍ", "ÿ") == ""
 | 
			
		||||
 | 
			
		||||
@test replace("äƀçđ", "", "π") == "πäπƀπçπđπ"
 | 
			
		||||
@test replace("äƀçđ", "ƀ", "π") == "äπçđ"
 | 
			
		||||
@test replace("äƀçđ", r"ƀ?", "π") == "πäπçπđπ"
 | 
			
		||||
@test replace("äƀçđ", r"ƀ+", "π") == "äπçđ"
 | 
			
		||||
@test replace("äƀçđ", r"ƀ?ç?", "π") == "πäπđπ"
 | 
			
		||||
@test replace("äƀçđ", r"[ƀç]?", "π") == "πäππđπ"
 | 
			
		||||
 | 
			
		||||
@test replace("foobarfoo", r"(fo|ba)", "ẍẍ") == "ẍẍoẍẍrẍẍo"
 | 
			
		||||
 | 
			
		||||
@test replace("ḟøøbarḟøø", r"(ḟø|ba)", "xx") == "xxøxxrxxø"
 | 
			
		||||
@test replace("ḟøøbarḟøø", r"(ḟøø|ba)", "bar") == "barbarrbar"
 | 
			
		||||
 | 
			
		||||
@test replace("fooƀäṙfoo", r"(fo|ƀä)", "xx") == "xxoxxṙxxo"
 | 
			
		||||
@test replace("fooƀäṙfoo", r"(foo|ƀä)", "ƀäṙ") == "ƀäṙƀäṙṙƀäṙ"
 | 
			
		||||
 | 
			
		||||
@test replace("ḟøøƀäṙḟøø", r"(ḟø|ƀä)", "xx") == "xxøxxṙxxø"
 | 
			
		||||
@test replace("ḟøøƀäṙḟøø", r"(ḟøø|ƀä)", "ƀäṙ") == "ƀäṙƀäṙṙƀäṙ"
 | 
			
		||||
 | 
			
		||||
@test replace("foo", "oo", uppercase) == "fOO"
 | 
			
		||||
 | 
			
		||||
# Issue 13332
 | 
			
		||||
@test replace("abc", 'b', 2.1) == "a2.1c"
 | 
			
		||||
 | 
			
		||||
# chomp/chop
 | 
			
		||||
@test chomp("foo\n") == "foo"
 | 
			
		||||
@test chop("fooε") == "foo"
 | 
			
		||||
@test isa(chomp("foo"), SubString)
 | 
			
		||||
@test isa(chop("foo"), SubString)
 | 
			
		||||
 | 
			
		||||
# bytes2hex and hex2bytes
 | 
			
		||||
hex_str = "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"
 | 
			
		||||
bin_val = hex2bytes(hex_str)
 | 
			
		||||
 | 
			
		||||
@test div(length(hex_str), 2) == length(bin_val)
 | 
			
		||||
@test hex_str == bytes2hex(bin_val)
 | 
			
		||||
 | 
			
		||||
bin_val = hex2bytes("07bf")
 | 
			
		||||
@test bin_val[1] == 7
 | 
			
		||||
@test bin_val[2] == 191
 | 
			
		||||
@test typeof(bin_val) == Array{UInt8, 1}
 | 
			
		||||
@test length(bin_val) == 2
 | 
			
		||||
 | 
			
		||||
# all valid hex chars
 | 
			
		||||
@test "0123456789abcdefabcdef" == bytes2hex(hex2bytes("0123456789abcdefABCDEF"))
 | 
			
		||||
 | 
			
		||||
# odd size
 | 
			
		||||
@test_throws ArgumentError hex2bytes("0123456789abcdefABCDEF0")
 | 
			
		||||
 | 
			
		||||
#non-hex characters
 | 
			
		||||
@test_throws ArgumentError hex2bytes("0123456789abcdefABCDEFGH")
 | 
			
		||||
		Reference in New Issue
	
	Block a user