Skip to content

Commit 1e7feac

Browse files
test: test namespacing of variables of variables
1 parent 4213dbc commit 1e7feac

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/namespacing.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ModelingToolkit
2-
using ModelingToolkit: t_nounits as t, D_nounits as D, iscomplete, does_namespacing
2+
using ModelingToolkit: t_nounits as t, D_nounits as D, iscomplete, does_namespacing,
3+
renamespace
34

45
@variables x(t)
56
@parameters p
@@ -24,3 +25,23 @@ nsys = toggle_namespacing(sys, false)
2425

2526
@test_throws ["namespacing", "inner"] System(
2627
Equation[], t; systems = [nsys], name = :a)
28+
29+
@testset "Variables of variables" begin
30+
@variables x(t) y(x)
31+
@named inner = System([D(x) ~ x, y ~ 2x + 1], t)
32+
@test issetequal(unknowns(inner), [x, y])
33+
ss = mtkcompile(inner)
34+
@test isequal(only(unknowns(ss)), x)
35+
@test isequal(only(observed(ss)), y ~ 2x + 1)
36+
37+
@named sys = System(Equation[], t; systems = [inner])
38+
xx, yy = let sys = inner
39+
xx = renamespace(sys, x)
40+
yy = only(@variables y(xx))
41+
xx, renamespace(sys, yy)
42+
end
43+
@test issetequal(unknowns(sys), [xx, yy])
44+
ss = mtkcompile(sys)
45+
@test isequal(only(unknowns(ss)), xx)
46+
@test isequal(only(observed(ss)), yy ~ 2xx + 1)
47+
end

0 commit comments

Comments
 (0)