wyreframe 0.1.0 → 0.1.5

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.
Files changed (58) hide show
  1. package/LICENSE +692 -0
  2. package/README.md +65 -5
  3. package/package.json +8 -7
  4. package/src/index.ts +425 -0
  5. package/src/renderer/Renderer.gen.tsx +49 -0
  6. package/src/renderer/Renderer.mjs +41 -1
  7. package/src/renderer/Renderer.res +78 -0
  8. package/src/parser/Core/__tests__/Bounds_test.mjs +0 -326
  9. package/src/parser/Core/__tests__/Bounds_test.res +0 -412
  10. package/src/parser/Core/__tests__/Grid_test.mjs +0 -322
  11. package/src/parser/Core/__tests__/Grid_test.res +0 -319
  12. package/src/parser/Core/__tests__/Types_test.mjs +0 -614
  13. package/src/parser/Core/__tests__/Types_test.res +0 -650
  14. package/src/parser/Detector/__tests__/BoxTracer_test.mjs +0 -70
  15. package/src/parser/Detector/__tests__/BoxTracer_test.res +0 -92
  16. package/src/parser/Detector/__tests__/HierarchyBuilder_test.mjs +0 -489
  17. package/src/parser/Detector/__tests__/HierarchyBuilder_test.res +0 -849
  18. package/src/parser/Detector/__tests__/ShapeDetector_test.mjs +0 -377
  19. package/src/parser/Detector/__tests__/ShapeDetector_test.res +0 -563
  20. package/src/parser/Interactions/__tests__/InteractionMerger_test.mjs +0 -576
  21. package/src/parser/Interactions/__tests__/InteractionMerger_test.res +0 -646
  22. package/src/parser/Scanner/__tests__/Grid_manual.mjs +0 -214
  23. package/src/parser/Scanner/__tests__/Grid_manual.res +0 -141
  24. package/src/parser/Semantic/Elements/__tests__/ButtonParser_test.mjs +0 -189
  25. package/src/parser/Semantic/Elements/__tests__/ButtonParser_test.res +0 -257
  26. package/src/parser/Semantic/Elements/__tests__/CheckboxParser_test.mjs +0 -202
  27. package/src/parser/Semantic/Elements/__tests__/CheckboxParser_test.res +0 -250
  28. package/src/parser/Semantic/Elements/__tests__/CodeTextParser_manual.mjs +0 -293
  29. package/src/parser/Semantic/Elements/__tests__/CodeTextParser_manual.res +0 -134
  30. package/src/parser/Semantic/Elements/__tests__/InputParser_test.mjs +0 -253
  31. package/src/parser/Semantic/Elements/__tests__/InputParser_test.res +0 -304
  32. package/src/parser/Semantic/Elements/__tests__/LinkParser_test.mjs +0 -289
  33. package/src/parser/Semantic/Elements/__tests__/LinkParser_test.res +0 -402
  34. package/src/parser/Semantic/Elements/__tests__/TextParser_test.mjs +0 -149
  35. package/src/parser/Semantic/Elements/__tests__/TextParser_test.res +0 -167
  36. package/src/parser/Semantic/__tests__/ASTBuilder_test.mjs +0 -187
  37. package/src/parser/Semantic/__tests__/ASTBuilder_test.res +0 -192
  38. package/src/parser/Semantic/__tests__/ParserRegistry_test.mjs +0 -154
  39. package/src/parser/Semantic/__tests__/ParserRegistry_test.res +0 -191
  40. package/src/parser/Semantic/__tests__/SemanticParser_integration_test.mjs +0 -768
  41. package/src/parser/Semantic/__tests__/SemanticParser_integration_test.res +0 -1069
  42. package/src/parser/Semantic/__tests__/SemanticParser_manual.mjs +0 -1329
  43. package/src/parser/Semantic/__tests__/SemanticParser_manual.res +0 -544
  44. package/src/parser/__tests__/GridScanner_integration.test.mjs +0 -632
  45. package/src/parser/__tests__/GridScanner_integration.test.res +0 -816
  46. package/src/parser/__tests__/Performance.test.mjs +0 -244
  47. package/src/parser/__tests__/Performance.test.res +0 -371
  48. package/src/parser/__tests__/PerformanceFixtures.mjs +0 -200
  49. package/src/parser/__tests__/PerformanceFixtures.res +0 -284
  50. package/src/parser/__tests__/WyreframeParser_integration.test.mjs +0 -770
  51. package/src/parser/__tests__/WyreframeParser_integration.test.res +0 -1008
  52. package/src/parser/__tests__/fixtures/alignment-test.txt +0 -9
  53. package/src/parser/__tests__/fixtures/all-elements.txt +0 -16
  54. package/src/parser/__tests__/fixtures/login-scene.txt +0 -17
  55. package/src/parser/__tests__/fixtures/multi-scene.txt +0 -25
  56. package/src/parser/__tests__/fixtures/nested-boxes.txt +0 -15
  57. package/src/parser/__tests__/fixtures/simple-box.txt +0 -5
  58. package/src/parser/__tests__/fixtures/with-dividers.txt +0 -14
