Skip to content

Commit 334ab42

Browse files
authored
Add tests for show (#63)
Also eliminates an extra blank line from display.
1 parent 065e2ce commit 334ab42

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Observables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function Base.show(io::IO, x::Observable{T}) where T
9999
if isdefined(x, :val)
100100
show(io, x.val)
101101
else
102-
println(io, "not assigned yet!")
102+
print(io, "not assigned yet!")
103103
end
104104
end
105105

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ using Test
1010
end
1111
end
1212

13+
@testset "construct and show" begin
14+
obs = Observable(5)
15+
@test string(obs) == "Observable{$Int} with 0 listeners. Value:\n5"
16+
on(identity, obs)
17+
@test string(obs) == "Observable{$Int} with 1 listeners. Value:\n5"
18+
on(x->nothing, obs)
19+
@test string(obs) == "Observable{$Int} with 2 listeners. Value:\n5"
20+
obs[] = 7
21+
@test string(obs) == "Observable{$Int} with 2 listeners. Value:\n7"
22+
obs = Observable{Any}()
23+
@test string(obs) == "Observable{Any} with 0 listeners. Value:\nnot assigned yet!"
24+
end
25+
1326
@testset "listeners" begin
1427
r = Observable(0)
1528
@test r[] == 0

0 commit comments

Comments
 (0)