Skip to content

Commit dd965f6

Browse files
committed
test: test if @mtkmodel works with fully-qualified names
Refactor out `Pin` and `Ground` into a mock-module `MyMockModule`, so we can use `MyMockModule` and see if `@mtkmodel` works with components that have fully-qualified names (i.e., `MyMockModule.Ground`).
1 parent 973c09a commit dd965f6

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

test/model_parsing.jl

+25-17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ using Unitful
77

88
ENV["MTK_ICONS_DIR"] = "$(@__DIR__)/icons"
99

10+
# Mock module used to test if the `@mtkmodel` macro works with fully-qualified names as well.
11+
module MyMockModule
12+
using ..ModelingToolkit, Unitful
13+
14+
export Pin
15+
@connector Pin begin
16+
v(t), [unit = u"V"] # Potential at the pin [V]
17+
i(t), [connect = Flow, unit = u"A"] # Current flowing into the pin [A]
18+
@icon "pin.png"
19+
end
20+
21+
@mtkmodel Ground begin
22+
@components begin
23+
g = Pin()
24+
end
25+
@icon read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String)
26+
@equations begin
27+
g.v ~ 0
28+
end
29+
end
30+
end
31+
32+
using .MyMockModule
33+
1034
@connector RealInput begin
1135
u(t), [input = true, unit = u"V"]
1236
end
@@ -28,12 +52,6 @@ end
2852
@variables t [unit = u"s"]
2953
D = Differential(t)
3054

31-
@connector Pin begin
32-
v(t), [unit = u"V"] # Potential at the pin [V]
33-
i(t), [connect = Flow, unit = u"A"] # Current flowing into the pin [A]
34-
@icon "pin.png"
35-
end
36-
3755
@named p = Pin(; v = π)
3856
@test getdefault(p.v) == π
3957
@test Pin.isconnector == true
@@ -57,16 +75,6 @@ end
5775

5876
@test OnePort.isconnector == false
5977

60-
@mtkmodel Ground begin
61-
@components begin
62-
g = Pin()
63-
end
64-
@icon read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String)
65-
@equations begin
66-
g.v ~ 0
67-
end
68-
end
69-
7078
resistor_log = "$(@__DIR__)/logo/resistor.svg"
7179
@mtkmodel Resistor begin
7280
@extend v, i = oneport = OnePort()
@@ -127,7 +135,7 @@ end
127135
capacitor = Capacitor(; C = C_val)
128136
source = Voltage()
129137
constant = Constant(; k = k_val)
130-
ground = Ground()
138+
ground = MyMockModule.Ground()
131139
end
132140

133141
@equations begin

0 commit comments

Comments
 (0)