Skip to content

Commit ba7bf24

Browse files
committed
Add tests for expression defaults in @mlj_model
1 parent 11e3f0f commit ba7bf24

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/model_def.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,26 @@ end
151151
@test Cc().a === nothing
152152
@test Cd().a === missing
153153
end
154+
155+
@testset "Expression defaults" begin
156+
# Should work with and without constraint:
157+
@mlj_model mutable struct Foo1
158+
a::Vector{Int} = [1, 2, 3]
159+
end
160+
Foo1().a == [1, 2, 3]
161+
@mlj_model mutable struct Foo2
162+
a::Vector{Int} = [1, 2, 3]::(true)
163+
end
164+
Foo2().a == [1, 2, 3]
165+
166+
# Negative number:
167+
@mlj_model mutable struct Foo3
168+
a::Float64 = -1.0
169+
end
170+
Foo3().a === -1.0
171+
@mlj_model mutable struct Foo4
172+
a::Float64 = (-1.0)::(true)
173+
end
174+
Foo4().a == -1.0
175+
176+
end

0 commit comments

Comments
 (0)