Skip to content

Commit ed638ec

Browse files
committed
update IOStrings and SplicedStrings for Julia 1.0
1 parent 5974f14 commit ed638ec

File tree

3 files changed

+193
-193
lines changed

3 files changed

+193
-193
lines changed

test/IOString.jl

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
using LazyJSON
2+
using Test
3+
4+
const JSON = LazyJSON
5+
6+
@testset "IOString" begin
7+
8+
@testset "IOString Error" begin
9+
log = [] ; io = Base.BufferStream()
10+
11+
@sync begin
12+
@async begin
13+
try
14+
v = LazyJSON.value(io)
15+
push!(log, Int64(v))
16+
catch e
17+
push!(log, e)
18+
end
19+
end
20+
21+
@test isempty(log)
22+
write(io, "a")
23+
while isempty(log) sleep(0.01) end; @test log[1] isa LazyJSON.ParseError
24+
close(io)
25+
end
26+
end
27+
28+
@testset "IOString Number" begin
29+
log = [] ; io = Base.BufferStream()
30+
31+
@sync begin
32+
@async begin
33+
v = LazyJSON.value(io)
34+
push!(log, Int64(v))
35+
end
36+
37+
@test isempty(log)
38+
write(io, "1") ; sleep(0.01) ;@test isempty(log)
39+
write(io, "2") ; sleep(0.01) ;@test isempty(log)
40+
write(io, "3") ; sleep(0.01) ;@test isempty(log)
41+
close(io) ; while isempty(log) sleep(0.01) end
42+
@test log[1] == 123
43+
end
44+
end
45+
46+
47+
@testset "IOString String" begin
48+
log = [] ; io = Base.BufferStream()
49+
50+
@sync begin
51+
@async begin
52+
v = LazyJSON.value(io)
53+
push!(log, String(v))
54+
end
55+
56+
@test isempty(log)
57+
write(io, "\"1") ; sleep(0.01) ;@test isempty(log)
58+
write(io, "2") ; sleep(0.01) ;@test isempty(log)
59+
write(io, "3\"") ; while isempty(log) sleep(0.01) end
60+
@test log[1] == "123"
61+
close(io)
62+
end
63+
end
64+
65+
@testset "IOString Lazy String" begin
66+
log = [] ; io = Base.BufferStream()
67+
68+
@sync begin
69+
@async begin
70+
v = LazyJSON.value(io)
71+
push!(log, v)
72+
end
73+
74+
etb = LazyJSON.IOStrings.ASCII_ETB
75+
@test isempty(log)
76+
write(io, "\"") ; sleep(0.01) ;@test log[1] isa JSON.String
77+
;@test log[1].s.buf.data[1] == UInt8('"')
78+
@test log[1].s.buf.data[2] == etb
79+
write(io, "12") ; sleep(0.01) ;@test log[1].s.buf.data[1] == UInt8('"')
80+
@test log[1].s.buf.data[2] == etb
81+
write(io, "3\""); sleep(0.01) ;@test log[1] == "123"
82+
close(io)
83+
end
84+
end
85+
86+
@testset "IOString Array" begin
87+
log = [] ; io = Base.BufferStream()
88+
89+
@sync begin
90+
@async begin
91+
v = LazyJSON.value(io)
92+
for x in v
93+
push!(log, Int64(x))
94+
end
95+
end
96+
97+
@test isempty(log)
98+
write(io, "[") ; sleep(0.01) ;@test isempty(log)
99+
write(io, "1") ; sleep(0.01) ;@test isempty(log)
100+
write(io, ",") ; sleep(0.01) ;@test log[1] == 1
101+
write(io, "2,") ; sleep(0.01) ;@test log[2] == 2
102+
write(io, "3") ; sleep(0.01) ;@test length(log) == 2
103+
write(io, "4") ; sleep(0.01) ;@test length(log) == 2
104+
write(io, "5") ; sleep(0.01) ;@test length(log) == 2
105+
write(io, "]") ; sleep(0.01) ;@test log[3] == 345
106+
close(io)
107+
end
108+
end
109+
110+
111+
112+
@testset "IOString Object" begin
113+
log = [] ; io = Base.BufferStream()
114+
115+
@sync begin
116+
t = @async begin
117+
v = LazyJSON.value(io)
118+
for (k, x) in v
119+
push!(log, (String(k), String(x)))
120+
end
121+
end
122+
123+
@test isempty(log)
124+
write(io, "{") ; sleep(0.01) ;@test isempty(log)
125+
write(io, "\"f") ; sleep(0.01) ;@test isempty(log)
126+
write(io, "oo\":") ; sleep(0.01) ;@test isempty(log)
127+
write(io, "\"A") ; sleep(0.01) ;@test isempty(log)
128+
write(io, "\"") ; sleep(0.01) ;@test log[1] == ("foo", "A")
129+
write(io, ",") ; sleep(0.01)
130+
write(io, "\"bar\":")
131+
write(io, " \"123\" ,"); sleep(0.01) ;@test log[2] == ("bar", "123")
132+
write(io, "}") ; sleep(0.01)
133+
close(io)
134+
end
135+
end
136+
137+
138+
@testset "IOString split" begin
139+
log = [] ; io = Base.BufferStream()
140+
141+
gist_json = """{
142+
"id": 1296269,
143+
"owner": {
144+
"login": "octocat"
145+
},
146+
"parent": {
147+
"name": "test-parent"
148+
},
149+
"full_name": "octocat/Hello-World",
150+
"private": false,
151+
"url": "https://api.github.com/repos/octocat/Hello-World",
152+
"language": null,
153+
"pushed_at": "2011-01-26T19:06:43Z",
154+
"permissions": {
155+
"admin": false,
156+
"push": false,
157+
"pull": true
158+
}
159+
}"""
160+
bytes = Vector{UInt8}(codeunits(gist_json))
161+
162+
@sync begin
163+
t = @async begin
164+
v = LazyJSON.value(io)
165+
push!(log, v.id)
166+
push!(log, v.owner.login)
167+
push!(log, v.private)
168+
push!(log, v.permissions.admin)
169+
end
170+
171+
@test isempty(log)
172+
write(io, bytes[1:80]) ; sleep(0.01) ;@test log[1] == 1296269
173+
@test log[2] == "octocat"
174+
@test length(log) == 2
175+
write(io, bytes[81:200]) ; sleep(0.01) ;@test log[3] == false
176+
@test length(log) == 3
177+
write(io, bytes[201:end]) ; sleep(0.01) ;@test log[4] == false
178+
@test length(log) == 4
179+
close(io)
180+
end
181+
end
182+
183+
end #testset
184+