@@ -1,1329 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Grid from "../../Core/Grid.mjs";
4
- import * as Belt_Option from "@rescript/runtime/lib/es6/Belt_Option.js";
5
- import * as SemanticParser from "../SemanticParser.mjs";
6
-
7
- let makeTestGrid = Grid.fromLines;
8
-
9
- function makeTestBox(top, left, bottom, right) {
10
- return {
11
- name: undefined,
12
- bounds: {
13
- top: top,
14
- left: left,
15
- bottom: bottom,
16
- right: right
17
- },
18
- children: []
19
- };
20
- }
21
-
22
- function test_extractContentLines_simpleBox() {
23
- let grid = Grid.fromLines([
24
- "+-------+",
25
- "| Hello |",
26
- "+-------+"
27
- ]);
28
- let box_bounds = {
29
- top: 0,
30
- left: 0,
31
- bottom: 2,
32
- right: 8
33
- };
34
- let box_children = [];
35
- let box = {
36
- name: undefined,
37
- bounds: box_bounds,
38
- children: box_children
39
- };
40
- let content = SemanticParser.extractContentLines(box, grid.cells);
41
- if (content.length !== 1) {
42
- throw {
43
- RE_EXN_ID: "Assert_failure",
44
- _1: [
45
- "SemanticParser_manual.res",
46
- 32,
47
- 2
48
- ],
49
- Error: new Error()
50
- };
51
- }
52
- if (content[0] === " Hello ") {
53
- return;
54
- }
55
- throw {
56
- RE_EXN_ID: "Assert_failure",
57
- _1: [
58
- "SemanticParser_manual.res",
59
- 33,
60
- 2
61
- ],
62
- Error: new Error()
63
- };
64
- }
65
-
66
- function test_extractContentLines_multipleLines() {
67
- let grid = Grid.fromLines([
68
- "+--Login--+",
69
- "| #email |",
70
- "| [Submit]|",
71
- "+----------+"
72
- ]);
73
- let box_bounds = {
74
- top: 0,
75
- left: 0,
76
- bottom: 3,
77
- right: 10
78
- };
79
- let box_children = [];
80
- let box = {
81
- name: undefined,
82
- bounds: box_bounds,
83
- children: box_children
84
- };
85
- let content = SemanticParser.extractContentLines(box, grid.cells);
86
- if (content.length !== 2) {
87
- throw {
88
- RE_EXN_ID: "Assert_failure",
89
- _1: [
90
- "SemanticParser_manual.res",
91
- 49,
92
- 2
93
- ],
94
- Error: new Error()
95
- };
96
- }
97
- if (content[0] !== " #email ") {
98
- throw {
99
- RE_EXN_ID: "Assert_failure",
100
- _1: [
101
- "SemanticParser_manual.res",
102
- 50,
103
- 2
104
- ],
105
- Error: new Error()
106
- };
107
- }
108
- if (content[1] === " [Submit]") {
109
- return;
110
- }
111
- throw {
112
- RE_EXN_ID: "Assert_failure",
113
- _1: [
114
- "SemanticParser_manual.res",
115
- 51,
116
- 2
117
- ],
118
- Error: new Error()
119
- };
120
- }
121
-
122
- function test_extractContentLines_preserveWhitespace() {
123
- let grid = Grid.fromLines([
124
- "+---------+",
125
- "| a b |",
126
- "+---------+"
127
- ]);
128
- let box_bounds = {
129
- top: 0,
130
- left: 0,
131
- bottom: 2,
132
- right: 10
133
- };
134
- let box_children = [];
135
- let box = {
136
- name: undefined,
137
- bounds: box_bounds,
138
- children: box_children
139
- };
140
- let content = SemanticParser.extractContentLines(box, grid.cells);
141
- if (content.length !== 1) {
142
- throw {
143
- RE_EXN_ID: "Assert_failure",
144
- _1: [
145
- "SemanticParser_manual.res",
146
- 66,
147
- 2
148
- ],
149
- Error: new Error()
150
- };
151
- }
152
- if (content[0] === " a b ") {
153
- return;
154
- }
155
- throw {
156
- RE_EXN_ID: "Assert_failure",
157
- _1: [
158
- "SemanticParser_manual.res",
159
- 67,
160
- 2
161
- ],
162
- Error: new Error()
163
- };
164
- }
165
-
166
- function test_extractContentLines_emptyBox() {
167
- let grid = Grid.fromLines([
168
- "+---+",
169
- "+---+"
170
- ]);
171
- let box_bounds = {
172
- top: 0,
173
- left: 0,
174
- bottom: 1,
175
- right: 4
176
- };
177
- let box_children = [];
178
- let box = {
179
- name: undefined,
180
- bounds: box_bounds,
181
- children: box_children
182
- };
183
- let content = SemanticParser.extractContentLines(box, grid.cells);
184
- if (content.length === 0) {
185
- return;
186
- }
187
- throw {
188
- RE_EXN_ID: "Assert_failure",
189
- _1: [
190
- "SemanticParser_manual.res",
191
- 81,
192
- 2
193
- ],
194
- Error: new Error()
195
- };
196
- }
197
-
198
- function test_extractContentLines_withDivider() {
199
- let grid = Grid.fromLines([
200
- "+------+",
201
- "| Head |",
202
- "|======|",
203
- "| Body |",
204
- "+------+"
205
- ]);
206
- let box_bounds = {
207
- top: 0,
208
- left: 0,
209
- bottom: 4,
210
- right: 7
211
- };
212
- let box_children = [];
213
- let box = {
214
- name: undefined,
215
- bounds: box_bounds,
216
- children: box_children
217
- };
218
- let content = SemanticParser.extractContentLines(box, grid.cells);
219
- if (content.length !== 3) {
220
- throw {
221
- RE_EXN_ID: "Assert_failure",
222
- _1: [
223
- "SemanticParser_manual.res",
224
- 98,
225
- 2
226
- ],
227
- Error: new Error()
228
- };
229
- }
230
- if (content[0] !== " Head ") {
231
- throw {
232
- RE_EXN_ID: "Assert_failure",
233
- _1: [
234
- "SemanticParser_manual.res",
235
- 99,
236
- 2
237
- ],
238
- Error: new Error()
239
- };
240
- }
241
- if (content[1] !== "======") {
242
- throw {
243
- RE_EXN_ID: "Assert_failure",
244
- _1: [
245
- "SemanticParser_manual.res",
246
- 100,
247
- 2
248
- ],
249
- Error: new Error()
250
- };
251
- }
252
- if (content[2] === " Body ") {
253
- return;
254
- }
255
- throw {
256
- RE_EXN_ID: "Assert_failure",
257
- _1: [
258
- "SemanticParser_manual.res",
259
- 101,
260
- 2
261
- ],
262
- Error: new Error()
263
- };
264
- }
265
-
266
- function test_extractContentLines_withEmptyLines() {
267
- let grid = Grid.fromLines([
268
- "+-----+",
269
- "| Top |",
270
- "| |",
271
- "| Bot |",
272
- "+-----+"
273
- ]);
274
- let box_bounds = {
275
- top: 0,
276
- left: 0,
277
- bottom: 4,
278
- right: 6
279
- };
280
- let box_children = [];
281
- let box = {
282
- name: undefined,
283
- bounds: box_bounds,
284
- children: box_children
285
- };
286
- let content = SemanticParser.extractContentLines(box, grid.cells);
287
- if (content.length !== 3) {
288
- throw {
289
- RE_EXN_ID: "Assert_failure",
290
- _1: [
291
- "SemanticParser_manual.res",
292
- 118,
293
- 2
294
- ],
295
- Error: new Error()
296
- };
297
- }
298
- if (content[0] !== " Top ") {
299
- throw {
300
- RE_EXN_ID: "Assert_failure",
301
- _1: [
302
- "SemanticParser_manual.res",
303
- 119,
304
- 2
305
- ],
306
- Error: new Error()
307
- };
308
- }
309
- if (content[1] !== " ") {
310
- throw {
311
- RE_EXN_ID: "Assert_failure",
312
- _1: [
313
- "SemanticParser_manual.res",
314
- 120,
315
- 2
316
- ],
317
- Error: new Error()
318
- };
319
- }
320
- if (content[2] === " Bot ") {
321
- return;
322
- }
323
- throw {
324
- RE_EXN_ID: "Assert_failure",
325
- _1: [
326
- "SemanticParser_manual.res",
327
- 121,
328
- 2
329
- ],
330
- Error: new Error()
331
- };
332
- }
333
-
334
- function test_extractContentLines_nestedBox() {
335
- let grid = Grid.fromLines([
336
- "+-----------+",
337
- "| +-------+ |",
338
- "| | Inner | |",
339
- "| +-------+ |",
340
- "+-----------+"
341
- ]);
342
- let innerBox_bounds = {
343
- top: 1,
344
- left: 2,
345
- bottom: 3,
346
- right: 9
347
- };
348
- let innerBox_children = [];
349
- let innerBox = {
350
- name: undefined,
351
- bounds: innerBox_bounds,
352
- children: innerBox_children
353
- };
354
- let innerContent = SemanticParser.extractContentLines(innerBox, grid.cells);
355
- if (innerContent.length !== 1) {
356
- throw {
357
- RE_EXN_ID: "Assert_failure",
358
- _1: [
359
- "SemanticParser_manual.res",
360
- 139,
361
- 2
362
- ],
363
- Error: new Error()
364
- };
365
- }
366
- if (innerContent[0] !== " Inner ") {
367
- throw {
368
- RE_EXN_ID: "Assert_failure",
369
- _1: [
370
- "SemanticParser_manual.res",
371
- 140,
372
- 2
373
- ],
374
- Error: new Error()
375
- };
376
- }
377
- let outerBox_bounds = {
378
- top: 0,
379
- left: 0,
380
- bottom: 4,
381
- right: 12
382
- };
383
- let outerBox_children = [];
384
- let outerBox = {
385
- name: undefined,
386
- bounds: outerBox_bounds,
387
- children: outerBox_children
388
- };
389
- let outerContent = SemanticParser.extractContentLines(outerBox, grid.cells);
390
- if (outerContent.length !== 3) {
391
- throw {
392
- RE_EXN_ID: "Assert_failure",
393
- _1: [
394
- "SemanticParser_manual.res",
395
- 147,
396
- 2
397
- ],
398
- Error: new Error()
399
- };
400
- }
401
- if (outerContent[0].includes("+-------+")) {
402
- return;
403
- }
404
- throw {
405
- RE_EXN_ID: "Assert_failure",
406
- _1: [
407
- "SemanticParser_manual.res",
408
- 148,
409
- 2
410
- ],
411
- Error: new Error()
412
- };
413
- }
414
-
415
- function test_extractContentLines_specialChars() {
416
- let grid = Grid.fromLines([
417
- "+--------+",
418
- "| a|b-c+ |",
419
- "+--------+"
420
- ]);
421
- let box_bounds = {
422
- top: 0,
423
- left: 0,
424
- bottom: 2,
425
- right: 9
426
- };
427
- let box_children = [];
428
- let box = {
429
- name: undefined,
430
- bounds: box_bounds,
431
- children: box_children
432
- };
433
- let content = SemanticParser.extractContentLines(box, grid.cells);
434
- if (content.length !== 1) {
435
- throw {
436
- RE_EXN_ID: "Assert_failure",
437
- _1: [
438
- "SemanticParser_manual.res",
439
- 163,
440
- 2
441
- ],
442
- Error: new Error()
443
- };
444
- }
445
- if (content[0] === " a|b-c+ ") {
446
- return;
447
- }
448
- throw {
449
- RE_EXN_ID: "Assert_failure",
450
- _1: [
451
- "SemanticParser_manual.res",
452
- 164,
453
- 2
454
- ],
455
- Error: new Error()
456
- };
457
- }
458
-
459
- function test_hasContent_nonEmpty() {
460
- let grid = Grid.fromLines([
461
- "+-----+",
462
- "| Txt |",
463
- "+-----+"
464
- ]);
465
- let box_bounds = {
466
- top: 0,
467
- left: 0,
468
- bottom: 2,
469
- right: 6
470
- };
471
- let box_children = [];
472
- let box = {
473
- name: undefined,
474
- bounds: box_bounds,
475
- children: box_children
476
- };
477
- if (SemanticParser.hasContent(box, grid) === true) {
478
- return;
479
- }
480
- throw {
481
- RE_EXN_ID: "Assert_failure",
482
- _1: [
483
- "SemanticParser_manual.res",
484
- 178,
485
- 2
486
- ],
487
- Error: new Error()
488
- };
489
- }
490
-
491
- function test_hasContent_empty() {
492
- let grid = Grid.fromLines([
493
- "+-----+",
494
- "| |",
495
- "+-----+"
496
- ]);
497
- let box_bounds = {
498
- top: 0,
499
- left: 0,
500
- bottom: 2,
501
- right: 6
502
- };
503
- let box_children = [];
504
- let box = {
505
- name: undefined,
506
- bounds: box_bounds,
507
- children: box_children
508
- };
509
- if (SemanticParser.hasContent(box, grid) === false) {
510
- return;
511
- }
512
- throw {
513
- RE_EXN_ID: "Assert_failure",
514
- _1: [
515
- "SemanticParser_manual.res",
516
- 190,
517
- 2
518
- ],
519
- Error: new Error()
520
- };
521
- }
522
-
523
- function test_getContentLineCount() {
524
- let grid = Grid.fromLines([
525
- "+-----+",
526
- "| L1 |",
527
- "| L2 |",
528
- "| L3 |",
529
- "+-----+"
530
- ]);
531
- let box_bounds = {
532
- top: 0,
533
- left: 0,
534
- bottom: 4,
535
- right: 6
536
- };
537
- let box_children = [];
538
- let box = {
539
- name: undefined,
540
- bounds: box_bounds,
541
- children: box_children
542
- };
543
- if (SemanticParser.getContentLineCount(box, grid) === 3) {
544
- return;
545
- }
546
- throw {
547
- RE_EXN_ID: "Assert_failure",
548
- _1: [
549
- "SemanticParser_manual.res",
550
- 204,
551
- 2
552
- ],
553
- Error: new Error()
554
- };
555
- }
556
-
557
- function test_parseSceneDirectives_scene() {
558
- let lines = [
559
- "@scene: login",
560
- "+--Box--+",
561
- "| |",
562
- "+-------+"
563
- ];
564
- let match = SemanticParser.parseSceneDirectives(lines);
565
- let metadata = match[0];
566
- if (metadata.id !== "login") {
567
- throw {
568
- RE_EXN_ID: "Assert_failure",
569
- _1: [
570
- "SemanticParser_manual.res",
571
- 216,
572
- 2
573
- ],
574
- Error: new Error()
575
- };
576
- }
577
- if (metadata.title !== "login") {
578
- throw {
579
- RE_EXN_ID: "Assert_failure",
580
- _1: [
581
- "SemanticParser_manual.res",
582
- 217,
583
- 2
584
- ],
585
- Error: new Error()
586
- };
587
- }
588
- if (metadata.transition !== "fade") {
589
- throw {
590
- RE_EXN_ID: "Assert_failure",
591
- _1: [
592
- "SemanticParser_manual.res",
593
- 218,
594
- 2
595
- ],
596
- Error: new Error()
597
- };
598
- }
599
- if (match[1].length === 3) {
600
- return;
601
- }
602
- throw {
603
- RE_EXN_ID: "Assert_failure",
604
- _1: [
605
- "SemanticParser_manual.res",
606
- 219,
607
- 2
608
- ],
609
- Error: new Error()
610
- };
611
- }
612
-
613
- function test_parseSceneDirectives_title() {
614
- let lines = [
615
- "@scene: login",
616
- "@title: Login Page",
617
- "+--Box--+"
618
- ];
619
- let match = SemanticParser.parseSceneDirectives(lines);
620
- let metadata = match[0];
621
- if (metadata.id !== "login") {
622
- throw {
623
- RE_EXN_ID: "Assert_failure",
624
- _1: [
625
- "SemanticParser_manual.res",
626
- 227,
627
- 2
628
- ],
629
- Error: new Error()
630
- };
631
- }
632
- if (metadata.title === "Login Page") {
633
- return;
634
- }
635
- throw {
636
- RE_EXN_ID: "Assert_failure",
637
- _1: [
638
- "SemanticParser_manual.res",
639
- 228,
640
- 2
641
- ],
642
- Error: new Error()
643
- };
644
- }
645
-
646
- function test_parseSceneDirectives_titleQuotes() {
647
- let lines = [
648
- "@scene: login",
649
- "@title: \"Login Page\"",
650
- "+--Box--+"
651
- ];
652
- let match = SemanticParser.parseSceneDirectives(lines);
653
- if (match[0].title === "Login Page") {
654
- return;
655
- }
656
- throw {
657
- RE_EXN_ID: "Assert_failure",
658
- _1: [
659
- "SemanticParser_manual.res",
660
- 236,
661
- 2
662
- ],
663
- Error: new Error()
664
- };
665
- }
666
-
667
- function test_parseSceneDirectives_transition() {
668
- let lines = [
669
- "@scene: login",
670
- "@transition: slide",
671
- "+--Box--+"
672
- ];
673
- let match = SemanticParser.parseSceneDirectives(lines);
674
- if (match[0].transition === "slide") {
675
- return;
676
- }
677
- throw {
678
- RE_EXN_ID: "Assert_failure",
679
- _1: [
680
- "SemanticParser_manual.res",
681
- 244,
682
- 2
683
- ],
684
- Error: new Error()
685
- };
686
- }
687
-
688
- function test_parseSceneDirectives_allDirectives() {
689
- let lines = [
690
- "@scene: login",
691
- "@title: Login Page",
692
- "@transition: slide",
693
- "",
694
- "+--Login--+",
695
- "| #email |",
696
- "+----------+"
697
- ];
698
- let match = SemanticParser.parseSceneDirectives(lines);
699
- let metadata = match[0];
700
- if (metadata.id !== "login") {
701
- throw {
702
- RE_EXN_ID: "Assert_failure",
703
- _1: [
704
- "SemanticParser_manual.res",
705
- 260,
706
- 2
707
- ],
708
- Error: new Error()
709
- };
710
- }
711
- if (metadata.title !== "Login Page") {
712
- throw {
713
- RE_EXN_ID: "Assert_failure",
714
- _1: [
715
- "SemanticParser_manual.res",
716
- 261,
717
- 2
718
- ],
719
- Error: new Error()
720
- };
721
- }
722
- if (metadata.transition !== "slide") {
723
- throw {
724
- RE_EXN_ID: "Assert_failure",
725
- _1: [
726
- "SemanticParser_manual.res",
727
- 262,
728
- 2
729
- ],
730
- Error: new Error()
731
- };
732
- }
733
- if (match[1].length === 4) {
734
- return;
735
- }
736
- throw {
737
- RE_EXN_ID: "Assert_failure",
738
- _1: [
739
- "SemanticParser_manual.res",
740
- 263,
741
- 2
742
- ],
743
- Error: new Error()
744
- };
745
- }
746
-
747
- function test_parseSceneDirectives_defaults() {
748
- let lines = [
749
- "+--Box--+",
750
- "| |",
751
- "+-------+"
752
- ];
753
- let match = SemanticParser.parseSceneDirectives(lines);
754
- let metadata = match[0];
755
- if (metadata.id !== "main") {
756
- throw {
757
- RE_EXN_ID: "Assert_failure",
758
- _1: [
759
- "SemanticParser_manual.res",
760
- 271,
761
- 2
762
- ],
763
- Error: new Error()
764
- };
765
- }
766
- if (metadata.title !== "main") {
767
- throw {
768
- RE_EXN_ID: "Assert_failure",
769
- _1: [
770
- "SemanticParser_manual.res",
771
- 272,
772
- 2
773
- ],
774
- Error: new Error()
775
- };
776
- }
777
- if (metadata.transition === "fade") {
778
- return;
779
- }
780
- throw {
781
- RE_EXN_ID: "Assert_failure",
782
- _1: [
783
- "SemanticParser_manual.res",
784
- 273,
785
- 2
786
- ],
787
- Error: new Error()
788
- };
789
- }
790
-
791
- function test_parseSceneDirectives_unknownDirectives() {
792
- let lines = [
793
- "@scene: login",
794
- "@unknown: something",
795
- "@custom: value",
796
- "+--Box--+"
797
- ];
798
- let match = SemanticParser.parseSceneDirectives(lines);
799
- if (match[0].id !== "login") {
800
- throw {
801
- RE_EXN_ID: "Assert_failure",
802
- _1: [
803
- "SemanticParser_manual.res",
804
- 281,
805
- 2
806
- ],
807
- Error: new Error()
808
- };
809
- }
810
- if (match[1].length === 1) {
811
- return;
812
- }
813
- throw {
814
- RE_EXN_ID: "Assert_failure",
815
- _1: [
816
- "SemanticParser_manual.res",
817
- 282,
818
- 2
819
- ],
820
- Error: new Error()
821
- };
822
- }
823
-
824
- function test_splitSceneBlocks_dashedSeparator() {
825
- let blocks = SemanticParser.splitSceneBlocks(`@scene: login
826
- +--Login--+
827
-
828
- ---
829
-
830
- @scene: home
831
- +--Home--+`);
832
- if (blocks.length !== 2) {
833
- throw {
834
- RE_EXN_ID: "Assert_failure",
835
- _1: [
836
- "SemanticParser_manual.res",
837
- 297,
838
- 2
839
- ],
840
- Error: new Error()
841
- };
842
- }
843
- if (!Belt_Option.getExn(blocks[0]).includes("@scene: login")) {
844
- throw {
845
- RE_EXN_ID: "Assert_failure",
846
- _1: [
847
- "SemanticParser_manual.res",
848
- 298,
849
- 2
850
- ],
851
- Error: new Error()
852
- };
853
- }
854
- if (Belt_Option.getExn(blocks[1]).includes("@scene: home")) {
855
- return;
856
- }
857
- throw {
858
- RE_EXN_ID: "Assert_failure",
859
- _1: [
860
- "SemanticParser_manual.res",
861
- 299,
862
- 2
863
- ],
864
- Error: new Error()
865
- };
866
- }
867
-
868
- function test_splitSceneBlocks_sceneDirectiveSeparator() {
869
- let blocks = SemanticParser.splitSceneBlocks(`@scene: login
870
- +--Login--+
871
- @scene: home
872
- +--Home--+`);
873
- if (blocks.length === 2) {
874
- return;
875
- }
876
- throw {
877
- RE_EXN_ID: "Assert_failure",
878
- _1: [
879
- "SemanticParser_manual.res",
880
- 311,
881
- 2
882
- ],
883
- Error: new Error()
884
- };
885
- }
886
-
887
- function test_splitSceneBlocks_singleScene() {
888
- let blocks = SemanticParser.splitSceneBlocks(`@scene: login
889
- +--Login--+
890
- | #email |
891
- +----------+`);
892
- if (blocks.length === 1) {
893
- return;
894
- }
895
- throw {
896
- RE_EXN_ID: "Assert_failure",
897
- _1: [
898
- "SemanticParser_manual.res",
899
- 323,
900
- 2
901
- ],
902
- Error: new Error()
903
- };
904
- }
905
-
906
- function test_splitSceneBlocks_filtersEmpty() {
907
- let blocks = SemanticParser.splitSceneBlocks(`
908
-
909
- ---
910
-
911
- @scene: login
912
- +--Box--+
913
-
914
- ---
915
-
916
- `);
917
- if (blocks.length === 1) {
918
- return;
919
- }
920
- throw {
921
- RE_EXN_ID: "Assert_failure",
922
- _1: [
923
- "SemanticParser_manual.res",
924
- 341,
925
- 2
926
- ],
927
- Error: new Error()
928
- };
929
- }
930
-
931
- function test_groupContentByScenes_simple() {
932
- let scenes = SemanticParser.groupContentByScenes(`@scene: login
933
- @title: Login Page
934
- @transition: slide
935
-
936
- +--Login--+
937
- | #email |
938
- +----------+`);
939
- if (scenes.length !== 1) {
940
- throw {
941
- RE_EXN_ID: "Assert_failure",
942
- _1: [
943
- "SemanticParser_manual.res",
944
- 356,
945
- 2
946
- ],
947
- Error: new Error()
948
- };
949
- }
950
- let match = Belt_Option.getExn(scenes[0]);
951
- let metadata = match[0];
952
- if (metadata.id !== "login") {
953
- throw {
954
- RE_EXN_ID: "Assert_failure",
955
- _1: [
956
- "SemanticParser_manual.res",
957
- 359,
958
- 2
959
- ],
960
- Error: new Error()
961
- };
962
- }
963
- if (metadata.title !== "Login Page") {
964
- throw {
965
- RE_EXN_ID: "Assert_failure",
966
- _1: [
967
- "SemanticParser_manual.res",
968
- 360,
969
- 2
970
- ],
971
- Error: new Error()
972
- };
973
- }
974
- if (metadata.transition !== "slide") {
975
- throw {
976
- RE_EXN_ID: "Assert_failure",
977
- _1: [
978
- "SemanticParser_manual.res",
979
- 361,
980
- 2
981
- ],
982
- Error: new Error()
983
- };
984
- }
985
- if (match[1].length > 0) {
986
- return;
987
- }
988
- throw {
989
- RE_EXN_ID: "Assert_failure",
990
- _1: [
991
- "SemanticParser_manual.res",
992
- 362,
993
- 2
994
- ],
995
- Error: new Error()
996
- };
997
- }
998
-
999
- function test_groupContentByScenes_multiple() {
1000
- let scenes = SemanticParser.groupContentByScenes(`@scene: login
1001
- +--Login--+
1002
-
1003
- ---
1004
-
1005
- @scene: home
1006
- +--Home--+
1007
-
1008
- ---
1009
-
1010
- @scene: settings
1011
- +--Settings--+`);
1012
- if (scenes.length !== 3) {
1013
- throw {
1014
- RE_EXN_ID: "Assert_failure",
1015
- _1: [
1016
- "SemanticParser_manual.res",
1017
- 382,
1018
- 2
1019
- ],
1020
- Error: new Error()
1021
- };
1022
- }
1023
- let match = Belt_Option.getExn(scenes[0]);
1024
- let match$1 = Belt_Option.getExn(scenes[1]);
1025
- let match$2 = Belt_Option.getExn(scenes[2]);
1026
- if (match[0].id !== "login") {
1027
- throw {
1028
- RE_EXN_ID: "Assert_failure",
1029
- _1: [
1030
- "SemanticParser_manual.res",
1031
- 388,
1032
- 2
1033
- ],
1034
- Error: new Error()
1035
- };
1036
- }
1037
- if (match$1[0].id !== "home") {
1038
- throw {
1039
- RE_EXN_ID: "Assert_failure",
1040
- _1: [
1041
- "SemanticParser_manual.res",
1042
- 389,
1043
- 2
1044
- ],
1045
- Error: new Error()
1046
- };
1047
- }
1048
- if (match$2[0].id === "settings") {
1049
- return;
1050
- }
1051
- throw {
1052
- RE_EXN_ID: "Assert_failure",
1053
- _1: [
1054
- "SemanticParser_manual.res",
1055
- 390,
1056
- 2
1057
- ],
1058
- Error: new Error()
1059
- };
1060
- }
1061
-
1062
- function test_groupContentByScenes_default() {
1063
- let scenes = SemanticParser.groupContentByScenes(`+--Box--+
1064
- | Text |
1065
- +-------+`);
1066
- if (scenes.length !== 1) {
1067
- throw {
1068
- RE_EXN_ID: "Assert_failure",
1069
- _1: [
1070
- "SemanticParser_manual.res",
1071
- 401,
1072
- 2
1073
- ],
1074
- Error: new Error()
1075
- };
1076
- }
1077
- let match = Belt_Option.getExn(scenes[0]);
1078
- let metadata = match[0];
1079
- if (metadata.id !== "main") {
1080
- throw {
1081
- RE_EXN_ID: "Assert_failure",
1082
- _1: [
1083
- "SemanticParser_manual.res",
1084
- 404,
1085
- 2
1086
- ],
1087
- Error: new Error()
1088
- };
1089
- }
1090
- if (metadata.title !== "main") {
1091
- throw {
1092
- RE_EXN_ID: "Assert_failure",
1093
- _1: [
1094
- "SemanticParser_manual.res",
1095
- 405,
1096
- 2
1097
- ],
1098
- Error: new Error()
1099
- };
1100
- }
1101
- if (metadata.transition === "fade") {
1102
- return;
1103
- }
1104
- throw {
1105
- RE_EXN_ID: "Assert_failure",
1106
- _1: [
1107
- "SemanticParser_manual.res",
1108
- 406,
1109
- 2
1110
- ],
1111
- Error: new Error()
1112
- };
1113
- }
1114
-
1115
- function test_groupContentByScenes_empty() {
1116
- let scenes = SemanticParser.groupContentByScenes("");
1117
- if (scenes.length === 0) {
1118
- return;
1119
- }
1120
- throw {
1121
- RE_EXN_ID: "Assert_failure",
1122
- _1: [
1123
- "SemanticParser_manual.res",
1124
- 414,
1125
- 2
1126
- ],
1127
- Error: new Error()
1128
- };
1129
- }
1130
-
1131
- function test_groupContentByScenes_complex() {
1132
- let scenes = SemanticParser.groupContentByScenes(`@scene: login
1133
- @title: "Login Page"
1134
-
1135
- +--Login----------------+
1136
- | * WYREFRAME |
1137
- | |
1138
- | #email |
1139
- | #password |
1140
- | |
1141
- | [ Login ] |
1142
- +----------------------+
1143
-
1144
- ---
1145
-
1146
- @scene: home
1147
- @transition: slide
1148
-
1149
- +--Home-----------------+
1150
- | Welcome! |
1151
- +----------------------+`);
1152
- if (scenes.length !== 2) {
1153
- throw {
1154
- RE_EXN_ID: "Assert_failure",
1155
- _1: [
1156
- "SemanticParser_manual.res",
1157
- 442,
1158
- 2
1159
- ],
1160
- Error: new Error()
1161
- };
1162
- }
1163
- let match = Belt_Option.getExn(scenes[0]);
1164
- let loginMeta = match[0];
1165
- if (loginMeta.id !== "login") {
1166
- throw {
1167
- RE_EXN_ID: "Assert_failure",
1168
- _1: [
1169
- "SemanticParser_manual.res",
1170
- 445,
1171
- 2
1172
- ],
1173
- Error: new Error()
1174
- };
1175
- }
1176
- if (loginMeta.title !== "Login Page") {
1177
- throw {
1178
- RE_EXN_ID: "Assert_failure",
1179
- _1: [
1180
- "SemanticParser_manual.res",
1181
- 446,
1182
- 2
1183
- ],
1184
- Error: new Error()
1185
- };
1186
- }
1187
- if (!match[1].join("\n").includes("#email")) {
1188
- throw {
1189
- RE_EXN_ID: "Assert_failure",
1190
- _1: [
1191
- "SemanticParser_manual.res",
1192
- 447,
1193
- 2
1194
- ],
1195
- Error: new Error()
1196
- };
1197
- }
1198
- let match$1 = Belt_Option.getExn(scenes[1]);
1199
- let homeMeta = match$1[0];
1200
- if (homeMeta.id !== "home") {
1201
- throw {
1202
- RE_EXN_ID: "Assert_failure",
1203
- _1: [
1204
- "SemanticParser_manual.res",
1205
- 450,
1206
- 2
1207
- ],
1208
- Error: new Error()
1209
- };
1210
- }
1211
- if (homeMeta.transition !== "slide") {
1212
- throw {
1213
- RE_EXN_ID: "Assert_failure",
1214
- _1: [
1215
- "SemanticParser_manual.res",
1216
- 451,
1217
- 2
1218
- ],
1219
- Error: new Error()
1220
- };
1221
- }
1222
- if (match$1[1].join("\n").includes("Welcome!")) {
1223
- return;
1224
- }
1225
- throw {
1226
- RE_EXN_ID: "Assert_failure",
1227
- _1: [
1228
- "SemanticParser_manual.res",
1229
- 452,
1230
- 2
1231
- ],
1232
- Error: new Error()
1233
- };
1234
- }
1235
-
1236
- function runTests() {
1237
- console.log("Running SemanticParser tests...");
1238
- console.log("\n=== Box Content Extraction ===");
1239
- test_extractContentLines_simpleBox();
1240
- console.log("✓ Simple box content extraction");
1241
- test_extractContentLines_multipleLines();
1242
- console.log("✓ Multiple lines extraction");
1243
- test_extractContentLines_preserveWhitespace();
1244
- console.log("✓ Whitespace preservation");
1245
- test_extractContentLines_emptyBox();
1246
- console.log("✓ Empty box handling");
1247
- test_extractContentLines_withDivider();
1248
- console.log("✓ Box with divider");
1249
- test_extractContentLines_withEmptyLines();
1250
- console.log("✓ Box with empty lines");
1251
- test_extractContentLines_nestedBox();
1252
- console.log("✓ Nested box content");
1253
- test_extractContentLines_specialChars();
1254
- console.log("✓ Special characters in content");
1255
- test_hasContent_nonEmpty();
1256
- console.log("✓ hasContent (non-empty)");
1257
- test_hasContent_empty();
1258
- console.log("✓ hasContent (empty)");
1259
- test_getContentLineCount();
1260
- console.log("✓ getContentLineCount");
1261
- console.log("\n=== Scene Directive Parsing ===");
1262
- test_parseSceneDirectives_scene();
1263
- console.log("✓ Parse @scene directive");
1264
- test_parseSceneDirectives_title();
1265
- console.log("✓ Parse @title directive");
1266
- test_parseSceneDirectives_titleQuotes();
1267
- console.log("✓ Remove quotes from @title");
1268
- test_parseSceneDirectives_transition();
1269
- console.log("✓ Parse @transition directive");
1270
- test_parseSceneDirectives_allDirectives();
1271
- console.log("✓ Parse all directives together");
1272
- test_parseSceneDirectives_defaults();
1273
- console.log("✓ Default metadata values");
1274
- test_parseSceneDirectives_unknownDirectives();
1275
- console.log("✓ Ignore unknown directives");
1276
- test_splitSceneBlocks_dashedSeparator();
1277
- console.log("✓ Split scenes by --- separator");
1278
- test_splitSceneBlocks_sceneDirectiveSeparator();
1279
- console.log("✓ Split scenes by @scene directive");
1280
- test_splitSceneBlocks_singleScene();
1281
- console.log("✓ Handle single scene");
1282
- test_splitSceneBlocks_filtersEmpty();
1283
- console.log("✓ Filter empty blocks");
1284
- test_groupContentByScenes_simple();
1285
- console.log("✓ Group simple scene with directives");
1286
- test_groupContentByScenes_multiple();
1287
- console.log("✓ Group multiple scenes");
1288
- test_groupContentByScenes_default();
1289
- console.log("✓ Create default scene");
1290
- test_groupContentByScenes_empty();
1291
- console.log("✓ Handle empty input");
1292
- test_groupContentByScenes_complex();
1293
- console.log("✓ Handle complex multi-scene example");
1294
- console.log("\n✅ All SemanticParser tests passed!");
1295
- }
1296
-
1297
- export {
1298
- makeTestGrid,
1299
- makeTestBox,
1300
- test_extractContentLines_simpleBox,
1301
- test_extractContentLines_multipleLines,
1302
- test_extractContentLines_preserveWhitespace,
1303
- test_extractContentLines_emptyBox,
1304
- test_extractContentLines_withDivider,
1305
- test_extractContentLines_withEmptyLines,
1306
- test_extractContentLines_nestedBox,
1307
- test_extractContentLines_specialChars,
1308
- test_hasContent_nonEmpty,
1309
- test_hasContent_empty,
1310
- test_getContentLineCount,
1311
- test_parseSceneDirectives_scene,
1312
- test_parseSceneDirectives_title,
1313
- test_parseSceneDirectives_titleQuotes,
1314
- test_parseSceneDirectives_transition,
1315
- test_parseSceneDirectives_allDirectives,
1316
- test_parseSceneDirectives_defaults,
1317
- test_parseSceneDirectives_unknownDirectives,
1318
- test_splitSceneBlocks_dashedSeparator,
1319
- test_splitSceneBlocks_sceneDirectiveSeparator,
1320
- test_splitSceneBlocks_singleScene,
1321
- test_splitSceneBlocks_filtersEmpty,
1322
- test_groupContentByScenes_simple,
1323
- test_groupContentByScenes_multiple,
1324
- test_groupContentByScenes_default,
1325
- test_groupContentByScenes_empty,
1326
- test_groupContentByScenes_complex,
1327
- runTests,
1328
- }
1329
- /* Grid Not a pure module */