Skip to content

Commit 8ae0e85

Browse files
committed
make tests independent of string representation
1 parent fe3fe7c commit 8ae0e85

File tree

8 files changed

+31
-35
lines changed

8 files changed

+31
-35
lines changed

test/core.jl

+1-5
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,6 @@ let
636636
@test !isdefined(a, :foo)
637637
@test !isdefined(2, :a)
638638

639-
@test isdefined("a",:data)
640-
@test isdefined("a", 1)
641-
@test !isdefined("a", 2)
642-
643639
@test_throws TypeError isdefined(2)
644640
end
645641

@@ -4007,7 +4003,7 @@ b = "aaa"
40074003
c = [0x2, 0x1, 0x3]
40084004

40094005
@test check_nul(a)
4010-
@test check_nul(b.data)
4006+
@test check_nul(convert(Vector{UInt8},b))
40114007
@test check_nul(c)
40124008
d = [0x2, 0x1, 0x3]
40134009
@test check_nul(d)

test/iobuffer.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ write(io,[1,2,3])
103103
skip(io,1)
104104
@test write(io,UInt8(104)) == 1
105105
skip(io,3)
106-
@test write(io,"apples".data) == 3
106+
@test write(io,b"apples") == 3
107107
skip(io,71)
108108
@test write(io,'y') == 1
109109
@test readstring(io) == "happy"

test/misc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ end
403403

404404
let s = "abcα🐨\0x\0"
405405
for T in (UInt8, UInt16, UInt32, Int32)
406-
@test transcode(T, s) == transcode(T, s.data)
406+
@test transcode(T, s) == transcode(T, convert(Vector{UInt8},s))
407407
@test transcode(String, transcode(T, s)) == s
408408
end
409409
end

test/mmap.jl

+19-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
file = tempname()
44
write(file, "Hello World\n")
5-
t = "Hello World".data
5+
t = b"Hello World"
66
@test Mmap.mmap(file, Array{UInt8,3}, (11,1,1)) == reshape(t,(11,1,1))
77
gc(); gc()
88
@test Mmap.mmap(file, Array{UInt8,3}, (1,11,1)) == reshape(t,(1,11,1))
@@ -16,7 +16,7 @@ gc(); gc()
1616
gc(); gc()
1717
@test Mmap.mmap(file, Array{UInt8,2}, (0,12)) == Array{UInt8}((0,0))
1818
m = Mmap.mmap(file, Array{UInt8,3}, (1,2,1))
19-
@test m == reshape("He".data,(1,2,1))
19+
@test m == reshape(b"He",(1,2,1))
2020
finalize(m); m=nothing; gc()
2121

2222
# constructors
@@ -49,7 +49,7 @@ s = open(f->f,file,"w")
4949
@test Mmap.mmap(file) == Array{UInt8}(0) # requested len=0 on empty file
5050
@test Mmap.mmap(file,Vector{UInt8},0) == Array{UInt8}(0)
5151
m = Mmap.mmap(file,Vector{UInt8},12)
52-
m[:] = "Hello World\n".data
52+
m[:] = b"Hello World\n"
5353
Mmap.sync!(m)
5454
finalize(m); m=nothing; gc()
5555
@test open(readstring,file) == "Hello World\n"
@@ -115,10 +115,10 @@ write(file, "Hello World\n")
115115
s = open(file, "r")
116116
@test isreadonly(s) == true
117117
c = Mmap.mmap(s, Vector{UInt8}, (11,))
118-
@test c == "Hello World".data
118+
@test c == b"Hello World"
119119
finalize(c); c=nothing; gc()
120120
c = Mmap.mmap(s, Vector{UInt8}, (UInt16(11),))
121-
@test c == "Hello World".data
121+
@test c == b"Hello World"
122122
finalize(c); c=nothing; gc()
123123
@test_throws ArgumentError Mmap.mmap(s, Vector{UInt8}, (Int16(-11),))
124124
@test_throws ArgumentError Mmap.mmap(s, Vector{UInt8}, (typemax(UInt),))
@@ -136,18 +136,18 @@ close(s)
136136
finalize(c); c=nothing; gc()
137137

138138
c = Mmap.mmap(file)
139-
@test c == "Hellx World\n".data
139+
@test c == b"Hellx World\n"
140140
finalize(c); c=nothing; gc()
141141
c = Mmap.mmap(file, Vector{UInt8}, 3)
142-
@test c == "Hel".data
142+
@test c == b"Hel"
143143
finalize(c); c=nothing; gc()
144144
s = open(file, "r")
145145
c = Mmap.mmap(s, Vector{UInt8}, 6)
146-
@test c == "Hellx ".data
146+
@test c == b"Hellx "
147147
close(s)
148148
finalize(c); c=nothing; gc()
149149
c = Mmap.mmap(file, Vector{UInt8}, 5, 6)
150-
@test c == "World".data
150+
@test c == b"World"
151151
finalize(c); c=nothing; gc()
152152

