Skip to content

Commit

Permalink
make tests independent of string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Dec 21, 2016
1 parent eef764a commit 133d41d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 32 deletions.
6 changes: 1 addition & 5 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions test/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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),))
Expand All @@ -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")
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion test/perf/shootout/revcomp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/unicode/utf8.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 133d41d

Please sign in to comment.