Skip to content

Commit 535605a

Browse files
committed
More tests
1 parent c05bc5b commit 535605a

1 file changed

Lines changed: 36 additions & 23 deletions

File tree

test/runtests.jl

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using SimpleUnPack
22
using Test
33

4-
struct Property{T}
5-
x::T
4+
struct Property{X,Y}
5+
x::X
6+
y::Y
67
end
78

8-
Base.propertynames(::Property) = (:x, :y)
9+
Base.propertynames(::Property) = (:x, :y, :z)
910
function Base.getproperty(x::Property, p::Symbol)
10-
if p === :y
11-
return 1.0
11+
if p === :z
12+
return "z"
1213
else
1314
return getfield(x, p)
1415
end
@@ -48,34 +49,46 @@ end
4849

4950
@testset "SimpleUnPack.jl" begin
5051
@testset "Variable as RHS" begin
51-
d = (x=42, y=1.0, z="z")
52+
d = (x=42, y=1.0, z="z1")
5253
@unpack x, z = d
5354
@test x == 42
54-
@test z == "z"
55+
@test z == "z1"
56+
@unpack y = d
57+
@test y == 1.0
5558

56-
d = Struct(42, 1.0, "z")
59+
d = Struct(43, 2.0, "z2")
5760
@unpack x, z = d
58-
@test x == 42
59-
@test z == "z"
61+
@test x == 43
62+
@test z == "z2"
63+
@unpack y = d
64+
@test y == 2.0
6065

61-
d = Property(42)
62-
@unpack y, x = d
63-
@test x == 42
64-
@test y == 1.0
66+
d = Property(44, 3.0)
67+
@unpack x, z = d
68+
@test x == 44
69+
@test z == "z"
70+
@unpack y = d
71+
@test y == 3.0
6572
end
6673

6774
@testset "Expression as RHS" begin
68-
@unpack x, z = (x=42, y=1.0, z="z")
75+
@unpack x, z = (x=42, y=1.0, z="z1")
6976
@test x == 42
70-
@test z == "z"
77+
@test z == "z1"
78+
@unpack y = (x=42, y=1.0, z="z1")
79+
@test y == 1.0
7180

72-
@unpack x, z = Struct(42, 1.0, "z")
73-
@test x == 42
74-
@test z == "z"
81+
@unpack x, z = Struct(43, 2.0, "z2")
82+
@test x == 43
83+
@test z == "z2"
84+
@unpack y = Struct(43, 2.0, "z2")
85+
@test y == 2.0
7586

76-
@unpack y, x = Property(42)
77-
@test x == 42
78-
@test y == 1.0
87+
@unpack x, z = Property(44, 3.0)
88+
@test x == 44
89+
@test z == "z"
90+
@unpack y = Property(44, 3.0)
91+
@test y == 3.0
7992
end
8093

8194
@testset "Type inference" begin
@@ -85,7 +98,7 @@ end
8598
end
8699
@test @inferred(f((; y=1.0, z="z", x=42))) == (42, 1.0)
87100
@test @inferred(f(Struct(42, 1.0, "z"))) == (42, 1.0)
88-
@test @inferred(f(Property(42))) == (42, 1.0)
101+
@test @inferred(f(Property(42, 1.0))) == (42, 1.0)
89102
end
90103

91104
@testset "Errors" begin

0 commit comments

Comments
 (0)