Skip to content

Commit

Permalink
test: test if @mtkmodel works with fully-qualified names
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
thazhemadam committed Dec 7, 2023
1 parent 973c09a commit dd965f6
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions test/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ using Unitful

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

# Mock module used to test if the `@mtkmodel` macro works with fully-qualified names as well.
module MyMockModule
using ..ModelingToolkit, Unitful

export Pin
@connector Pin begin
v(t), [unit = u"V"] # Potential at the pin [V]
i(t), [connect = Flow, unit = u"A"] # Current flowing into the pin [A]
@icon "pin.png"
end

@mtkmodel Ground begin
@components begin
g = Pin()
end
@icon read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String)
@equations begin
g.v ~ 0
end
end
end

using .MyMockModule

@connector RealInput begin
u(t), [input = true, unit = u"V"]
end
Expand All @@ -28,12 +52,6 @@ end
@variables t [unit = u"s"]
D = Differential(t)

@connector Pin begin
v(t), [unit = u"V"] # Potential at the pin [V]
i(t), [connect = Flow, unit = u"A"] # Current flowing into the pin [A]
@icon "pin.png"
end

@named p = Pin(; v = π)
@test getdefault(p.v) == π
@test Pin.isconnector == true
Expand All @@ -57,16 +75,6 @@ end

@test OnePort.isconnector == false

@mtkmodel Ground begin
@components begin
g = Pin()
end
@icon read(abspath(ENV["MTK_ICONS_DIR"], "ground.svg"), String)
@equations begin
g.v ~ 0
end
end

resistor_log = "$(@__DIR__)/logo/resistor.svg"
@mtkmodel Resistor begin
@extend v, i = oneport = OnePort()
Expand Down Expand Up @@ -127,7 +135,7 @@ end
capacitor = Capacitor(; C = C_val)
source = Voltage()
constant = Constant(; k = k_val)
ground = Ground()
ground = MyMockModule.Ground()
end

@equations begin
Expand Down

0 comments on commit dd965f6

Please sign in to comment.