153153
s = open(file, "w")
@@ -156,26 +156,26 @@ close(s)
156156

157157
# test Mmap.mmap
158158
m = Mmap.mmap(file)
159-
t = "Hello World\n"
159+
tdata = b"Hello World\n"
160160
for i = 1:12
161-
@test m[i] == t.data[i]
161+
@test m[i] == tdata[i]
162162
end
163163
@test_throws BoundsError m[13]
164164
finalize(m); m=nothing; gc()
165165

166166
m = Mmap.mmap(file,Vector{UInt8},6)
167-
@test m[1] == "H".data[1]
168-
@test m[2] == "e".data[1]
169-
@test m[3] == "l".data[1]
170-
@test m[4] == "l".data[1]
171-
@test m[5] == "o".data[1]
172-
@test m[6] == " ".data[1]
167+
@test m[1] == b"H"[1]
168+
@test m[2] == b"e"[1]
169+
@test m[3] == b"l"[1]
170+
@test m[4] == b"l"[1]
171+
@test m[5] == b"o"[1]
172+
@test m[6] == b" "[1]
173173
@test_throws BoundsError m[7]
174174
finalize(m); m=nothing; gc()
175175

176176
m = Mmap.mmap(file,Vector{UInt8},2,6)
177-
@test m[1] == "W".data[1]
178-
@test m[2] == "o".data[1]
177+
@test m[1] == b"W"[1]
178+
@test m[2] == b"o"[1]
179179
@test_throws BoundsError m[3]
180180
finalize(m); m = nothing; gc()
181181

test/perf/shootout/revcomp.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function revcomp(infile="revcomp-input.txt")
4343
input = open(infile, "r")
4444
buff = UInt8[]
4545
while true
46-
line = readline(input).data
46+
line = readuntil(input, UInt8('\n'))
4747
if isempty(line)
4848
# print_buff(buff)
4949
return

test/read.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ for (name, f) in l
296296
@test readstring("$filename.to") == text
297297

298298
verbose && println("$name write(::IOBuffer, ...)")
299-
to = IOBuffer(copy(text.data), false, true)
299+
to = IOBuffer(copy(convert(Vector{UInt8},text)), false, true)
300300
write(to, io())
301301
@test String(take!(to)) == text
302302

@@ -365,14 +365,14 @@ test_read_nbyte()
365365

366366

367367
let s = "qwerty"
368-
@test read(IOBuffer(s)) == s.data
369-
@test read(IOBuffer(s), 10) == s.data
370-
@test read(IOBuffer(s), 1) == s.data[1:1]
368+
@test read(IOBuffer(s)) == convert(Vector{UInt8},s)
369+
@test read(IOBuffer(s), 10) == convert(Vector{UInt8},s)
370+
@test read(IOBuffer(s), 1) == convert(Vector{UInt8},s)[1:1]
371371

372372
# Test growing output array
373373
x = UInt8[]
374374
n = readbytes!(IOBuffer(s), x, 10)
375-
@test x == s.data
375+
@test x == convert(Vector{UInt8},s)
376376
@test n == length(x)
377377
end
378378

test/strings/basic.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ foobaz(ch) = reinterpret(Char, typemax(UInt32))
434434

435435
# issue #18280: next/nextind must return past String's underlying data
436436
for s in ("Hello", "Σ", "こんにちは", "😊😁")
437-
@test next(s, endof(s))[2] > endof(s.data)
438-
@test nextind(s, endof(s)) > endof(s.data)
437+
@test next(s, endof(s))[2] > sizeof(s)
438+
@test nextind(s, endof(s)) > sizeof(s)
439439
end
440440

441441
# Test cmp with AbstractStrings that don't index the same as UTF-8, which would include

test/unicode/utf8.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
let ch = 0x10000
66
for hi = 0xd800:0xdbff
77
for lo = 0xdc00:0xdfff
8-
@test convert(String, String(Char[hi, lo]).data) == string(Char(ch))
8+
@test convert(String, convert(Vector{UInt8},String(Char[hi, lo]))) == string(Char(ch))
99
ch += 1
1010
end
1111
end

0 commit comments

Comments
 (0)