Skip to content

Commit e324633

Browse files
committed
test: conditionally define component array
1 parent a4a79ce commit e324633

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

docs/src/basics/MTKModel_Connector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ end
230230
```
231231

232232
!!! note
233-
233+
234234
For more examples of usage, checkout [ModelingToolkitStandardLibrary.jl](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/)
235235

236236
## More on `Model.structure`

src/systems/model_parsing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,9 @@ function _parse_components!(body, kwargs)
844844
arg.args[2] = b
845845
expr = :(@named $arg)
846846
push!(comp_names, a)
847-
if (isa(b.args[1], Symbol) || Meta.isexpr(b.args[1], :.))
847+
if (isa(b.args[1], Symbol) || Meta.isexpr(b.args[1], :.))
848848
push!(comps, [a, b.args[1]])
849-
end
849+
end
850850
end
851851
_ => error("Couldn't parse the component body: $arg")
852852
end

test/model_parsing.jl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,40 @@ end
680680
:comprehension_2,
681681
:written_out_for_1,
682682
:written_out_for_2,
683-
:single_sub_component,
683+
:single_sub_component
684684
]
685685

686686
@test getdefault(component.comprehension_1.sc) == 1
687687
@test getdefault(component.comprehension_2.sc) == 2
688688
@test getdefault(component.written_out_for_1.sc) == 2
689689
@test getdefault(component.written_out_for_2.sc) == 3
690+
691+
@mtkmodel ConditionalComponent begin
692+
@structural_parameters begin
693+
N = 2
694+
end
695+
@components begin
696+
if N == 2
697+
if_comprehension = [SubComponent(sc = i) for i in 1:N]
698+
elseif N == 3
699+
elseif_comprehension = [SubComponent(sc = i) for i in 1:N]
700+
else
701+
else_comprehension = [SubComponent(sc = i) for i in 1:N]
702+
end
703+
end
704+
end
705+
706+
@named if_component = ConditionalComponent()
707+
@test nameof.(get_systems(if_component)) == [:if_comprehension_1, :if_comprehension_2]
708+
709+
@named elseif_component = ConditionalComponent(; N = 3)
710+
@test nameof.(get_systems(elseif_component)) ==
711+
[:elseif_comprehension_1, :elseif_comprehension_2, :elseif_comprehension_3]
712+
713+
@named else_component = ConditionalComponent(; N = 4)
714+
@test nameof.(get_systems(else_component)) ==
715+
[:else_comprehension_1, :else_comprehension_2,
716+
:else_comprehension_3, :else_comprehension_4]
690717
end
691718

692719
@testset "Parent module of Models" begin

0 commit comments

Comments
 (0)