zombie-mermaid 2.2.3 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/ascii.cjs +1 -11
- package/dist/ascii.d.cts +1 -167
- package/dist/ascii.d.ts +1 -167
- package/dist/ascii.js +1 -6591
- package/dist/cli.js +836 -10946
- package/dist/index.cjs +2 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -680
- package/dist/index.d.ts +42 -680
- package/dist/index.js +408 -10002
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +1 -17909
- package/dist/mcp.d.cts +1 -11
- package/dist/mcp.d.ts +1 -11
- package/dist/mcp.js +1 -17884
- package/package.json +29 -29
- package/src/__tests__/workspace-package-boundaries.test.ts +15 -16
- package/src/__tests__/xychart-parser-categories.test.ts +78 -0
- package/src/ascii-entry.ts +14 -0
- package/src/cli/html-viewer.ts +5 -0
- package/src/mcp-entry.ts +21 -0
- package/dist/ascii.cjs.map +0 -1
- package/dist/ascii.js.map +0 -1
- package/dist/mcp.cjs.map +0 -1
- package/dist/mcp.js.map +0 -1
- package/packages/ascii-renderer/LICENSE +0 -22
- package/packages/ascii-renderer/src/ansi.ts +0 -490
- package/packages/ascii-renderer/src/canvas.ts +0 -658
- package/packages/ascii-renderer/src/class-diagram.ts +0 -2001
- package/packages/ascii-renderer/src/converter.ts +0 -446
- package/packages/ascii-renderer/src/coords.ts +0 -58
- package/packages/ascii-renderer/src/display-width.ts +0 -151
- package/packages/ascii-renderer/src/draw-arrows.ts +0 -549
- package/packages/ascii-renderer/src/draw-boxes.ts +0 -267
- package/packages/ascii-renderer/src/draw-bundles.ts +0 -611
- package/packages/ascii-renderer/src/draw-lines.ts +0 -174
- package/packages/ascii-renderer/src/draw-subgraphs.ts +0 -108
- package/packages/ascii-renderer/src/draw.ts +0 -337
- package/packages/ascii-renderer/src/edge-bundling.ts +0 -435
- package/packages/ascii-renderer/src/edge-cell-styles.ts +0 -81
- package/packages/ascii-renderer/src/edge-routing.ts +0 -1049
- package/packages/ascii-renderer/src/er-diagram.ts +0 -1488
- package/packages/ascii-renderer/src/flowchart.ts +0 -94
- package/packages/ascii-renderer/src/grid-occupancy.ts +0 -234
- package/packages/ascii-renderer/src/grid.ts +0 -1267
- package/packages/ascii-renderer/src/hyperlinks.ts +0 -248
- package/packages/ascii-renderer/src/index.ts +0 -163
- package/packages/ascii-renderer/src/lane-search.ts +0 -68
- package/packages/ascii-renderer/src/multiline-utils.ts +0 -82
- package/packages/ascii-renderer/src/pathfinder.ts +0 -448
- package/packages/ascii-renderer/src/registry.ts +0 -88
- package/packages/ascii-renderer/src/sequence.ts +0 -1318
- package/packages/ascii-renderer/src/shapes/circle.ts +0 -31
- package/packages/ascii-renderer/src/shapes/corners.ts +0 -273
- package/packages/ascii-renderer/src/shapes/diamond.ts +0 -31
- package/packages/ascii-renderer/src/shapes/hexagon.ts +0 -31
- package/packages/ascii-renderer/src/shapes/index.ts +0 -123
- package/packages/ascii-renderer/src/shapes/rectangle.ts +0 -199
- package/packages/ascii-renderer/src/shapes/rounded.ts +0 -31
- package/packages/ascii-renderer/src/shapes/special.ts +0 -352
- package/packages/ascii-renderer/src/shapes/stadium.ts +0 -122
- package/packages/ascii-renderer/src/shapes/state.ts +0 -204
- package/packages/ascii-renderer/src/shapes/types.ts +0 -78
- package/packages/ascii-renderer/src/territory.ts +0 -136
- package/packages/ascii-renderer/src/types.ts +0 -454
- package/packages/ascii-renderer/src/validate.ts +0 -189
- package/packages/ascii-renderer/src/xychart.ts +0 -1085
- package/packages/core/LICENSE +0 -22
- package/packages/core/src/click-directive.ts +0 -106
- package/packages/core/src/color-utils.ts +0 -205
- package/packages/core/src/diagram-type.ts +0 -35
- package/packages/core/src/direction-override.ts +0 -46
- package/packages/core/src/direction.ts +0 -56
- package/packages/core/src/index.ts +0 -34
- package/packages/core/src/init-directive.ts +0 -248
- package/packages/core/src/multiline-utils.ts +0 -275
- package/packages/core/src/statements.ts +0 -197
- package/packages/core/src/style-directives.ts +0 -214
- package/packages/core/src/text-metrics.ts +0 -498
- package/packages/core/src/theme.ts +0 -696
- package/packages/core/src/types.ts +0 -670
- package/packages/mcp/LICENSE +0 -22
- package/packages/mcp/src/index.ts +0 -17
- package/packages/mcp/src/server.ts +0 -135
- package/packages/mcp/src/tools/check-sequence-activations.ts +0 -91
- package/packages/mcp/src/tools/fix-sequence-activations.ts +0 -77
- package/packages/mcp/src/tools/render-ascii.ts +0 -99
- package/packages/mcp/src/tools/render-svg.ts +0 -95
- package/packages/mermaid-parser/LICENSE +0 -22
- package/packages/mermaid-parser/src/class/format.ts +0 -15
- package/packages/mermaid-parser/src/class/parser.ts +0 -593
- package/packages/mermaid-parser/src/class/types.ts +0 -166
- package/packages/mermaid-parser/src/er/parser.ts +0 -286
- package/packages/mermaid-parser/src/er/types.ts +0 -99
- package/packages/mermaid-parser/src/expanded-shapes.ts +0 -376
- package/packages/mermaid-parser/src/index.ts +0 -48
- package/packages/mermaid-parser/src/sequence/activation-check.ts +0 -149
- package/packages/mermaid-parser/src/sequence/activation-fix.ts +0 -112
- package/packages/mermaid-parser/src/sequence/box-color.ts +0 -85
- package/packages/mermaid-parser/src/sequence/parser.ts +0 -613
- package/packages/mermaid-parser/src/sequence/types.ts +0 -242
- package/packages/mermaid-parser/src/xychart/colors.ts +0 -177
- package/packages/mermaid-parser/src/xychart/parser.ts +0 -203
- package/packages/mermaid-parser/src/xychart/types.ts +0 -150
- package/packages/svg-renderer/LICENSE +0 -22
- package/packages/svg-renderer/src/class/layout.ts +0 -360
- package/packages/svg-renderer/src/class/renderer.ts +0 -636
- package/packages/svg-renderer/src/edge-curves.ts +0 -204
- package/packages/svg-renderer/src/elk-instance.ts +0 -292
- package/packages/svg-renderer/src/er/layout.ts +0 -200
- package/packages/svg-renderer/src/er/renderer.ts +0 -493
- package/packages/svg-renderer/src/index.ts +0 -58
- package/packages/svg-renderer/src/layout-engine/constants.ts +0 -19
- package/packages/svg-renderer/src/layout-engine/edge-bundling.ts +0 -379
- package/packages/svg-renderer/src/layout-engine/elk-adapter-utils.ts +0 -81
- package/packages/svg-renderer/src/layout-engine/elk-graph-builder.ts +0 -240
- package/packages/svg-renderer/src/layout-engine/from-elk.ts +0 -685
- package/packages/svg-renderer/src/layout-engine/layer-alignment.ts +0 -174
- package/packages/svg-renderer/src/layout-engine/to-elk.ts +0 -695
- package/packages/svg-renderer/src/layout-engine.ts +0 -74
- package/packages/svg-renderer/src/layout.ts +0 -8
- package/packages/svg-renderer/src/renderer.ts +0 -1485
- package/packages/svg-renderer/src/resolve-colors.ts +0 -339
- package/packages/svg-renderer/src/sequence/layout.ts +0 -698
- package/packages/svg-renderer/src/sequence/renderer.ts +0 -546
- package/packages/svg-renderer/src/shape-clipping.ts +0 -197
- package/packages/svg-renderer/src/styles.ts +0 -118
- package/packages/svg-renderer/src/xychart/layout.ts +0 -682
- package/packages/svg-renderer/src/xychart/renderer.ts +0 -684
- package/src/__tests__/ascii-canvas-write.test.ts +0 -137
- package/src/__tests__/ascii-charset-border-junctions.test.ts +0 -63
- package/src/__tests__/ascii-cjk-width.test.ts +0 -150
- package/src/__tests__/ascii-class-box-occupancy.test.ts +0 -462
- package/src/__tests__/ascii-class-column-width-488-489.test.ts +0 -639
- package/src/__tests__/ascii-class-cross-level-jog-corruption.test.ts +0 -187
- package/src/__tests__/ascii-class-detour-label-routing-487.test.ts +0 -114
- package/src/__tests__/ascii-class-diagram-compartments.test.ts +0 -70
- package/src/__tests__/ascii-class-label-box-collision.test.ts +0 -60
- package/src/__tests__/ascii-class-label-row-collision-531.test.ts +0 -135
- package/src/__tests__/ascii-class-label-territory-row-awareness.test.ts +0 -57
- package/src/__tests__/ascii-class-padding.test.ts +0 -104
- package/src/__tests__/ascii-class-parent-alignment-971.test.ts +0 -139
- package/src/__tests__/ascii-class-parent-alignment-972.test.ts +0 -208
- package/src/__tests__/ascii-class-reciprocal-relationships-448.test.ts +0 -169
- package/src/__tests__/ascii-combining-mark-width.test.ts +0 -70
- package/src/__tests__/ascii-coords-overlay.test.ts +0 -64
- package/src/__tests__/ascii-decision-lr-box-start.test.ts +0 -106
- package/src/__tests__/ascii-display-width-unit.test.ts +0 -154
- package/src/__tests__/ascii-draw-arrows-coverage.test.ts +0 -171
- package/src/__tests__/ascii-draw-arrows-single-point-path.test.ts +0 -112
- package/src/__tests__/ascii-edge-bundling-rank-violation-454.test.ts +0 -72
- package/src/__tests__/ascii-edge-ending-glyphs.test.ts +0 -206
- package/src/__tests__/ascii-edge-label-diagonal-fallback-418.test.ts +0 -95
- package/src/__tests__/ascii-edge-routing-fixes.test.ts +0 -178
- package/src/__tests__/ascii-edge-routing-single-point-path.test.ts +0 -107
- package/src/__tests__/ascii-edge-styles.test.ts +0 -149
- package/src/__tests__/ascii-emoji-cluster-width.test.ts +0 -101
- package/src/__tests__/ascii-er-box-occupancy.test.ts +0 -251
- package/src/__tests__/ascii-er-cardinality.test.ts +0 -40
- package/src/__tests__/ascii-er-corner-glyphs.test.ts +0 -249
- package/src/__tests__/ascii-er-jog-stray-line.test.ts +0 -111
- package/src/__tests__/ascii-er-label-padding.test.ts +0 -118
- package/src/__tests__/ascii-er-padding.test.ts +0 -114
- package/src/__tests__/ascii-er-relationship-label-corruption-350.test.ts +0 -458
- package/src/__tests__/ascii-er-relationship-overwrite.test.ts +0 -325
- package/src/__tests__/ascii-er-stray-connectors.test.ts +0 -347
- package/src/__tests__/ascii-er-unrelated-stem-separation-411.test.ts +0 -98
- package/src/__tests__/ascii-er-vertical-one-marker.test.ts +0 -110
- package/src/__tests__/ascii-label-line-terminal-fallback.test.ts +0 -172
- package/src/__tests__/ascii-lane-search.test.ts +0 -207
- package/src/__tests__/ascii-multibox-cjk-width.test.ts +0 -184
- package/src/__tests__/ascii-multiline.test.ts +0 -291
- package/src/__tests__/ascii-padding-edge-cases.test.ts +0 -154
- package/src/__tests__/ascii-pathfinder-route-edge.test.ts +0 -194
- package/src/__tests__/ascii-sequence-alt-else-label.test.ts +0 -236
- package/src/__tests__/ascii-sequence-block-wall-clearance.test.ts +0 -217
- package/src/__tests__/ascii-sequence-box-group.test.ts +0 -159
- package/src/__tests__/ascii-sequence-cjk-width.test.ts +0 -235
- package/src/__tests__/ascii-sequence-create-destroy.test.ts +0 -114
- package/src/__tests__/ascii-sequence-form-invariants.test.ts +0 -432
- package/src/__tests__/ascii-sequence-mermaid-parity.test.ts +0 -219
- package/src/__tests__/ascii-sequence-notes.test.ts +0 -61
- package/src/__tests__/ascii-sequence-padding.test.ts +0 -119
- package/src/__tests__/ascii-sequence-self-arrow.test.ts +0 -206
- package/src/__tests__/ascii-shape-diamond.test.ts +0 -38
- package/src/__tests__/ascii-shape-rectangle.test.ts +0 -258
- package/src/__tests__/ascii-shape-rounded.test.ts +0 -36
- package/src/__tests__/ascii-shapes-circle.test.ts +0 -41
- package/src/__tests__/ascii-shapes-hexagon.test.ts +0 -42
- package/src/__tests__/ascii-shapes-special.test.ts +0 -349
- package/src/__tests__/ascii-shapes-stadium.test.ts +0 -217
- package/src/__tests__/ascii-shapes-state.test.ts +0 -234
- package/src/__tests__/ascii-state-bidirectional-label-swap-530.test.ts +0 -130
- package/src/__tests__/ascii-subgraph-direction-honored-445.test.ts +0 -90
- package/src/__tests__/ascii-subgraph-label-border-clip.test.ts +0 -152
- package/src/__tests__/ascii-subgraph-title-padding.test.ts +0 -77
- package/src/__tests__/ascii-territory-unit.test.ts +0 -219
- package/src/__tests__/ascii-validate.test.ts +0 -220
- package/src/__tests__/ascii.test.ts +0 -328
- package/src/__tests__/box-color.test.ts +0 -80
- package/src/__tests__/class-arrow-directions.test.ts +0 -505
- package/src/__tests__/click-directive.test.ts +0 -63
- package/src/__tests__/color-utils.test.ts +0 -186
- package/src/__tests__/diagram-type.test.ts +0 -28
- package/src/__tests__/draw-lines.test.ts +0 -93
- package/src/__tests__/edge-cell-styles.test.ts +0 -180
- package/src/__tests__/elk-adapter-utils.test.ts +0 -166
- package/src/__tests__/grid-occupancy.test.ts +0 -240
- package/src/__tests__/helpers/ascii-form.ts +0 -142
- package/src/__tests__/helpers/terminal-display-width.ts +0 -74
- package/src/__tests__/mcp-check-sequence-activations-tool.test.ts +0 -85
- package/src/__tests__/mcp-fix-sequence-activations-tool.test.ts +0 -134
- package/src/__tests__/mcp-server.test.ts +0 -163
- package/src/__tests__/pathfinder.test.ts +0 -246
- package/src/__tests__/sequence-activation-fix.test.ts +0 -91
- package/src/__tests__/testdata/ascii/ampersand_lhs.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_lhs_and_rhs.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_rhs.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_td_fanin.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_td_fanout.txt +0 -18
- package/src/__tests__/testdata/ascii/ampersand_without_edge.txt +0 -18
- package/src/__tests__/testdata/ascii/back_reference_from_child.txt +0 -10
- package/src/__tests__/testdata/ascii/backlink_from_bottom.txt +0 -22
- package/src/__tests__/testdata/ascii/backlink_from_top.txt +0 -22
- package/src/__tests__/testdata/ascii/backlink_with_short_y_padding.txt +0 -20
- package/src/__tests__/testdata/ascii/cls_all_relationships.txt +0 -19
- package/src/__tests__/testdata/ascii/cls_annotation.txt +0 -29
- package/src/__tests__/testdata/ascii/cls_association.txt +0 -14
- package/src/__tests__/testdata/ascii/cls_basic.txt +0 -15
- package/src/__tests__/testdata/ascii/cls_dependency.txt +0 -14
- package/src/__tests__/testdata/ascii/cls_inheritance.txt +0 -20
- package/src/__tests__/testdata/ascii/cls_methods.txt +0 -21
- package/src/__tests__/testdata/ascii/comments.txt +0 -23
- package/src/__tests__/testdata/ascii/custom_padding.txt +0 -10
- package/src/__tests__/testdata/ascii/duplicate_labels.txt +0 -19
- package/src/__tests__/testdata/ascii/er_attributes.txt +0 -21
- package/src/__tests__/testdata/ascii/er_basic.txt +0 -8
- package/src/__tests__/testdata/ascii/er_identifying.txt +0 -18
- package/src/__tests__/testdata/ascii/flowchart_tb_simple.txt +0 -29
- package/src/__tests__/testdata/ascii/graph_bt_direction.txt +0 -28
- package/src/__tests__/testdata/ascii/graph_tb_direction.txt +0 -26
- package/src/__tests__/testdata/ascii/nested_subgraphs_with_labels.txt +0 -36
- package/src/__tests__/testdata/ascii/preserve_order_of_definition.txt +0 -23
- package/src/__tests__/testdata/ascii/self_reference.txt +0 -10
- package/src/__tests__/testdata/ascii/self_reference_with_edge.txt +0 -10
- package/src/__tests__/testdata/ascii/seq_basic.txt +0 -17
- package/src/__tests__/testdata/ascii/seq_multiple_messages.txt +0 -25
- package/src/__tests__/testdata/ascii/seq_self_message.txt +0 -18
- package/src/__tests__/testdata/ascii/single_node.txt +0 -8
- package/src/__tests__/testdata/ascii/single_node_longer_name.txt +0 -8
- package/src/__tests__/testdata/ascii/subgraph_complex_mixed.txt +0 -38
- package/src/__tests__/testdata/ascii/subgraph_complex_nested.txt +0 -49
- package/src/__tests__/testdata/ascii/subgraph_direction_override.txt +0 -47
- package/src/__tests__/testdata/ascii/subgraph_empty.txt +0 -10
- package/src/__tests__/testdata/ascii/subgraph_mixed_nodes.txt +0 -20
- package/src/__tests__/testdata/ascii/subgraph_mixed_nodes_td.txt +0 -48
- package/src/__tests__/testdata/ascii/subgraph_multiple_edges.txt +0 -32
- package/src/__tests__/testdata/ascii/subgraph_multiple_nodes.txt +0 -16
- package/src/__tests__/testdata/ascii/subgraph_nested.txt +0 -24
- package/src/__tests__/testdata/ascii/subgraph_nested_with_external.txt +0 -30
- package/src/__tests__/testdata/ascii/subgraph_node_outside_lr.txt +0 -17
- package/src/__tests__/testdata/ascii/subgraph_single_node.txt +0 -16
- package/src/__tests__/testdata/ascii/subgraph_td_direction.txt +0 -26
- package/src/__tests__/testdata/ascii/subgraph_td_multiple.txt +0 -44
- package/src/__tests__/testdata/ascii/subgraph_td_multiple_paddingy.txt +0 -42
- package/src/__tests__/testdata/ascii/subgraph_three_levels_nested.txt +0 -32
- package/src/__tests__/testdata/ascii/subgraph_three_separate.txt +0 -24
- package/src/__tests__/testdata/ascii/subgraph_two_separate.txt +0 -20
- package/src/__tests__/testdata/ascii/subgraph_with_labels.txt +0 -20
- package/src/__tests__/testdata/ascii/three_nodes.txt +0 -9
- package/src/__tests__/testdata/ascii/three_nodes_single_line.txt +0 -8
- package/src/__tests__/testdata/ascii/two_layer_single_graph.txt +0 -19
- package/src/__tests__/testdata/ascii/two_layer_single_graph_longer_names.txt +0 -19
- package/src/__tests__/testdata/ascii/two_nodes_linked.txt +0 -8
- package/src/__tests__/testdata/ascii/two_nodes_longer_names.txt +0 -8
- package/src/__tests__/testdata/ascii/two_root_nodes.txt +0 -19
- package/src/__tests__/testdata/ascii/two_root_nodes_longer_names.txt +0 -19
- package/src/__tests__/testdata/ascii/two_single_root_nodes.txt +0 -19
- package/src/__tests__/testdata/unicode/ampersand_lhs.txt +0 -18
- package/src/__tests__/testdata/unicode/ampersand_lhs_and_rhs.txt +0 -18
- package/src/__tests__/testdata/unicode/ampersand_rhs.txt +0 -18
- package/src/__tests__/testdata/unicode/ampersand_without_edge.txt +0 -18
- package/src/__tests__/testdata/unicode/back_reference_from_child.txt +0 -10
- package/src/__tests__/testdata/unicode/backlink_from_bottom.txt +0 -22
- package/src/__tests__/testdata/unicode/backlink_from_top.txt +0 -22
- package/src/__tests__/testdata/unicode/cls_all_relationships.txt +0 -19
- package/src/__tests__/testdata/unicode/cls_annotation.txt +0 -29
- package/src/__tests__/testdata/unicode/cls_association.txt +0 -14
- package/src/__tests__/testdata/unicode/cls_basic.txt +0 -15
- package/src/__tests__/testdata/unicode/cls_dependency.txt +0 -14
- package/src/__tests__/testdata/unicode/cls_inheritance.txt +0 -20
- package/src/__tests__/testdata/unicode/cls_methods.txt +0 -21
- package/src/__tests__/testdata/unicode/comments.txt +0 -23
- package/src/__tests__/testdata/unicode/duplicate_labels.txt +0 -19
- package/src/__tests__/testdata/unicode/er_attributes.txt +0 -21
- package/src/__tests__/testdata/unicode/er_basic.txt +0 -8
- package/src/__tests__/testdata/unicode/er_identifying.txt +0 -18
- package/src/__tests__/testdata/unicode/graph_bt_direction.txt +0 -28
- package/src/__tests__/testdata/unicode/preserve_order_of_definition.txt +0 -23
- package/src/__tests__/testdata/unicode/self_reference.txt +0 -10
- package/src/__tests__/testdata/unicode/self_reference_with_edge.txt +0 -10
- package/src/__tests__/testdata/unicode/seq_basic.txt +0 -17
- package/src/__tests__/testdata/unicode/seq_multiple_messages.txt +0 -25
- package/src/__tests__/testdata/unicode/seq_self_message.txt +0 -18
- package/src/__tests__/testdata/unicode/single_node.txt +0 -8
- package/src/__tests__/testdata/unicode/single_node_longer_name.txt +0 -8
- package/src/__tests__/testdata/unicode/three_nodes.txt +0 -9
- package/src/__tests__/testdata/unicode/three_nodes_single_line.txt +0 -8
- package/src/__tests__/testdata/unicode/two_layer_single_graph.txt +0 -19
- package/src/__tests__/testdata/unicode/two_layer_single_graph_longer_names.txt +0 -19
- package/src/__tests__/testdata/unicode/two_nodes_linked.txt +0 -8
- package/src/__tests__/testdata/unicode/two_nodes_longer_names.txt +0 -8
- package/src/__tests__/testdata/unicode/two_root_nodes.txt +0 -19
- package/src/__tests__/testdata/unicode/two_root_nodes_longer_names.txt +0 -19
- package/src/__tests__/testdata/unicode/two_single_root_nodes.txt +0 -19
- package/src/__tests__/text-metrics.test.ts +0 -473
- package/src/__tests__/theme-palette-contrast.test.ts +0 -84
- package/src/__tests__/theme.test.ts +0 -132
- package/src/__tests__/xychart-ascii.test.ts +0 -376
- package/src/__tests__/xychart-colors.test.ts +0 -149
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
createGrid,
|
|
4
|
-
isOccupied,
|
|
5
|
-
isFree,
|
|
6
|
-
isBlockFree,
|
|
7
|
-
placeBlock,
|
|
8
|
-
pathCells,
|
|
9
|
-
cloneGrid,
|
|
10
|
-
NODE_BLOCK_SIZE,
|
|
11
|
-
} from '../../packages/ascii-renderer/src/grid-occupancy.ts'
|
|
12
|
-
|
|
13
|
-
describe('grid-occupancy', () => {
|
|
14
|
-
it('createGrid starts empty', () => {
|
|
15
|
-
const grid = createGrid()
|
|
16
|
-
expect(isOccupied(grid, { x: 0, y: 0 })).toBe(false)
|
|
17
|
-
expect(isFree(grid, { x: 0, y: 0 })).toBe(true)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
describe('isFree', () => {
|
|
21
|
-
it('is false for negative coordinates even when unoccupied', () => {
|
|
22
|
-
const grid = createGrid()
|
|
23
|
-
expect(isOccupied(grid, { x: -1, y: 0 })).toBe(false)
|
|
24
|
-
expect(isFree(grid, { x: -1, y: 0 })).toBe(false)
|
|
25
|
-
expect(isFree(grid, { x: 0, y: -1 })).toBe(false)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('is false for an occupied non-negative cell', () => {
|
|
29
|
-
const grid = createGrid()
|
|
30
|
-
placeBlock(grid, { x: 2, y: 2 }, 1)
|
|
31
|
-
expect(isFree(grid, { x: 2, y: 2 })).toBe(false)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('is true for a free non-negative cell', () => {
|
|
35
|
-
const grid = createGrid()
|
|
36
|
-
expect(isFree(grid, { x: 5, y: 5 })).toBe(true)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
describe('isBlockFree / placeBlock', () => {
|
|
41
|
-
it('reports a fresh block as free, then occupied after placing', () => {
|
|
42
|
-
const grid = createGrid()
|
|
43
|
-
const origin = { x: 0, y: 0 }
|
|
44
|
-
expect(isBlockFree(grid, origin)).toBe(true)
|
|
45
|
-
placeBlock(grid, origin)
|
|
46
|
-
expect(isBlockFree(grid, origin)).toBe(false)
|
|
47
|
-
// Every cell in the default NODE_BLOCK_SIZE x NODE_BLOCK_SIZE block
|
|
48
|
-
// is reserved, not just the origin cell.
|
|
49
|
-
for (let dx = 0; dx < NODE_BLOCK_SIZE; dx++) {
|
|
50
|
-
for (let dy = 0; dy < NODE_BLOCK_SIZE; dy++) {
|
|
51
|
-
expect(isOccupied(grid, { x: origin.x + dx, y: origin.y + dy })).toBe(
|
|
52
|
-
true,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('detects partial overlap with an already-placed block', () => {
|
|
59
|
-
const grid = createGrid()
|
|
60
|
-
placeBlock(grid, { x: 0, y: 0 }) // occupies (0,0)..(2,2)
|
|
61
|
-
// Shifted by 1 in each axis: overlaps the first block at (1,1)-(2,2)
|
|
62
|
-
// even though its own origin cell (1,1) is inside the first block too.
|
|
63
|
-
expect(isBlockFree(grid, { x: 1, y: 1 })).toBe(false)
|
|
64
|
-
// Fully disjoint block (mod-4 pitch) is free.
|
|
65
|
-
expect(isBlockFree(grid, { x: 4, y: 0 })).toBe(true)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('throws rather than silently overwriting on collision', () => {
|
|
69
|
-
const grid = createGrid()
|
|
70
|
-
placeBlock(grid, { x: 0, y: 0 })
|
|
71
|
-
expect(() => placeBlock(grid, { x: 1, y: 1 })).toThrow(/already occupied/)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('supports a single-cell block via size=1', () => {
|
|
75
|
-
const grid = createGrid()
|
|
76
|
-
placeBlock(grid, { x: 3, y: 3 }, 1)
|
|
77
|
-
expect(isOccupied(grid, { x: 3, y: 3 })).toBe(true)
|
|
78
|
-
expect(isOccupied(grid, { x: 4, y: 3 })).toBe(false)
|
|
79
|
-
expect(isOccupied(grid, { x: 3, y: 4 })).toBe(false)
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
describe('Grid.delete', () => {
|
|
84
|
-
it('releases a cell so it reports free again', () => {
|
|
85
|
-
const grid = createGrid()
|
|
86
|
-
grid.add('5,5')
|
|
87
|
-
expect(grid.has('5,5')).toBe(true)
|
|
88
|
-
grid.delete('5,5')
|
|
89
|
-
expect(grid.has('5,5')).toBe(false)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('is a no-op for a cell that was never reserved', () => {
|
|
93
|
-
const grid = createGrid()
|
|
94
|
-
expect(() => grid.delete('9,9')).not.toThrow()
|
|
95
|
-
expect(grid.has('9,9')).toBe(false)
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
describe('pathCells', () => {
|
|
100
|
-
it('returns an empty array for an empty path', () => {
|
|
101
|
-
expect(pathCells([])).toEqual([])
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('returns the single point for a one-point path', () => {
|
|
105
|
-
expect(pathCells([{ x: 4, y: 7 }])).toEqual([{ x: 4, y: 7 }])
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('walks every intermediate cell of a horizontal segment', () => {
|
|
109
|
-
const cells = pathCells([
|
|
110
|
-
{ x: 0, y: 0 },
|
|
111
|
-
{ x: 3, y: 0 },
|
|
112
|
-
])
|
|
113
|
-
expect(cells).toEqual([
|
|
114
|
-
{ x: 0, y: 0 },
|
|
115
|
-
{ x: 1, y: 0 },
|
|
116
|
-
{ x: 2, y: 0 },
|
|
117
|
-
{ x: 3, y: 0 },
|
|
118
|
-
])
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('walks every intermediate cell of a vertical segment', () => {
|
|
122
|
-
const cells = pathCells([
|
|
123
|
-
{ x: 2, y: 5 },
|
|
124
|
-
{ x: 2, y: 2 },
|
|
125
|
-
])
|
|
126
|
-
expect(cells).toEqual([
|
|
127
|
-
{ x: 2, y: 5 },
|
|
128
|
-
{ x: 2, y: 4 },
|
|
129
|
-
{ x: 2, y: 3 },
|
|
130
|
-
{ x: 2, y: 2 },
|
|
131
|
-
])
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('walks a clean 45° diagonal', () => {
|
|
135
|
-
const cells = pathCells([
|
|
136
|
-
{ x: 0, y: 0 },
|
|
137
|
-
{ x: 3, y: 3 },
|
|
138
|
-
])
|
|
139
|
-
expect(cells).toEqual([
|
|
140
|
-
{ x: 0, y: 0 },
|
|
141
|
-
{ x: 1, y: 1 },
|
|
142
|
-
{ x: 2, y: 2 },
|
|
143
|
-
{ x: 3, y: 3 },
|
|
144
|
-
])
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Regression for a real crash: `determinePath`'s Case-4 direct fallback
|
|
149
|
-
* (`edge.path = [prefFrom, prefTo]`, used when A* finds no route at
|
|
150
|
-
* all) can produce a segment whose dx/dy ratio is anything, not just
|
|
151
|
-
* 0, equal, or axis-aligned. An earlier version of `pathCells` stepped
|
|
152
|
-
* both axes by `Math.sign(delta)` every iteration, which only ever
|
|
153
|
-
* reaches the target when `|dx| === |dy|` — for a 10-wide, 3-tall
|
|
154
|
-
* segment like this one it walks (10,10), (11,11)... forever, since x
|
|
155
|
-
* and y can never both equal (10,3) on the same iteration. That
|
|
156
|
-
* doesn't just produce a wrong path — it hung the real render until a
|
|
157
|
-
* backing `Set` threw "maximum size exceeded" (see
|
|
158
|
-
* ascii-edge-cross-style-overlap.test.ts for the end-to-end repro).
|
|
159
|
-
* Bresenham handles any ratio and is guaranteed to land exactly on the
|
|
160
|
-
* endpoint in `max(|dx|, |dy|) + 1` steps.
|
|
161
|
-
*/
|
|
162
|
-
it('terminates and lands exactly on the endpoint for a non-45° diagonal', () => {
|
|
163
|
-
const cells = pathCells([
|
|
164
|
-
{ x: 0, y: 0 },
|
|
165
|
-
{ x: 10, y: 3 },
|
|
166
|
-
])
|
|
167
|
-
expect(cells[cells.length - 1]).toEqual({ x: 10, y: 3 })
|
|
168
|
-
expect(cells.length).toBe(11) // max(|10|, |3|) + 1
|
|
169
|
-
// Every step must move by at most one cell on each axis (no skips,
|
|
170
|
-
// no doubling back) — Bresenham can step both axes in the same
|
|
171
|
-
// iteration to stay close to the true line, so Chebyshev distance
|
|
172
|
-
// between consecutive cells is always exactly 1, though Manhattan
|
|
173
|
-
// distance can be 1 or 2.
|
|
174
|
-
for (let i = 1; i < cells.length; i++) {
|
|
175
|
-
const a = cells[i - 1]!
|
|
176
|
-
const b = cells[i]!
|
|
177
|
-
expect(Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y))).toBe(1)
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it('walks a multi-segment path corner-to-corner without duplicating the shared corner', () => {
|
|
182
|
-
const cells = pathCells([
|
|
183
|
-
{ x: 0, y: 0 },
|
|
184
|
-
{ x: 2, y: 0 },
|
|
185
|
-
{ x: 2, y: 2 },
|
|
186
|
-
])
|
|
187
|
-
expect(cells).toEqual([
|
|
188
|
-
{ x: 0, y: 0 },
|
|
189
|
-
{ x: 1, y: 0 },
|
|
190
|
-
{ x: 2, y: 0 },
|
|
191
|
-
{ x: 2, y: 1 },
|
|
192
|
-
{ x: 2, y: 2 },
|
|
193
|
-
])
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Regression: an earlier version silently returned a path truncated at
|
|
198
|
-
* `MAX_WALK_STEPS`, which under-reports to a caller checking "every
|
|
199
|
-
* cell this path touches" (edge-cell-styles.ts's conflict detection,
|
|
200
|
-
* specifically) — a conflict past the cutoff would simply never be
|
|
201
|
-
* seen. Throwing converts that silent blind spot into a loud failure.
|
|
202
|
-
*/
|
|
203
|
-
it('throws rather than silently returning a truncated path past the walk limit', () => {
|
|
204
|
-
expect(() =>
|
|
205
|
-
pathCells([
|
|
206
|
-
{ x: 0, y: 0 },
|
|
207
|
-
{ x: 200_000, y: 0 },
|
|
208
|
-
]),
|
|
209
|
-
).toThrow(/did not reach its endpoint/)
|
|
210
|
-
})
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
describe('Grid.keys / cloneGrid', () => {
|
|
214
|
-
it('keys() iterates every reserved cell', () => {
|
|
215
|
-
const grid = createGrid()
|
|
216
|
-
grid.add('1,1')
|
|
217
|
-
grid.add('2,2')
|
|
218
|
-
expect(new Set(grid.keys())).toEqual(new Set(['1,1', '2,2']))
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
it('cloneGrid copies current reservations into an independent grid', () => {
|
|
222
|
-
const original = createGrid()
|
|
223
|
-
original.add('1,1')
|
|
224
|
-
const clone = cloneGrid(original)
|
|
225
|
-
expect(isOccupied(clone, { x: 1, y: 1 })).toBe(true)
|
|
226
|
-
|
|
227
|
-
// Independent: mutating one after cloning doesn't affect the other.
|
|
228
|
-
original.add('2,2')
|
|
229
|
-
expect(isOccupied(clone, { x: 2, y: 2 })).toBe(false)
|
|
230
|
-
|
|
231
|
-
clone.add('3,3')
|
|
232
|
-
expect(isOccupied(original, { x: 3, y: 3 })).toBe(false)
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
it('cloneGrid on an empty grid produces an empty grid', () => {
|
|
236
|
-
const clone = cloneGrid(createGrid())
|
|
237
|
-
expect([...clone.keys()]).toEqual([])
|
|
238
|
-
})
|
|
239
|
-
})
|
|
240
|
-
})
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structural fact extraction for rendered ASCII diagrams — shared by the
|
|
3
|
-
* "form invariant" suites (ascii-sequence-form-invariants.test.ts,
|
|
4
|
-
* ascii-class-box-occupancy.test.ts, ascii-er-box-occupancy.test.ts).
|
|
5
|
-
*
|
|
6
|
-
* These suites assert structural properties of the rendered output (does
|
|
7
|
-
* this box overlap that one, does this label fit inside its container)
|
|
8
|
-
* rather than diffing against a committed fixture. `svg-samples.visual.test.ts`
|
|
9
|
-
* / `ascii-samples.visual.test.ts` only self-diff against their own baseline
|
|
10
|
-
* screenshot, which can never catch a defect that was already present when
|
|
11
|
-
* that baseline was captured — these helpers exist to check the renderer
|
|
12
|
-
* against its own stated semantics instead (e.g. "a box must be wide enough
|
|
13
|
-
* to hold its label", "an unrelated box must never be overwritten").
|
|
14
|
-
*
|
|
15
|
-
* Deliberately works on the *rendered string*, not renderer internals:
|
|
16
|
-
* `renderSequenceAscii`/`renderClassAscii`/`renderErAscii` each do
|
|
17
|
-
* parse→layout→draw→stringify in one function with no layout object
|
|
18
|
-
* exposed, and (checked directly) `src/ascii/er-diagram.ts`'s own occupancy
|
|
19
|
-
* guard (`boxCells`) is a flat, entity-agnostic occupied-cell set — even the
|
|
20
|
-
* renderer's own internals can't answer "which entity owns this cell"
|
|
21
|
-
* without a scan shaped like the one below. Matches this repo's existing
|
|
22
|
-
* convention of small, local, string-based test helpers (see
|
|
23
|
-
* `helpers/terminal-display-width.ts`).
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export interface Rect {
|
|
27
|
-
x0: number
|
|
28
|
-
x1: number
|
|
29
|
-
y0: number
|
|
30
|
-
y1: number
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Border-ish characters in both Unicode and `useAscii: true` box-drawing. */
|
|
34
|
-
const BORDER_CHARS = new Set([
|
|
35
|
-
'│',
|
|
36
|
-
'┌',
|
|
37
|
-
'└',
|
|
38
|
-
'├',
|
|
39
|
-
'┤',
|
|
40
|
-
'┐',
|
|
41
|
-
'┘',
|
|
42
|
-
'─',
|
|
43
|
-
'┬',
|
|
44
|
-
'┴',
|
|
45
|
-
'┼',
|
|
46
|
-
'+',
|
|
47
|
-
'|',
|
|
48
|
-
'-',
|
|
49
|
-
])
|
|
50
|
-
|
|
51
|
-
function isBorderish(ch: string | undefined): boolean {
|
|
52
|
-
return ch !== undefined && BORDER_CHARS.has(ch)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function lineAt(lines: string[], y: number, x: number): string | undefined {
|
|
56
|
-
return lines[y]?.[x]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Locate a named, bordered box (an actor box, a class box, an entity box) by
|
|
61
|
-
* its header text.
|
|
62
|
-
*
|
|
63
|
-
* Finds the row where `name` sits with a border-ish character immediately to
|
|
64
|
-
* its left and right (skipping padding spaces), *and* a border-ish character
|
|
65
|
-
* directly above that same column (the box's top border or a section
|
|
66
|
-
* divider) — the second check keeps a name that's a substring of another
|
|
67
|
-
* name, or that happens to appear inside an attribute/label string, from
|
|
68
|
-
* false-matching a header row it isn't actually part of. Then walks outward
|
|
69
|
-
* from that row along the left/right border columns until the border stops
|
|
70
|
-
* holding, to find the box's full vertical extent.
|
|
71
|
-
*
|
|
72
|
-
* Works identically in Unicode and `useAscii: true` mode: it only asks "is
|
|
73
|
-
* this column border-ish at this row," never which specific glyph is there.
|
|
74
|
-
*/
|
|
75
|
-
export function findBoxRect(ascii: string, name: string): Rect {
|
|
76
|
-
const lines = ascii.split('\n')
|
|
77
|
-
|
|
78
|
-
for (let y = 0; y < lines.length; y++) {
|
|
79
|
-
const line = lines[y]!
|
|
80
|
-
let searchFrom = 0
|
|
81
|
-
for (;;) {
|
|
82
|
-
const idx = line.indexOf(name, searchFrom)
|
|
83
|
-
if (idx === -1) break
|
|
84
|
-
searchFrom = idx + 1
|
|
85
|
-
|
|
86
|
-
let left = idx - 1
|
|
87
|
-
while (left >= 0 && line[left] === ' ') left--
|
|
88
|
-
let right = idx + name.length
|
|
89
|
-
while (right < line.length && line[right] === ' ') right++
|
|
90
|
-
|
|
91
|
-
if (!isBorderish(line[left]) || !isBorderish(line[right])) continue
|
|
92
|
-
// Require a border-ish char directly above this header row (top
|
|
93
|
-
// border or a divider) — rejects a match inside a box's body text.
|
|
94
|
-
if (!isBorderish(lineAt(lines, y - 1, left))) continue
|
|
95
|
-
|
|
96
|
-
const x0 = left
|
|
97
|
-
const x1 = right
|
|
98
|
-
|
|
99
|
-
let y0 = y
|
|
100
|
-
while (
|
|
101
|
-
isBorderish(lineAt(lines, y0 - 1, x0)) &&
|
|
102
|
-
isBorderish(lineAt(lines, y0 - 1, x1))
|
|
103
|
-
) {
|
|
104
|
-
y0--
|
|
105
|
-
}
|
|
106
|
-
let y1 = y
|
|
107
|
-
while (
|
|
108
|
-
isBorderish(lineAt(lines, y1 + 1, x0)) &&
|
|
109
|
-
isBorderish(lineAt(lines, y1 + 1, x1))
|
|
110
|
-
) {
|
|
111
|
-
y1++
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return { x0, x1, y0, y1 }
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
throw new Error(`findBoxRect: no bordered box found for "${name}"`)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Locate free-floating text (a relationship label, a note's own text) that
|
|
123
|
-
* isn't itself inside a bordered box header — same row/column scan as
|
|
124
|
-
* `findBoxRect` but without the border precondition. Returns the tightest
|
|
125
|
-
* rectangle containing every occurrence-adjacent character of `text` on its
|
|
126
|
-
* line (just the matched span, not a box).
|
|
127
|
-
*/
|
|
128
|
-
export function findTextRect(ascii: string, text: string): Rect {
|
|
129
|
-
const lines = ascii.split('\n')
|
|
130
|
-
for (let y = 0; y < lines.length; y++) {
|
|
131
|
-
const idx = lines[y]!.indexOf(text)
|
|
132
|
-
if (idx !== -1) {
|
|
133
|
-
return { x0: idx, x1: idx + text.length - 1, y0: y, y1: y }
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
throw new Error(`findTextRect: "${text}" not found`)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Half-open interval overlap check between two rectangles. */
|
|
140
|
-
export function rectsOverlap(a: Rect, b: Rect): boolean {
|
|
141
|
-
return a.x0 <= b.x1 && a.x1 >= b.x0 && a.y0 <= b.y1 && a.y1 >= b.y0
|
|
142
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Independently re-implemented terminal display-width calculation, shared by
|
|
3
|
-
* the ASCII wide-character regression suites (issues #66, #182, #205, #214).
|
|
4
|
-
*
|
|
5
|
-
* Deliberately does NOT import from `src/ascii/display-width.ts` or
|
|
6
|
-
* `packages/core/src/text-metrics.ts`: these suites verify rendered output against an
|
|
7
|
-
* authority separate from the implementation under test, so that a bug in the
|
|
8
|
-
* renderer's own width helper cannot make its tests pass by agreeing with
|
|
9
|
-
* itself. Mirrors the East Asian Width ranges a real monospace terminal uses
|
|
10
|
-
* to decide whether a code point renders as 1 or 2 columns.
|
|
11
|
-
*
|
|
12
|
-
* Measures per grapheme cluster (`Intl.Segmenter`), not per code point: a
|
|
13
|
-
* real terminal gives zero columns to a combining mark (it attaches to the
|
|
14
|
-
* preceding base character — issue #205) and exactly one glyph's worth of
|
|
15
|
-
* columns to a composed multi-code-point sequence like a ZWJ emoji, flag, or
|
|
16
|
-
* skin-tone modifier (issue #214), not one glyph's worth per code point.
|
|
17
|
-
*/
|
|
18
|
-
import { expect } from 'vitest'
|
|
19
|
-
|
|
20
|
-
const EMOJI_PATTERN = /\p{Extended_Pictographic}|\p{Emoji_Presentation}/u
|
|
21
|
-
/** Unicode general categories Mn (Nonspacing_Mark) and Me (Enclosing_Mark). */
|
|
22
|
-
const COMBINING_MARK_PATTERN = /\p{Mn}|\p{Me}/u
|
|
23
|
-
|
|
24
|
-
const graphemeSegmenter = new Intl.Segmenter(undefined, {
|
|
25
|
-
granularity: 'grapheme',
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
function isWideCodePoint(ch: string): boolean {
|
|
29
|
-
const code = ch.codePointAt(0)!
|
|
30
|
-
return (
|
|
31
|
-
(code >= 0x1100 && code <= 0x115f) || // Hangul Jamo
|
|
32
|
-
(code >= 0x2e80 && code <= 0xa4cf) || // CJK radicals .. Yi
|
|
33
|
-
(code >= 0xac00 && code <= 0xd7a3) || // Hangul syllables
|
|
34
|
-
(code >= 0xf900 && code <= 0xfaff) || // CJK compatibility ideographs
|
|
35
|
-
(code >= 0xff00 && code <= 0xff60) || // Fullwidth forms
|
|
36
|
-
(code >= 0xffe0 && code <= 0xffe6) || // Fullwidth signs
|
|
37
|
-
code >= 0x20000 || // CJK extension B+
|
|
38
|
-
EMOJI_PATTERN.test(ch)
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Number of terminal columns one grapheme cluster occupies: 0, 1, or 2. */
|
|
43
|
-
function clusterWidth(cluster: string): number {
|
|
44
|
-
let sawWide = false
|
|
45
|
-
let sawNonMark = false
|
|
46
|
-
for (const ch of cluster) {
|
|
47
|
-
if (isWideCodePoint(ch)) sawWide = true
|
|
48
|
-
if (!COMBINING_MARK_PATTERN.test(ch)) sawNonMark = true
|
|
49
|
-
}
|
|
50
|
-
if (sawWide) return 2
|
|
51
|
-
return sawNonMark ? 1 : 0
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Number of terminal columns `text` occupies. */
|
|
55
|
-
export function terminalDisplayWidth(text: string): number {
|
|
56
|
-
let width = 0
|
|
57
|
-
for (const { segment } of graphemeSegmenter.segment(text)) {
|
|
58
|
-
width += clusterWidth(segment)
|
|
59
|
-
}
|
|
60
|
-
return width
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** All rendered lines should occupy the same number of terminal columns. */
|
|
64
|
-
export function assertUniformDisplayWidth(ascii: string): void {
|
|
65
|
-
const lines = ascii.split('\n')
|
|
66
|
-
const widths = lines.map(terminalDisplayWidth)
|
|
67
|
-
const expected = widths[0]
|
|
68
|
-
for (let i = 0; i < lines.length; i++) {
|
|
69
|
-
expect(
|
|
70
|
-
widths[i],
|
|
71
|
-
`line ${i} (${JSON.stringify(lines[i])}) has display width ${widths[i]}, expected ${expected}`,
|
|
72
|
-
).toBe(expected)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { checkSequenceActivationsHandler } from '../../packages/mcp/src/tools/check-sequence-activations.ts'
|
|
3
|
-
|
|
4
|
-
function parseReport(text: string): { ok: boolean; issues: unknown[] } {
|
|
5
|
-
return JSON.parse(text) as { ok: boolean; issues: unknown[] }
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
describe('checkSequenceActivationsHandler', () => {
|
|
9
|
-
it('reports ok: true for a diagram with balanced activation', () => {
|
|
10
|
-
const result = checkSequenceActivationsHandler({
|
|
11
|
-
diagram: 'sequenceDiagram\n A->>+B: hello\n B-->>-A: world',
|
|
12
|
-
})
|
|
13
|
-
expect(result.isError).toBeUndefined()
|
|
14
|
-
const [content] = result.content
|
|
15
|
-
if (content?.type !== 'text') {
|
|
16
|
-
throw new Error('Expected text content')
|
|
17
|
-
}
|
|
18
|
-
const report = parseReport(content.text)
|
|
19
|
-
expect(report.ok).toBe(true)
|
|
20
|
-
expect(report.issues).toEqual([])
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('flags a dangling activate with no matching deactivate', () => {
|
|
24
|
-
const result = checkSequenceActivationsHandler({
|
|
25
|
-
diagram: 'sequenceDiagram\n activate A\n A->>B: hello',
|
|
26
|
-
})
|
|
27
|
-
expect(result.isError).toBeUndefined()
|
|
28
|
-
const [content] = result.content
|
|
29
|
-
if (content?.type !== 'text') {
|
|
30
|
-
throw new Error('Expected text content')
|
|
31
|
-
}
|
|
32
|
-
const report = parseReport(content.text)
|
|
33
|
-
expect(report.ok).toBe(false)
|
|
34
|
-
expect(report.issues).toEqual([
|
|
35
|
-
expect.objectContaining({
|
|
36
|
-
code: 'DANGLING_ACTIVATION',
|
|
37
|
-
actorId: 'A',
|
|
38
|
-
}),
|
|
39
|
-
])
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('flags a mismatched deactivate with nothing open', () => {
|
|
43
|
-
const result = checkSequenceActivationsHandler({
|
|
44
|
-
diagram: 'sequenceDiagram\n A->>B: hello\n deactivate A',
|
|
45
|
-
})
|
|
46
|
-
expect(result.isError).toBeUndefined()
|
|
47
|
-
const [content] = result.content
|
|
48
|
-
if (content?.type !== 'text') {
|
|
49
|
-
throw new Error('Expected text content')
|
|
50
|
-
}
|
|
51
|
-
const report = parseReport(content.text)
|
|
52
|
-
expect(report.ok).toBe(false)
|
|
53
|
-
expect(report.issues).toEqual([
|
|
54
|
-
expect.objectContaining({
|
|
55
|
-
code: 'UNMATCHED_DEACTIVATION',
|
|
56
|
-
actorId: 'A',
|
|
57
|
-
}),
|
|
58
|
-
])
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('rejects a non-sequence diagram with a clear error instead of a false report', () => {
|
|
62
|
-
const result = checkSequenceActivationsHandler({
|
|
63
|
-
diagram: 'graph LR\n A --> B',
|
|
64
|
-
})
|
|
65
|
-
expect(result.isError).toBe(true)
|
|
66
|
-
const [content] = result.content
|
|
67
|
-
if (content?.type !== 'text') {
|
|
68
|
-
throw new Error('Expected text content')
|
|
69
|
-
}
|
|
70
|
-
expect(content.text).toContain('only checks sequence diagrams')
|
|
71
|
-
expect(content.text).toContain('"flowchart"')
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('returns an MCP tool error instead of throwing on invalid sequence syntax', () => {
|
|
75
|
-
const result = checkSequenceActivationsHandler({
|
|
76
|
-
diagram: 'sequenceDiagram\n box\n box',
|
|
77
|
-
})
|
|
78
|
-
expect(result.isError).toBe(true)
|
|
79
|
-
const [content] = result.content
|
|
80
|
-
if (content?.type !== 'text') {
|
|
81
|
-
throw new Error('Expected text content')
|
|
82
|
-
}
|
|
83
|
-
expect(content.text).toContain('Failed to check diagram activations')
|
|
84
|
-
})
|
|
85
|
-
})
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { fixSequenceActivationsHandler } from '../../packages/mcp/src/tools/fix-sequence-activations.ts'
|
|
3
|
-
|
|
4
|
-
interface FixReport {
|
|
5
|
-
ok: boolean
|
|
6
|
-
fixedDiagram: string
|
|
7
|
-
fixesApplied: string[]
|
|
8
|
-
remainingIssues: unknown[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function parseReport(text: string): FixReport {
|
|
12
|
-
return JSON.parse(text) as FixReport
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('fixSequenceActivationsHandler', () => {
|
|
16
|
-
it('reports ok: true with no fixes for an already-balanced diagram', () => {
|
|
17
|
-
const result = fixSequenceActivationsHandler({
|
|
18
|
-
diagram: 'sequenceDiagram\n A->>+B: hello\n B-->>-A: world',
|
|
19
|
-
})
|
|
20
|
-
expect(result.isError).toBeUndefined()
|
|
21
|
-
const [content] = result.content
|
|
22
|
-
if (content?.type !== 'text') {
|
|
23
|
-
throw new Error('Expected text content')
|
|
24
|
-
}
|
|
25
|
-
const report = parseReport(content.text)
|
|
26
|
-
expect(report.ok).toBe(true)
|
|
27
|
-
expect(report.fixesApplied).toEqual([])
|
|
28
|
-
expect(report.remainingIssues).toEqual([])
|
|
29
|
-
expect(report.fixedDiagram).toBe(
|
|
30
|
-
'sequenceDiagram\n A->>+B: hello\n B-->>-A: world',
|
|
31
|
-
)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('appends a matching deactivate for a dangling activation', () => {
|
|
35
|
-
const result = fixSequenceActivationsHandler({
|
|
36
|
-
diagram: 'sequenceDiagram\n activate A\n A->>B: hello',
|
|
37
|
-
})
|
|
38
|
-
expect(result.isError).toBeUndefined()
|
|
39
|
-
const [content] = result.content
|
|
40
|
-
if (content?.type !== 'text') {
|
|
41
|
-
throw new Error('Expected text content')
|
|
42
|
-
}
|
|
43
|
-
const report = parseReport(content.text)
|
|
44
|
-
expect(report.ok).toBe(true)
|
|
45
|
-
expect(report.fixesApplied).toHaveLength(1)
|
|
46
|
-
expect(report.remainingIssues).toEqual([])
|
|
47
|
-
expect(report.fixedDiagram.trim().endsWith('deactivate A')).toBe(true)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('fixes multiple dangling activations across different actors', () => {
|
|
51
|
-
const result = fixSequenceActivationsHandler({
|
|
52
|
-
diagram: 'sequenceDiagram\n activate A\n activate B\n A->>B: hello',
|
|
53
|
-
})
|
|
54
|
-
expect(result.isError).toBeUndefined()
|
|
55
|
-
const [content] = result.content
|
|
56
|
-
if (content?.type !== 'text') {
|
|
57
|
-
throw new Error('Expected text content')
|
|
58
|
-
}
|
|
59
|
-
const report = parseReport(content.text)
|
|
60
|
-
expect(report.ok).toBe(true)
|
|
61
|
-
expect(report.fixesApplied).toHaveLength(2)
|
|
62
|
-
expect(report.fixedDiagram).toContain('deactivate A')
|
|
63
|
-
expect(report.fixedDiagram).toContain('deactivate B')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('does not auto-fix an unmatched deactivation, reporting it instead', () => {
|
|
67
|
-
const result = fixSequenceActivationsHandler({
|
|
68
|
-
diagram: 'sequenceDiagram\n A->>B: hello\n deactivate A',
|
|
69
|
-
})
|
|
70
|
-
expect(result.isError).toBeUndefined()
|
|
71
|
-
const [content] = result.content
|
|
72
|
-
if (content?.type !== 'text') {
|
|
73
|
-
throw new Error('Expected text content')
|
|
74
|
-
}
|
|
75
|
-
const report = parseReport(content.text)
|
|
76
|
-
expect(report.ok).toBe(false)
|
|
77
|
-
expect(report.fixesApplied).toEqual([])
|
|
78
|
-
expect(report.fixedDiagram).toBe(
|
|
79
|
-
'sequenceDiagram\n A->>B: hello\n deactivate A',
|
|
80
|
-
)
|
|
81
|
-
expect(report.remainingIssues).toEqual([
|
|
82
|
-
expect.objectContaining({
|
|
83
|
-
code: 'UNMATCHED_DEACTIVATION',
|
|
84
|
-
actorId: 'A',
|
|
85
|
-
}),
|
|
86
|
-
])
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('fixes the dangling activation while still reporting an unmatched one', () => {
|
|
90
|
-
const result = fixSequenceActivationsHandler({
|
|
91
|
-
diagram: 'sequenceDiagram\n activate A\n A->>B: hello\n deactivate B',
|
|
92
|
-
})
|
|
93
|
-
expect(result.isError).toBeUndefined()
|
|
94
|
-
const [content] = result.content
|
|
95
|
-
if (content?.type !== 'text') {
|
|
96
|
-
throw new Error('Expected text content')
|
|
97
|
-
}
|
|
98
|
-
const report = parseReport(content.text)
|
|
99
|
-
expect(report.ok).toBe(false)
|
|
100
|
-
expect(report.fixesApplied).toHaveLength(1)
|
|
101
|
-
expect(report.fixedDiagram).toContain('deactivate A')
|
|
102
|
-
expect(report.remainingIssues).toEqual([
|
|
103
|
-
expect.objectContaining({
|
|
104
|
-
code: 'UNMATCHED_DEACTIVATION',
|
|
105
|
-
actorId: 'B',
|
|
106
|
-
}),
|
|
107
|
-
])
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('rejects a non-sequence diagram with a clear error instead of a false report', () => {
|
|
111
|
-
const result = fixSequenceActivationsHandler({
|
|
112
|
-
diagram: 'graph LR\n A --> B',
|
|
113
|
-
})
|
|
114
|
-
expect(result.isError).toBe(true)
|
|
115
|
-
const [content] = result.content
|
|
116
|
-
if (content?.type !== 'text') {
|
|
117
|
-
throw new Error('Expected text content')
|
|
118
|
-
}
|
|
119
|
-
expect(content.text).toContain('only fixes sequence diagrams')
|
|
120
|
-
expect(content.text).toContain('"flowchart"')
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('returns an MCP tool error instead of throwing on invalid sequence syntax', () => {
|
|
124
|
-
const result = fixSequenceActivationsHandler({
|
|
125
|
-
diagram: 'sequenceDiagram\n box\n box',
|
|
126
|
-
})
|
|
127
|
-
expect(result.isError).toBe(true)
|
|
128
|
-
const [content] = result.content
|
|
129
|
-
if (content?.type !== 'text') {
|
|
130
|
-
throw new Error('Expected text content')
|
|
131
|
-
}
|
|
132
|
-
expect(content.text).toContain('Failed to fix diagram activations')
|
|
133
|
-
})
|
|
134
|
-
})
|