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,250 +0,0 @@
1
- // CheckboxParser_test.res
2
- // Unit tests for checkbox element parser
3
-
4
- open Vitest
5
-
6
- describe("CheckboxParser", () => {
7
- let parser = CheckboxParser.make()
8
-
9
- describe("canParse", () => {
10
- test("recognizes checked checkbox [x]", t => {
11
- t->expect(parser.canParse("[x]"))->Expect.toBe(true)
12
- })
13
-
14
- test("recognizes checked checkbox with uppercase X", t => {
15
- t->expect(parser.canParse("[X]"))->Expect.toBe(true)
16
- })
17
-
18
- test("recognizes unchecked checkbox [ ]", t => {
19
- t->expect(parser.canParse("[ ]"))->Expect.toBe(true)
20
- })
21
-
22
- test("recognizes unchecked checkbox with multiple spaces", t => {
23
- t->expect(parser.canParse("[ ]"))->Expect.toBe(true)
24
- })
25
-
26
- test("recognizes checkbox with label", t => {
27
- t->expect(parser.canParse("[x] Accept terms"))->Expect.toBe(true)
28
- })
29
-
30
- test("recognizes checkbox with label at end", t => {
31
- t->expect(parser.canParse("Accept terms [x]"))->Expect.toBe(true)
32
- })
33
-
34
- test("rejects plain text", t => {
35
- t->expect(parser.canParse("plain text"))->Expect.toBe(false)
36
- })
37
-
38
- test("rejects button syntax", t => {
39
- t->expect(parser.canParse("[ Button ]"))->Expect.toBe(false)
40
- })
41
-
42
- test("rejects input syntax", t => {
43
- t->expect(parser.canParse("#email"))->Expect.toBe(false)
44
- })
45
-
46
- test("rejects incomplete brackets", t => {
47
- t->expect(parser.canParse("[x"))->Expect.toBe(false)
48
- t->expect(parser.canParse("x]"))->Expect.toBe(false)
49
- })
50
- })
51
-
52
- describe("parse - checked state", () => {
53
- let position = Types.Position.make(5, 10)
54
- let bounds = Types.Bounds.make(~top=0, ~left=0, ~bottom=10, ~right=30)
55
-
56
- test("extracts checked state from [x]", t => {
57
- switch parser.parse("[x]", position, bounds) {
58
- | Some(Checkbox({checked, label, position: pos})) => {
59
- t->expect(checked)->Expect.toBe(true)
60
- t->expect(label)->Expect.toBe("")
61
- t->expect(pos.row)->Expect.toBe(5)
62
- t->expect(pos.col)->Expect.toBe(10)
63
- }
64
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
65
- }
66
- })
67
-
68
- test("handles uppercase X in [X]", t => {
69
- switch parser.parse("[X]", position, bounds) {
70
- | Some(Checkbox({checked})) => {
71
- t->expect(checked)->Expect.toBe(true)
72
- }
73
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
74
- }
75
- })
76
-
77
- test("extracts label after checked checkbox", t => {
78
- switch parser.parse("[x] Accept terms and conditions", position, bounds) {
79
- | Some(Checkbox({checked, label})) => {
80
- t->expect(checked)->Expect.toBe(true)
81
- t->expect(label)->Expect.toBe("Accept terms and conditions")
82
- }
83
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
84
- }
85
- })
86
-
87
- test("trims whitespace from label", t => {
88
- switch parser.parse("[x] Subscribe to newsletter ", position, bounds) {
89
- | Some(Checkbox({label})) => {
90
- t->expect(label)->Expect.toBe("Subscribe to newsletter")
91
- }
92
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
93
- }
94
- })
95
-
96
- test("handles label with special characters", t => {
97
- switch parser.parse("[x] I agree to the Terms & Conditions", position, bounds) {
98
- | Some(Checkbox({label})) => {
99
- t->expect(label)->Expect.toBe("I agree to the Terms & Conditions")
100
- }
101
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
102
- }
103
- })
104
- })
105
-
106
- describe("parse - unchecked state", () => {
107
- let position = Types.Position.make(3, 5)
108
- let bounds = Types.Bounds.make(~top=0, ~left=0, ~bottom=10, ~right=30)
109
-
110
- test("extracts unchecked state from [ ]", t => {
111
- switch parser.parse("[ ]", position, bounds) {
112
- | Some(Checkbox({checked, label})) => {
113
- t->expect(checked)->Expect.toBe(false)
114
- t->expect(label)->Expect.toBe("")
115
- }
116
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
117
- }
118
- })
119
-
120
- test("handles multiple spaces in brackets", t => {
121
- switch parser.parse("[ ]", position, bounds) {
122
- | Some(Checkbox({checked})) => {
123
- t->expect(checked)->Expect.toBe(false)
124
- }
125
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
126
- }
127
- })
128
-
129
- test("extracts label after unchecked checkbox", t => {
130
- switch parser.parse("[ ] Remember me", position, bounds) {
131
- | Some(Checkbox({checked, label})) => {
132
- t->expect(checked)->Expect.toBe(false)
133
- t->expect(label)->Expect.toBe("Remember me")
134
- }
135
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
136
- }
137
- })
138
-
139
- test("handles long labels", t => {
140
- switch parser.parse("[ ] I would like to receive promotional emails and updates", position, bounds) {
141
- | Some(Checkbox({label})) => {
142
- t->expect(label)->Expect.toBe("I would like to receive promotional emails and updates")
143
- }
144
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
145
- }
146
- })
147
- })
148
-
149
- describe("parse - edge cases", () => {
150
- let position = Types.Position.make(0, 0)
151
- let bounds = Types.Bounds.make(~top=0, ~left=0, ~bottom=5, ~right=20)
152
-
153
- test("handles checkbox with no label", t => {
154
- switch parser.parse("[x]", position, bounds) {
155
- | Some(Checkbox({label})) => {
156
- t->expect(label)->Expect.toBe("")
157
- }
158
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
159
- }
160
- })
161
-
162
- test("handles extra whitespace before checkbox", t => {
163
- switch parser.parse(" [x] Label", position, bounds) {
164
- | Some(Checkbox({checked, label})) => {
165
- t->expect(checked)->Expect.toBe(true)
166
- t->expect(label)->Expect.toBe("Label")
167
- }
168
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
169
- }
170
- })
171
-
172
- test("handles extra whitespace after label", t => {
173
- switch parser.parse("[x] Label ", position, bounds) {
174
- | Some(Checkbox({label})) => {
175
- t->expect(label)->Expect.toBe("Label")
176
- }
177
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
178
- }
179
- })
180
-
181
- test("returns None for invalid pattern", t => {
182
- let result = parser.parse("not a checkbox", position, bounds)
183
- t->expect(result)->Expect.toBe(None)
184
- })
185
-
186
- test("returns None for button-like pattern [ Text ]", t => {
187
- let result = parser.parse("[ Submit ]", position, bounds)
188
- t->expect(result)->Expect.toBe(None)
189
- })
190
- })
191
-
192
- describe("parse - label variations", () => {
193
- let position = Types.Position.make(2, 3)
194
- let bounds = Types.Bounds.make(~top=0, ~left=0, ~bottom=10, ~right=40)
195
-
196
- test("handles label with numbers", t => {
197
- switch parser.parse("[x] Option 123", position, bounds) {
198
- | Some(Checkbox({label})) => {
199
- t->expect(label)->Expect.toBe("Option 123")
200
- }
201
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
202
- }
203
- })
204
-
205
- test("handles label with punctuation", t => {
206
- switch parser.parse("[ ] Yes, I agree!", position, bounds) {
207
- | Some(Checkbox({label})) => {
208
- t->expect(label)->Expect.toBe("Yes, I agree!")
209
- }
210
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
211
- }
212
- })
213
-
214
- test("handles label with parentheses", t => {
215
- switch parser.parse("[x] Enable feature (beta)", position, bounds) {
216
- | Some(Checkbox({label})) => {
217
- t->expect(label)->Expect.toBe("Enable feature (beta)")
218
- }
219
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
220
- }
221
- })
222
-
223
- test("handles label with quotes", t => {
224
- switch parser.parse("[x] Accept \"User Agreement\"", position, bounds) {
225
- | Some(Checkbox({label})) => {
226
- t->expect(label)->Expect.toBe("Accept \"User Agreement\"")
227
- }
228
- | _ => t->expect(true)->Expect.toBe(false) // fail: Expected Checkbox element
229
- }
230
- })
231
- })
232
-
233
- describe("priority", () => {
234
- test("has priority of 85", t => {
235
- t->expect(parser.priority)->Expect.toBe(85)
236
- })
237
-
238
- test("priority is higher than text parser (1)", t => {
239
- t->expect(parser.priority)->Expect.Int.toBeGreaterThan(1)
240
- })
241
-
242
- test("priority is lower than button parser (100)", t => {
243
- t->expect(parser.priority)->Expect.Int.toBeLessThan(100)
244
- })
245
-
246
- test("priority is lower than input parser (90)", t => {
247
- t->expect(parser.priority)->Expect.Int.toBeLessThan(90)
248
- })
249
- })
250
- })
@@ -1,293 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Types from "../../../Core/Types.mjs";
4
- import * as CodeTextParser from "../CodeTextParser.mjs";
5
-
6
- function test_canParse_quotedText() {
7
- if (CodeTextParser.canParse("'centered text'") === true) {
8
- return;
9
- }
10
- throw {
11
- RE_EXN_ID: "Assert_failure",
12
- _1: [
13
- "CodeTextParser_manual.res",
14
- 9,
15
- 2
16
- ],
17
- Error: new Error()
18
- };
19
- }
20
-
21
- function test_canParse_withSpaces() {
22
- if (CodeTextParser.canParse(" 'code' ") === true) {
23
- return;
24
- }
25
- throw {
26
- RE_EXN_ID: "Assert_failure",
27
- _1: [
28
- "CodeTextParser_manual.res",
29
- 15,
30
- 2
31
- ],
32
- Error: new Error()
33
- };
34
- }
35
-
36
- function test_canParse_plainText() {
37
- if (CodeTextParser.canParse("plain text") === false) {
38
- return;
39
- }
40
- throw {
41
- RE_EXN_ID: "Assert_failure",
42
- _1: [
43
- "CodeTextParser_manual.res",
44
- 21,
45
- 2
46
- ],
47
- Error: new Error()
48
- };
49
- }
50
-
51
- function test_parse_extractText() {
52
- let bounds = Types.Bounds.make(0, 0, 5, 30);
53
- let position = Types.Position.make(1, 1);
54
- let match = CodeTextParser.parse("'Submit'", position, bounds);
55
- if (match !== undefined) {
56
- if (match.TAG === "Text") {
57
- if (match.content !== "Submit") {
58
- throw {
59
- RE_EXN_ID: "Assert_failure",
60
- _1: [
61
- "CodeTextParser_manual.res",
62
- 32,
63
- 6
64
- ],
65
- Error: new Error()
66
- };
67
- }
68
- if (match.emphasis === true) {
69
- return;
70
- }
71
- throw {
72
- RE_EXN_ID: "Assert_failure",
73
- _1: [
74
- "CodeTextParser_manual.res",
75
- 33,
76
- 6
77
- ],
78
- Error: new Error()
79
- };
80
- }
81
- throw {
82
- RE_EXN_ID: "Assert_failure",
83
- _1: [
84
- "CodeTextParser_manual.res",
85
- 35,
86
- 9
87
- ],
88
- Error: new Error()
89
- };
90
- }
91
- throw {
92
- RE_EXN_ID: "Assert_failure",
93
- _1: [
94
- "CodeTextParser_manual.res",
95
- 35,
96
- 9
97
- ],
98
- Error: new Error()
99
- };
100
- }
101
-
102
- function test_parse_centerAlignment() {
103
- let bounds = Types.Bounds.make(0, 0, 5, 30);
104
- let position = Types.Position.make(1, 12);
105
- let match = CodeTextParser.parse("'Centered'", position, bounds);
106
- if (match !== undefined) {
107
- if (match.TAG === "Text") {
108
- if (match.align === "Center") {
109
- return;
110
- }
111
- throw {
112
- RE_EXN_ID: "Assert_failure",
113
- _1: [
114
- "CodeTextParser_manual.res",
115
- 47,
116
- 6
117
- ],
118
- Error: new Error()
119
- };
120
- }
121
- throw {
122
- RE_EXN_ID: "Assert_failure",
123
- _1: [
124
- "CodeTextParser_manual.res",
125
- 49,
126
- 9
127
- ],
128
- Error: new Error()
129
- };
130
- }
131
- throw {
132
- RE_EXN_ID: "Assert_failure",
133
- _1: [
134
- "CodeTextParser_manual.res",
135
- 49,
136
- 9
137
- ],
138
- Error: new Error()
139
- };
140
- }
141
-
142
- function test_parse_leftAlignment() {
143
- let bounds = Types.Bounds.make(0, 0, 5, 30);
144
- let position = Types.Position.make(1, 1);
145
- let match = CodeTextParser.parse("'Left'", position, bounds);
146
- if (match !== undefined) {
147
- if (match.TAG === "Text") {
148
- if (match.align === "Left") {
149
- return;
150
- }
151
- throw {
152
- RE_EXN_ID: "Assert_failure",
153
- _1: [
154
- "CodeTextParser_manual.res",
155
- 61,
156
- 6
157
- ],
158
- Error: new Error()
159
- };
160
- }
161
- throw {
162
- RE_EXN_ID: "Assert_failure",
163
- _1: [
164
- "CodeTextParser_manual.res",
165
- 63,
166
- 9
167
- ],
168
- Error: new Error()
169
- };
170
- }
171
- throw {
172
- RE_EXN_ID: "Assert_failure",
173
- _1: [
174
- "CodeTextParser_manual.res",
175
- 63,
176
- 9
177
- ],
178
- Error: new Error()
179
- };
180
- }
181
-
182
- function test_parse_rightAlignment() {
183
- let bounds = Types.Bounds.make(0, 0, 5, 30);
184
- let position = Types.Position.make(1, 24);
185
- let match = CodeTextParser.parse("'Right'", position, bounds);
186
- if (match !== undefined) {
187
- if (match.TAG === "Text") {
188
- if (match.align === "Right") {
189
- return;
190
- }
191
- throw {
192
- RE_EXN_ID: "Assert_failure",
193
- _1: [
194
- "CodeTextParser_manual.res",
195
- 75,
196
- 6
197
- ],
198
- Error: new Error()
199
- };
200
- }
201
- throw {
202
- RE_EXN_ID: "Assert_failure",
203
- _1: [
204
- "CodeTextParser_manual.res",
205
- 77,
206
- 9
207
- ],
208
- Error: new Error()
209
- };
210
- }
211
- throw {
212
- RE_EXN_ID: "Assert_failure",
213
- _1: [
214
- "CodeTextParser_manual.res",
215
- 77,
216
- 9
217
- ],
218
- Error: new Error()
219
- };
220
- }
221
-
222
- function test_parse_emptyContent() {
223
- let bounds = Types.Bounds.make(0, 0, 5, 30);
224
- let position = Types.Position.make(1, 1);
225
- let match = CodeTextParser.parse("' '", position, bounds);
226
- if (match === undefined) {
227
- return;
228
- }
229
- throw {
230
- RE_EXN_ID: "Assert_failure",
231
- _1: [
232
- "CodeTextParser_manual.res",
233
- 89,
234
- 15
235
- ],
236
- Error: new Error()
237
- };
238
- }
239
-
240
- function test_make_priority() {
241
- let parser = CodeTextParser.make();
242
- if (parser.priority === 75) {
243
- return;
244
- }
245
- throw {
246
- RE_EXN_ID: "Assert_failure",
247
- _1: [
248
- "CodeTextParser_manual.res",
249
- 96,
250
- 2
251
- ],
252
- Error: new Error()
253
- };
254
- }
255
-
256
- function runTests() {
257
- console.log("Running CodeTextParser tests...");
258
- test_canParse_quotedText();
259
- console.log(" test_canParse_quotedText passed");
260
- test_canParse_withSpaces();
261
- console.log(" test_canParse_withSpaces passed");
262
- test_canParse_plainText();
263
- console.log(" test_canParse_plainText passed");
264
- test_parse_extractText();
265
- console.log(" test_parse_extractText passed");
266
- test_parse_centerAlignment();
267
- console.log(" test_parse_centerAlignment passed");
268
- test_parse_leftAlignment();
269
- console.log(" test_parse_leftAlignment passed");
270
- test_parse_rightAlignment();
271
- console.log(" test_parse_rightAlignment passed");
272
- test_parse_emptyContent();
273
- console.log(" test_parse_emptyContent passed");
274
- test_make_priority();
275
- console.log(" test_make_priority passed");
276
- console.log("All CodeTextParser tests passed!");
277
- }
278
-
279
- runTests();
280
-
281
- export {
282
- test_canParse_quotedText,
283
- test_canParse_withSpaces,
284
- test_canParse_plainText,
285
- test_parse_extractText,
286
- test_parse_centerAlignment,
287
- test_parse_leftAlignment,
288
- test_parse_rightAlignment,
289
- test_parse_emptyContent,
290
- test_make_priority,
291
- runTests,
292
- }
293
- /* Not a pure module */
@@ -1,134 +0,0 @@
1
- // CodeTextParser_test.res
2
- // Tests for single-quote-wrapped text parser with position-based alignment
3
-
4
- open Types
5
-
6
- // Test: should recognize single-quote-wrapped text
7
- let test_canParse_quotedText = () => {
8
- let content = "'centered text'"
9
- assert(CodeTextParser.canParse(content) === true)
10
- }
11
-
12
- // Test: should recognize quoted text with spaces
13
- let test_canParse_withSpaces = () => {
14
- let content = " 'code' "
15
- assert(CodeTextParser.canParse(content) === true)
16
- }
17
-
18
- // Test: should not recognize plain text
19
- let test_canParse_plainText = () => {
20
- let content = "plain text"
21
- assert(CodeTextParser.canParse(content) === false)
22
- }
23
-
24
- // Test: should extract text from quotes
25
- let test_parse_extractText = () => {
26
- let bounds = Bounds.make(~top=0, ~left=0, ~bottom=5, ~right=30)
27
- let content = "'Submit'"
28
- let position = Position.make(1, 1)
29
-
30
- switch CodeTextParser.parse(content, position, bounds) {
31
- | Some(Text({content, emphasis, _})) => {
32
- assert(content === "Submit")
33
- assert(emphasis === true)
34
- }
35
- | _ => assert(false)
36
- }
37
- }
38
-
39
- // Test: should calculate center alignment for centered content
40
- let test_parse_centerAlignment = () => {
41
- let bounds = Bounds.make(~top=0, ~left=0, ~bottom=5, ~right=30)
42
- let content = "'Centered'"
43
- let position = Position.make(1, 12) // Roughly centered
44
-
45
- switch CodeTextParser.parse(content, position, bounds) {
46
- | Some(Text({align, _})) => {
47
- assert(align === Center)
48
- }
49
- | _ => assert(false)
50
- }
51
- }
52
-
53
- // Test: should calculate left alignment for left-positioned content
54
- let test_parse_leftAlignment = () => {
55
- let bounds = Bounds.make(~top=0, ~left=0, ~bottom=5, ~right=30)
56
- let content = "'Left'"
57
- let position = Position.make(1, 1) // Near left edge
58
-
59
- switch CodeTextParser.parse(content, position, bounds) {
60
- | Some(Text({align, _})) => {
61
- assert(align === Left)
62
- }
63
- | _ => assert(false)
64
- }
65
- }
66
-
67
- // Test: should calculate right alignment for right-positioned content
68
- let test_parse_rightAlignment = () => {
69
- let bounds = Bounds.make(~top=0, ~left=0, ~bottom=5, ~right=30)
70
- let content = "'Right'"
71
- let position = Position.make(1, 24) // Near right edge
72
-
73
- switch CodeTextParser.parse(content, position, bounds) {
74
- | Some(Text({align, _})) => {
75
- assert(align === Right)
76
- }
77
- | _ => assert(false)
78
- }
79
- }
80
-
81
- // Test: should return None for empty quoted content
82
- let test_parse_emptyContent = () => {
83
- let bounds = Bounds.make(~top=0, ~left=0, ~bottom=5, ~right=30)
84
- let content = "' '"
85
- let position = Position.make(1, 1)
86
-
87
- switch CodeTextParser.parse(content, position, bounds) {
88
- | None => assert(true)
89
- | Some(_) => assert(false)
90
- }
91
- }
92
-
93
- // Test: parser should have priority 75
94
- let test_make_priority = () => {
95
- let parser = CodeTextParser.make()
96
- assert(parser.priority === 75)
97
- }
98
-
99
- // Run all tests
100
- let runTests = () => {
101
- Console.log("Running CodeTextParser tests...")
102
-
103
- test_canParse_quotedText()
104
- Console.log(" test_canParse_quotedText passed")
105
-
106
- test_canParse_withSpaces()
107
- Console.log(" test_canParse_withSpaces passed")
108
-
109
- test_canParse_plainText()
110
- Console.log(" test_canParse_plainText passed")
111
-
112
- test_parse_extractText()
113
- Console.log(" test_parse_extractText passed")
114
-
115
- test_parse_centerAlignment()
116
- Console.log(" test_parse_centerAlignment passed")
117
-
118
- test_parse_leftAlignment()
119
- Console.log(" test_parse_leftAlignment passed")
120
-
121
- test_parse_rightAlignment()
122
- Console.log(" test_parse_rightAlignment passed")
123
-
124
- test_parse_emptyContent()
125
- Console.log(" test_parse_emptyContent passed")
126
-
127
- test_make_priority()
128
- Console.log(" test_make_priority passed")
129
-
130
- Console.log("All CodeTextParser tests passed!")
131
- }
132
-
133
- // Auto-run tests
134
- let _ = runTests()