|
1 | 1 | defmodule ColouredFlow.Definition.PresentationTest do |
2 | 2 | use ExUnit.Case, async: true |
| 3 | + use ColouredFlow.DefinitionHelpers |
3 | 4 |
|
4 | 5 | alias ColouredFlow.Definition.ColourSet |
5 | 6 | alias ColouredFlow.Definition.ColouredPetriNet |
@@ -85,49 +86,73 @@ defmodule ColouredFlow.Definition.PresentationTest do |
85 | 86 | end |
86 | 87 |
|
87 | 88 | test "prefixes every continuation line of multi-line composite descrs with %%" do |
88 | | - # `Macro.to_string` returns multi-line output for composite descrs. |
89 | | - # Mermaid's `%%` only comments a single line, so every continuation |
90 | | - # line must also start with `%%`; otherwise the parser bails with |
91 | | - # "Expecting NEWLINE/EOF, got NODE_STRING" on the lines that escape |
92 | | - # the comment block. |
93 | | - # Eight keys is enough for `Macro.to_string` to break the map across |
94 | | - # lines (heuristic kicks in past a width threshold). |
| 89 | + # `Macro.to_string` breaks long unions (enums) across lines using `|` as |
| 90 | + # the separator. List ordering is preserved, so the output is |
| 91 | + # deterministic — making an exact-match assertion possible. |
95 | 92 | cpnet = %ColouredPetriNet{ |
96 | 93 | colour_sets: [ |
97 | 94 | %ColourSet{ |
98 | | - name: :user, |
| 95 | + name: :color, |
99 | 96 | type: |
100 | | - {:map, |
101 | | - %{ |
102 | | - name: {:binary, []}, |
103 | | - age: {:integer, []}, |
104 | | - email: {:binary, []}, |
105 | | - active: {:boolean, []}, |
106 | | - role: {:binary, []}, |
107 | | - dept: {:binary, []}, |
108 | | - score: {:integer, []}, |
109 | | - country: {:binary, []} |
110 | | - }} |
| 97 | + {:enum, |
| 98 | + [ |
| 99 | + :alpha, |
| 100 | + :bravo, |
| 101 | + :charlie, |
| 102 | + :delta, |
| 103 | + :echo, |
| 104 | + :foxtrot, |
| 105 | + :golf, |
| 106 | + :hotel, |
| 107 | + :india, |
| 108 | + :juliet, |
| 109 | + :kilo, |
| 110 | + :lima, |
| 111 | + :mike, |
| 112 | + :november |
| 113 | + ]} |
111 | 114 | } |
112 | 115 | ], |
113 | | - places: [%Place{name: "p", colour_set: :user}], |
114 | | - transitions: [], |
115 | | - arcs: [], |
116 | | - variables: [], |
117 | | - constants: [], |
118 | | - functions: [] |
| 116 | + places: [%Place{name: "input", colour_set: :color}], |
| 117 | + transitions: [build_transition!(name: "pass_through")], |
| 118 | + arcs: [ |
| 119 | + build_arc!( |
| 120 | + label: "in", |
| 121 | + place: "input", |
| 122 | + transition: "pass_through", |
| 123 | + orientation: :p_to_t, |
| 124 | + expression: "bind {1, x}" |
| 125 | + ) |
| 126 | + ], |
| 127 | + variables: [%ColouredFlow.Definition.Variable{name: :x, colour_set: :color}] |
119 | 128 | } |
120 | 129 |
|
121 | | - mermaid = Presentation.to_mermaid(cpnet) |
122 | | - |
123 | | - colset_block = |
124 | | - mermaid |
125 | | - |> String.split("\n") |
126 | | - |> Enum.drop_while(&(not String.contains?(&1, "colset user"))) |
127 | | - |> Enum.take_while(&(&1 |> String.trim() |> String.starts_with?("%%"))) |
128 | | - |
129 | | - assert length(colset_block) > 1, "expected multi-line colset output" |
130 | | - assert Enum.all?(colset_block, &(&1 |> String.trim() |> String.starts_with?("%%"))) |
| 130 | + assert_mermaid(cpnet, """ |
| 131 | + flowchart TB |
| 132 | + %% colset color() :: :alpha |
| 133 | + %% | :bravo |
| 134 | + %% | :charlie |
| 135 | + %% | :delta |
| 136 | + %% | :echo |
| 137 | + %% | :foxtrot |
| 138 | + %% | :golf |
| 139 | + %% | :hotel |
| 140 | + %% | :india |
| 141 | + %% | :juliet |
| 142 | + %% | :kilo |
| 143 | + %% | :lima |
| 144 | + %% | :mike |
| 145 | + %% | :november |
| 146 | +
|
| 147 | + %% places |
| 148 | + input((input<br>:color:)) |
| 149 | +
|
| 150 | + %% transitions |
| 151 | + pass_through[pass_through] |
| 152 | +
|
| 153 | + %% arcs |
| 154 | + input --in--> pass_through |
| 155 | + """) |
131 | 156 | end |
132 | 157 | end |
133 | 158 |
|
|
0 commit comments