test/SplicedStrings.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ splice!(ss, firstindex(ss), lastindex(ss), "")
8585
@test ss.v == []
8686

8787
ss = SS("AAA", "BBB", "CCC")
88-
i = findfirst(equalto('B'), ss)
88+
i = findfirst(isequal('B'), ss)
8989
splice!(ss, i , i+2, "")
9090
@test ss == "AAACCC"
9191
@test ss.v == ["AAA", "CCC"]
@@ -137,11 +137,11 @@ ss = SS(["Hello", " ", "world", "!"])
137137
@test String(ss) == "Hello world!"
138138

139139
ss = SS("xxxx", "Hello", " ", "world", "!", "yyyy")
140-
@test SubString(ss, findfirst(equalto('l'), ss),
141-
findfirst(equalto('r'), ss)) == "llo wor"
140+
@test SubString(ss, findfirst(isequal('l'), ss),
141+
findfirst(isequal('r'), ss)) == "llo wor"
142142

143-
sss = SubString(ss, findfirst(equalto('l'), ss),
144-
findfirst(equalto('r'), ss))
143+
sss = SubString(ss, findfirst(isequal('l'), ss),
144+
findfirst(isequal('r'), ss))
145145
@test sss isa SubString{SS}
146146

147147
ss = SS("AAA", sss, "BBB")
@@ -219,7 +219,7 @@ ss = SS("one", "two", "three")
219219
@test 'o' in ss
220220
@test 'h' in ss
221221
@test 'r' in ss
222-
i = findfirst(equalto('w'), ss)
222+
i = findfirst(isequal('w'), ss)
223223
@test ss[i] == 'w'
224224

225225

0 commit comments

Comments
 (0)