Skip to content

Commit b1e7a0e

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 9013d7f commit b1e7a0e

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

test/model_parsing.jl

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ 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 begin
26+
read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String)
27+
end
28+
@equations begin
29+
g.v ~ 0
30+
end
31+
end
32+
end
33+
34+
using .MyMockModule
35+
1036
@connector RealInput begin
1137
u(t), [input = true, unit = u"V"]
1238
end
@@ -28,12 +54,6 @@ end
2854
@variables t [unit = u"s"]
2955
D = Differential(t)
3056

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-
3757
@named p = Pin(; v = π)
3858
@test getdefault(p.v) == π
3959
@test Pin.isconnector == true
@@ -57,18 +77,6 @@ end
5777

5878
@test OnePort.isconnector == false
5979

60-
@mtkmodel Ground begin
61-
@components begin
62-
g = Pin()
63-
end
64-
@icon begin
65-
read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String)
66-
end
67-
@equations begin
68-
g.v ~ 0
69-
end
70-
end
71-
7280
resistor_log = "$(@__DIR__)/logo/resistor.svg"
7381
@mtkmodel Resistor begin
7482
@extend v, i = oneport = OnePort()
@@ -131,7 +139,7 @@ end
131139
capacitor = Capacitor(; C = C_val)
132140
source = Voltage()
133141
constant = Constant(; k = k_val)
134-
ground = Ground()
142+
ground = MyMockModule.Ground()
135143
end
136144

137145
@equations begin

0 commit comments

Comments
 (0)