Skip to content

Commit 2bc051e

Browse files
committed
Switch tests to using sprint rather than IOBuffer
1 parent eb1109e commit 2bc051e

File tree

4 files changed

+27
-57
lines changed

4 files changed

+27
-57
lines changed

test/io.jl

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ ulyanovsk = resolve("Europe/Ulyanovsk", tzdata["europe"]...) # No named abbrevi
1010
new_york = resolve("America/New_York", tzdata["northamerica"]...) # Underscore in name
1111
dt = DateTime(1942,12,25,1,23,45)
1212

13-
buffer = IOBuffer()
14-
1513
# TimeZones as a string
1614
@test string(null) == "UTC+03:00"
1715
@test string(fixed) == "UTC+01:00"
@@ -21,50 +19,31 @@ buffer = IOBuffer()
2119
@test string(honolulu) == "Pacific/Honolulu"
2220
@test string(ulyanovsk) == "Europe/Ulyanovsk"
2321

24-
showcompact(buffer, null)
25-
@test Compat.String(take!(buffer)) == "UTC+03:00"
26-
showcompact(buffer, fixed)
27-
@test Compat.String(take!(buffer)) == "UTC+01:00"
28-
showcompact(buffer, est)
29-
@test Compat.String(take!(buffer)) == "EST"
30-
showcompact(buffer, warsaw)
31-
@test Compat.String(take!(buffer)) == "Europe/Warsaw"
32-
showcompact(buffer, apia)
33-
@test Compat.String(take!(buffer)) == "Pacific/Apia"
34-
showcompact(buffer, honolulu)
35-
@test Compat.String(take!(buffer)) == "Pacific/Honolulu"
36-
showcompact(buffer, ulyanovsk)
37-
@test Compat.String(take!(buffer)) == "Europe/Ulyanovsk"
38-
39-
show(buffer, null)
40-
@test Compat.String(take!(buffer)) == "UTC+03:00"
41-
show(buffer, fixed)
42-
@test Compat.String(take!(buffer)) == "UTC+01:00"
43-
show(buffer, est)
44-
@test Compat.String(take!(buffer)) == "EST (UTC-5)"
45-
show(buffer, warsaw)
46-
@test Compat.String(take!(buffer)) == "Europe/Warsaw (UTC+1/UTC+2)"
47-
show(buffer, apia)
48-
@test Compat.String(take!(buffer)) == "Pacific/Apia (UTC+13/UTC+14)"
49-
show(buffer, honolulu)
50-
@test Compat.String(take!(buffer)) == "Pacific/Honolulu (UTC-10)"
51-
show(buffer, ulyanovsk)
52-
@test Compat.String(take!(buffer)) == "Europe/Ulyanovsk (UTC+4)"
22+
@test sprint(showcompact, null) == "UTC+03:00"
23+
@test sprint(showcompact, fixed) == "UTC+01:00"
24+
@test sprint(showcompact, est) == "EST"
25+
@test sprint(showcompact, warsaw) == "Europe/Warsaw"
26+
@test sprint(showcompact, apia) == "Pacific/Apia"
27+
@test sprint(showcompact, honolulu) == "Pacific/Honolulu"
28+
@test sprint(showcompact, ulyanovsk) == "Europe/Ulyanovsk"
29+
30+
@test sprint(show, null) == "UTC+03:00"
31+
@test sprint(show, fixed) == "UTC+01:00"
32+
@test sprint(show, est) == "EST (UTC-5)"
33+
@test sprint(show, warsaw) == "Europe/Warsaw (UTC+1/UTC+2)"
34+
@test sprint(show, apia) == "Pacific/Apia (UTC+13/UTC+14)"
35+
@test sprint(show, honolulu) == "Pacific/Honolulu (UTC-10)"
36+
@test sprint(show, ulyanovsk) == "Europe/Ulyanovsk (UTC+4)"
5337

5438
# UTC and GMT are special cases
55-
show(buffer, FixedTimeZone("UTC"))
56-
@test Compat.String(take!(buffer)) == "UTC"
57-
show(buffer, FixedTimeZone("GMT", 0))
58-
@test Compat.String(take!(buffer)) == "GMT"
59-
show(buffer, FixedTimeZone("FOO", 0))
60-
@test Compat.String(take!(buffer)) == "FOO (UTC+0)"
39+
@test sprint(show, FixedTimeZone("UTC")) == "UTC"
40+
@test sprint(show, FixedTimeZone("GMT", 0)) == "GMT"
41+
@test sprint(show, FixedTimeZone("FOO", 0)) == "FOO (UTC+0)"
6142

6243
# ZonedDateTime as a string
6344
zdt = ZonedDateTime(dt, warsaw)
6445
@test string(zdt) == "1942-12-25T01:23:45+01:00"
65-
66-
show(buffer, zdt)
67-
@test Compat.String(take!(buffer)) == "1942-12-25T01:23:45+01:00"
46+
@test sprint(show, zdt) == "1942-12-25T01:23:45+01:00"
6847

6948

7049
# TimeZone parsing

test/types.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ import Base.Dates: Hour, Second, UTM
3737
# Test exception messages
3838
tz = FixedTimeZone("Imaginary/Zone", 0, 0)
3939

40-
buffer = IOBuffer()
41-
showerror(buffer, AmbiguousTimeError(DateTime(2015,1,1), tz))
42-
@test Compat.String(take!(buffer)) == "AmbiguousTimeError: Local DateTime 2015-01-01T00:00:00 is ambiguous within Imaginary/Zone"
43-
44-
buffer = IOBuffer()
45-
showerror(buffer, NonExistentTimeError(DateTime(2015,1,1), tz))
46-
@test Compat.String(take!(buffer)) == "NonExistentTimeError: Local DateTime 2015-01-01T00:00:00 does not exist within Imaginary/Zone"
40+
@test sprint(showerror, AmbiguousTimeError(DateTime(2015,1,1), tz)) ==
41+
"AmbiguousTimeError: Local DateTime 2015-01-01T00:00:00 is ambiguous within Imaginary/Zone"
42+
@test sprint(showerror, NonExistentTimeError(DateTime(2015,1,1), tz)) ==
43+
"NonExistentTimeError: Local DateTime 2015-01-01T00:00:00 does not exist within Imaginary/Zone"
4744

4845

4946
warsaw = resolve("Europe/Warsaw", tzdata["europe"]...)

test/tzdata/timeoffset.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,5 @@ t = TimeOffset(1,-23,-45)
4747

4848
# TimeOffset show function
4949
t = TimeOffset(1,23,45)
50-
buffer = IOBuffer()
51-
print(buffer, t)
52-
@test Compat.String(take!(buffer)) == "01:23:45"
53-
show(buffer, t)
54-
@test Compat.String(take!(buffer)) == "01:23:45"
50+
@test sprint(print, t) == "01:23:45"
51+
@test sprint(show, t) == "01:23:45"

test/utcoffset.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,5 @@ let a = UTCOffset(7200, 3600), b = UTCOffset(3600, 7200)
4040
@test isequal(a, b)
4141
end
4242

43-
buffer = IOBuffer()
44-
show(buffer, UTCOffset(0, 0))
45-
@test Compat.String(take!(buffer)) == "UTC+0/+0"
46-
show(buffer, UTCOffset(3600, 7200))
47-
@test Compat.String(take!(buffer)) == "UTC+1/+2"
43+
@test sprint(show, UTCOffset(0, 0)) == "UTC+0/+0"
44+
@test sprint(show, UTCOffset(3600, 7200)) == "UTC+1/+2"

0 commit comments

Comments
 (0)