Skip to content

Commit 3b4749e

Browse files
fahchenclaude
andcommitted
test(presentation): exact-match heredoc for multi-line colset
Replace the split + take_while + Enum.all? assertion with an `assert_mermaid` exact-match call (matching the existing test style). Use a 14-variant enum so `Macro.to_string` actually breaks across lines, and populate transitions/arcs so the expected heredoc has no trailing whitespace pitfalls. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f2a7d3c commit 3b4749e

1 file changed

Lines changed: 60 additions & 35 deletions

File tree

test/coloured_flow/definition/presentation_test.exs

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule ColouredFlow.Definition.PresentationTest do
22
use ExUnit.Case, async: true
3+
use ColouredFlow.DefinitionHelpers
34

45
alias ColouredFlow.Definition.ColourSet
56
alias ColouredFlow.Definition.ColouredPetriNet
@@ -85,49 +86,73 @@ defmodule ColouredFlow.Definition.PresentationTest do
8586
end
8687

8788
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.
9592
cpnet = %ColouredPetriNet{
9693
colour_sets: [
9794
%ColourSet{
98-
name: :user,
95+
name: :color,
9996
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+
]}
111114
}
112115
],
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}]
119128
}
120129

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+
""")
131156
end
132157
end
133158

0 commit comments

Comments
 (0)