Skip to content

Commit 81714e5

Browse files
test: test properly scoped discovery of parameters
1 parent 9b2412d commit 81714e5

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

test/variable_scope.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using ModelingToolkit
2-
using ModelingToolkit: SymScope
3-
using Symbolics: arguments, value
2+
using ModelingToolkit: SymScope, t_nounits as t, D_nounits as D
3+
using Symbolics: arguments, value, getname
44
using Test
55

66
@independent_variables t
@@ -84,3 +84,22 @@ arr1 = ODESystem(Equation[], t, [], []; name = :arr1) ∘ arr0
8484
arr_ps = ModelingToolkit.getname.(parameters(arr1))
8585
@test isequal(arr_ps[1], Symbol("xx"))
8686
@test isequal(arr_ps[2], Symbol("arr0₊xx"))
87+
88+
function Foo(; name, p = 1)
89+
@parameters p = p
90+
@variables x(t)
91+
return ODESystem(D(x) ~ p, t; name)
92+
end
93+
function Bar(; name, p = 2)
94+
@parameters p = p
95+
@variables x(t)
96+
@named foo = Foo(; p)
97+
return ODESystem(D(x) ~ p + t, t; systems = [foo], name)
98+
end
99+
@named bar = Bar()
100+
bar = complete(bar)
101+
@test length(parameters(bar)) == 2
102+
@test sort(getname.(parameters(bar))) == [:foo₊p, :p]
103+
defs = ModelingToolkit.defaults(bar)
104+
@test defs[bar.p] == 2
105+
@test isequal(defs[bar.foo.p], bar.p)

0 commit comments

Comments
 (0)