From 133d41d7081a77a187e3ef55582042689d7f185d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 20 Dec 2016 23:03:03 -0500 Subject: [PATCH] make tests independent of string representation --- test/core.jl | 6 +----- test/misc.jl | 2 +- test/mmap.jl | 38 +++++++++++++++++------------------ test/perf/shootout/revcomp.jl | 2 +- test/read.jl | 10 ++++----- test/unicode/utf8.jl | 2 +- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/test/core.jl b/test/core.jl index e2757e304a4b3e..bfe210e68d3a22 100644 --- a/test/core.jl +++ b/test/core.jl @@ -624,10 +624,6 @@ let @test !isdefined(a, :foo) @test !isdefined(2, :a) - @test isdefined("a",:data) - @test isdefined("a", 1) - @test !isdefined("a", 2) - @test_throws TypeError isdefined(2) end @@ -3988,7 +3984,7 @@ b = "aaa" c = [0x2, 0x1, 0x3] @test check_nul(a) -@test check_nul(b.data) +@test check_nul(convert(Vector{UInt8},b)) @test check_nul(c) d = [0x2, 0x1, 0x3] @test check_nul(d) diff --git a/test/misc.jl b/test/misc.jl index 8364a8762987f5..7b76c4c8b960a6 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -403,7 +403,7 @@ end let s = "abcα🐨\0x\0" for T in (UInt8, UInt16, UInt32, Int32) - @test transcode(T, s) == transcode(T, s.data) + @test transcode(T, s) == transcode(T, convert(Vector{UInt8},s)) @test transcode(String, transcode(T, s)) == s end end diff --git a/test/mmap.jl b/test/mmap.jl index 14285d3851de63..f79a1154baf21f 100644 --- a/test/mmap.jl +++ b/test/mmap.jl @@ -2,7 +2,7 @@ file = tempname() write(file, "Hello World\n") -t = "Hello World".data +t = b"Hello World" @test Mmap.mmap(file, Array{UInt8,3}, (11,1,1)) == reshape(t,(11,1,1)) gc(); gc() @test Mmap.mmap(file, Array{UInt8,3}, (1,11,1)) == reshape(t,(1,11,1)) @@ -16,7 +16,7 @@ gc(); gc() gc(); gc() @test Mmap.mmap(file, Array{UInt8,2}, (0,12)) == Array{UInt8}((0,0)) m = Mmap.mmap(file, Array{UInt8,3}, (1,2,1)) -@test m == reshape("He".data,(1,2,1)) +@test m == reshape(b"He",(1,2,1)) finalize(m); m=nothing; gc() # constructors @@ -49,7 +49,7 @@ s = open(f->f,file,"w") @test Mmap.mmap(file) == Array{UInt8}(0) # requested len=0 on empty file @test Mmap.mmap(file,Vector{UInt8},0) == Array{UInt8}(0) m = Mmap.mmap(file,Vector{UInt8},12) -m[:] = "Hello World\n".data +m[:] = b"Hello World\n" Mmap.sync!(m) finalize(m); m=nothing; gc() @test open(readstring,file) == "Hello World\n" @@ -115,10 +115,10 @@ write(file, "Hello World\n") s = open(file, "r") @test isreadonly(s) == true c = Mmap.mmap(s, Vector{UInt8}, (11,)) -@test c == "Hello World".data +@test c == b"Hello World" finalize(c); c=nothing; gc() c = Mmap.mmap(s, Vector{UInt8}, (UInt16(11),)) -@test c == "Hello World".data +@test c == b"Hello World" finalize(c); c=nothing; gc() @test_throws ArgumentError Mmap.mmap(s, Vector{UInt8}, (Int16(-11),)) @test_throws ArgumentError Mmap.mmap(s, Vector{UInt8}, (typemax(UInt),)) @@ -136,18 +136,18 @@ close(s) finalize(c); c=nothing; gc() c = Mmap.mmap(file) -@test c == "Hellx World\n".data +@test c == b"Hellx World\n" finalize(c); c=nothing; gc() c = Mmap.mmap(file, Vector{UInt8}, 3) -@test c == "Hel".data +@test c == b"Hel" finalize(c); c=nothing; gc() s = open(file, "r") c = Mmap.mmap(s, Vector{UInt8}, 6) -@test c == "Hellx ".data +@test c == b"Hellx " close(s) finalize(c); c=nothing; gc() c = Mmap.mmap(file, Vector{UInt8}, 5, 6) -@test c == "World".data +@test c == b"World" finalize(c); c=nothing; gc() s = open(file, "w") @@ -156,26 +156,26 @@ close(s) # test Mmap.mmap m = Mmap.mmap(file) -t = "Hello World\n" +tdata = b"Hello World\n" for i = 1:12 - @test m[i] == t.data[i] + @test m[i] == tdata[i] end @test_throws BoundsError m[13] finalize(m); m=nothing; gc() m = Mmap.mmap(file,Vector{UInt8},6) -@test m[1] == "H".data[1] -@test m[2] == "e".data[1] -@test m[3] == "l".data[1] -@test m[4] == "l".data[1] -@test m[5] == "o".data[1] -@test m[6] == " ".data[1] +@test m[1] == b"H"[1] +@test m[2] == b"e"[1] +@test m[3] == b"l"[1] +@test m[4] == b"l"[1] +@test m[5] == b"o"[1] +@test m[6] == b" "[1] @test_throws BoundsError m[7] finalize(m); m=nothing; gc() m = Mmap.mmap(file,Vector{UInt8},2,6) -@test m[1] == "W".data[1] -@test m[2] == "o".data[1] +@test m[1] == b"W"[1] +@test m[2] == b"o"[1] @test_throws BoundsError m[3] finalize(m); m = nothing; gc() diff --git a/test/perf/shootout/revcomp.jl b/test/perf/shootout/revcomp.jl index 5ef433c092b63c..b9fc342cb97282 100644 --- a/test/perf/shootout/revcomp.jl +++ b/test/perf/shootout/revcomp.jl @@ -43,7 +43,7 @@ function revcomp(infile="revcomp-input.txt") input = open(infile, "r") buff = UInt8[] while true - line = readline(input).data + line = readuntil(input, UInt8('\n')) if isempty(line) # print_buff(buff) return diff --git a/test/read.jl b/test/read.jl index d753c8bdd33b25..0ec4c579d01fd7 100644 --- a/test/read.jl +++ b/test/read.jl @@ -296,7 +296,7 @@ for (name, f) in l @test readstring("$filename.to") == text verbose && println("$name write(::IOBuffer, ...)") - to = IOBuffer(copy(text.data), false, true) + to = IOBuffer(copy(convert(Vector{UInt8},text)), false, true) write(to, io()) @test String(take!(to)) == text @@ -365,14 +365,14 @@ test_read_nbyte() let s = "qwerty" - @test read(IOBuffer(s)) == s.data - @test read(IOBuffer(s), 10) == s.data - @test read(IOBuffer(s), 1) == s.data[1:1] + @test read(IOBuffer(s)) == convert(Vector{UInt8},s) + @test read(IOBuffer(s), 10) == convert(Vector{UInt8},s) + @test read(IOBuffer(s), 1) == convert(Vector{UInt8},s)[1:1] # Test growing output array x = UInt8[] n = readbytes!(IOBuffer(s), x, 10) - @test x == s.data + @test x == convert(Vector{UInt8},s) @test n == length(x) end diff --git a/test/unicode/utf8.jl b/test/unicode/utf8.jl index 0a4665146b6973..9e42860685eb75 100644 --- a/test/unicode/utf8.jl +++ b/test/unicode/utf8.jl @@ -5,7 +5,7 @@ let ch = 0x10000 for hi = 0xd800:0xdbff for lo = 0xdc00:0xdfff - @test convert(String, String(Char[hi, lo]).data) == string(Char(ch)) + @test convert(String, convert(Vector{UInt8},String(Char[hi, lo]))) == string(Char(ch)) ch += 1 end end