-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
684 lines (672 loc) · 21.3 KB
/
parser_test.go
File metadata and controls
684 lines (672 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
package jinja
import (
"reflect"
"testing"
)
func TestParser_ParseNext(t *testing.T) {
tests := []struct {
name string
template string
want []*Node
wantErr bool // For ParseNext, errors are not expected from the current implementation unless explicitly set
}{
{
name: "simple control tag - include with literal path",
template: "{% include 'file.txt' %}",
want: []*Node{{Type: NodeControlTag, Content: "include 'file.txt'", Control: &ControlTagInfo{Type: ControlInclude, Expression: "'file.txt'"}}},
},
{
name: "control tag - include with variable expression",
template: "{% include template_path %}",
want: []*Node{{Type: NodeControlTag, Content: "include template_path", Control: &ControlTagInfo{Type: ControlInclude, Expression: "template_path"}}},
},
{
name: "control tag - include missing argument",
template: "{% include %}",
want: []*Node{{Type: NodeControlTag, Content: "include", Control: &ControlTagInfo{Type: ControlUnknown, Expression: "Error parsing tag 'include': include tag requires a template path or expression, e.g., {% include 'file.txt' %}"}}},
},
{
name: "empty string",
template: "",
want: nil,
},
{
name: "only literal text",
template: "Hello, world!",
want: []*Node{{Type: NodeText, Content: "Hello, world!"}},
},
{
name: "simple expression",
template: "{{ name }}",
want: []*Node{{Type: NodeExpression, Content: " name "}},
},
{
name: "literal then expression",
template: "Hello {{ name }}",
want: []*Node{
{Type: NodeText, Content: "Hello "},
{Type: NodeExpression, Content: " name "},
},
},
{
name: "expression then literal",
template: "{{ name }}!",
want: []*Node{
{Type: NodeExpression, Content: " name "},
{Type: NodeText, Content: "!"},
},
},
{
name: "literal, expression, literal",
template: "Hello {{ name }}!",
want: []*Node{
{Type: NodeText, Content: "Hello "},
{Type: NodeExpression, Content: " name "},
{Type: NodeText, Content: "!"},
},
},
{
name: "multiple expressions",
template: "{{ greeting }} {{ name }}!",
want: []*Node{
{Type: NodeExpression, Content: " greeting "},
{Type: NodeText, Content: " "},
{Type: NodeExpression, Content: " name "},
{Type: NodeText, Content: "!"},
},
},
{
name: "consecutive expressions",
template: "{{first}}{{second}}",
want: []*Node{
{Type: NodeExpression, Content: "first"},
{Type: NodeExpression, Content: "second"},
},
},
{
name: "unclosed tag at end of string",
template: "Hello {{",
want: []*Node{
{Type: NodeText, Content: "Hello "},
{Type: NodeText, Content: "{{"},
},
},
{
name: "unclosed tag with content at end of string",
template: "Hello {{ name",
want: []*Node{
{Type: NodeText, Content: "Hello "},
{Type: NodeText, Content: "{{ name"},
},
},
{
name: "unclosed tag in middle of string (same as content at end for current parser)",
template: "Hello {{ name and goodbye",
want: []*Node{
{Type: NodeText, Content: "Hello "},
{Type: NodeText, Content: "{{ name and goodbye"},
},
},
{
name: "unclosed tag followed by another literal (same as content at end)",
template: "text {{ unclosed text_after",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeText, Content: "{{ unclosed text_after"},
},
},
{
name: "double open brace literal, not a tag",
template: "This has { { not a tag } }",
want: []*Node{{Type: NodeText, Content: "This has { { not a tag } }"}},
},
{
name: "expression with no spaces",
template: "{{name}}",
want: []*Node{{Type: NodeExpression, Content: "name"}},
},
{
name: "expression with leading space",
template: "{{ name}}",
want: []*Node{{Type: NodeExpression, Content: " name"}},
},
{
name: "expression with trailing space",
template: "{{name }}",
want: []*Node{{Type: NodeExpression, Content: "name "}},
},
{
name: "empty expression",
template: "{{}}",
want: []*Node{{Type: NodeExpression, Content: ""}},
},
{
name: "expression with only spaces",
template: "{{ }}",
want: []*Node{{Type: NodeExpression, Content: " "}},
},
{
name: "string with only {{ }} then text",
template: "{{}} world",
want: []*Node{
{Type: NodeExpression, Content: ""},
{Type: NodeText, Content: " world"},
},
},
{
name: "text then {{}} then text",
template: "hello{{}}world",
want: []*Node{
{Type: NodeText, Content: "hello"},
{Type: NodeExpression, Content: ""},
{Type: NodeText, Content: "world"},
},
},
{
name: "incomplete open tag at very end {{ a",
template: "test {{ a",
want: []*Node{
{Type: NodeText, Content: "test "},
{Type: NodeText, Content: "{{ a"},
},
},
{
name: "incomplete open tag at very end {",
template: "test {",
want: []*Node{{Type: NodeText, Content: "test {"}},
},
{
name: "template starting with unclosed tag",
template: "{{ unfinished then text",
want: []*Node{{Type: NodeText, Content: "{{ unfinished then text"}},
},
{
name: "template with {{ and }} but content missing",
template: "{{}} and {{ value }}",
want: []*Node{
{Type: NodeExpression, Content: ""},
{Type: NodeText, Content: " and "},
{Type: NodeExpression, Content: " value "},
},
},
{
name: "only an unclosed tag {{tag",
template: "{{tag",
want: []*Node{{Type: NodeText, Content: "{{tag"}},
},
{
name: "only {{ at end",
template: "text{{",
want: []*Node{
{Type: NodeText, Content: "text"},
{Type: NodeText, Content: "{{"},
},
},
{
name: "string expression inside expression",
template: "{{ 'some string' }}",
want: []*Node{{Type: NodeExpression, Content: " 'some string' "}},
},
{
name: "expression opening braces inside expression",
template: "{{ '{{' }}",
want: []*Node{{Type: NodeExpression, Content: " '{{' "}},
},
{
name: "expression closing braces inside expression",
template: "{{ '}}' }}",
want: []*Node{{Type: NodeExpression, Content: " '}}' "}},
},
{
name: "string expression with escaped braces inside expression",
template: "{{ '{{}}' }}",
want: []*Node{{Type: NodeExpression, Content: " '{{}}' "}},
},
{
name: "string expression with escaped double quotes inside expression",
template: "{{ '\"' }}",
want: []*Node{{Type: NodeExpression, Content: " '\"' "}},
},
{
name: "escaped nested expression",
template: "{{ \"{{ name }}\" }}",
want: []*Node{{Type: NodeExpression, Content: " \"{{ name }}\" "}},
},
{
name: "nested {{ in string in expr then }}",
template: "{{ \"a{{b\" }}",
want: []*Node{{Type: NodeExpression, Content: " \"a{{b\" "}},
},
{
name: "nested {{ in string in expr then }} then text",
template: "{{ \"a{{b\" }} world",
want: []*Node{
{Type: NodeExpression, Content: " \"a{{b\" "},
{Type: NodeText, Content: " world"},
},
},
{
name: "complex nested {{ and }} within strings",
template: "Hello {{ \"a {{ b }} c\" | filter(\"x {{ y }} z\") }} Bye",
want: []*Node{
{Type: NodeText, Content: "Hello "},
{Type: NodeExpression, Content: " \"a {{ b }} c\" | filter(\"x {{ y }} z\") "},
{Type: NodeText, Content: " Bye"},
},
},
{
name: "simple comment",
template: "{# this is a comment #}",
want: []*Node{{Type: NodeComment, Content: " this is a comment "}},
},
{
name: "comment with text before and after",
template: "hello {# comment #} world",
want: []*Node{
{Type: NodeText, Content: "hello "},
{Type: NodeComment, Content: " comment "},
{Type: NodeText, Content: " world"},
},
},
{
name: "unclosed comment",
template: "hello {# comment world",
want: []*Node{{Type: NodeText, Content: "hello "}, {Type: NodeText, Content: "{# comment world"}},
},
{
name: "simple control tag - if",
template: "{% if condition %}",
want: []*Node{{Type: NodeControlTag, Content: "if condition", Control: &ControlTagInfo{Type: ControlIf, Expression: "condition"}}},
},
{
name: "simple control tag - endif",
template: "{% endif %}",
want: []*Node{{Type: NodeControlTag, Content: "endif", Control: &ControlTagInfo{Type: ControlEndIf}}},
},
{
name: "control tag - if with extra spaces",
template: "{% if condition %}",
want: []*Node{{Type: NodeControlTag, Content: "if condition", Control: &ControlTagInfo{Type: ControlIf, Expression: "condition"}}},
},
{
name: "control tag - if with complex condition",
template: "{% if user.name == 'test' and user.age > 30 %}",
want: []*Node{{Type: NodeControlTag, Content: "if user.name == 'test' and user.age > 30", Control: &ControlTagInfo{Type: ControlIf, Expression: "user.name == 'test' and user.age > 30"}}},
},
{
name: "control tag - if missing condition",
template: "{% if %}", // Parser creates an Unknown type node with error in Expression
want: []*Node{{Type: NodeControlTag, Content: "if", Control: &ControlTagInfo{Type: ControlUnknown, Expression: "Error parsing tag 'if': if tag requires a condition, e.g., {% if user.isAdmin %}"}}},
},
{
name: "control tag - endif with extra content",
template: "{% endif this %}", // Parser creates an Unknown type node with error in Expression
want: []*Node{{Type: NodeControlTag, Content: "endif this", Control: &ControlTagInfo{Type: ControlUnknown, Expression: "Error parsing tag 'endif this': endif tag does not take any arguments, e.g., {% endif %}"}}},
},
{
name: "simple control tag - else",
template: "{% else %}",
want: []*Node{{Type: NodeControlTag, Content: "else", Control: &ControlTagInfo{Type: ControlElse}}},
},
{
name: "control tag - else with arguments (invalid)",
template: "{% else somearg %}",
want: []*Node{{Type: NodeControlTag, Content: "else somearg", Control: &ControlTagInfo{Type: ControlUnknown, Expression: "Error parsing tag 'else somearg': else tag does not take any arguments, e.g., {% else %}"}}},
},
{
name: "simple control tag - elif",
template: "{% elif condition2 %}",
want: []*Node{{Type: NodeControlTag, Content: "elif condition2", Control: &ControlTagInfo{Type: ControlElseIf, Expression: "condition2"}}},
},
{
name: "control tag - elif with complex condition",
template: "{% elif item.value == 100 or is_admin %}",
want: []*Node{{Type: NodeControlTag, Content: "elif item.value == 100 or is_admin", Control: &ControlTagInfo{Type: ControlElseIf, Expression: "item.value == 100 or is_admin"}}},
},
{
name: "control tag - elif missing condition (invalid)",
template: "{% elif %}",
want: []*Node{{Type: NodeControlTag, Content: "elif", Control: &ControlTagInfo{Type: ControlUnknown, Expression: "Error parsing tag 'elif': elif tag requires a condition, e.g., {% elif user.isGuest %}"}}},
},
{
name: "unclosed control tag - if",
template: "text {% if condition",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeText, Content: "{% if condition"},
},
},
{
name: "control tag containing string with percent brace",
template: "{% if name == \"test %}\" %}",
want: []*Node{{Type: NodeControlTag, Content: "if name == \"test %}\"", Control: &ControlTagInfo{Type: ControlIf, Expression: "name == \"test %}\""}}},
},
{
name: "mixed tags including control",
template: "Value: {{ val }} {# comment #} {% if debug %}Debug Mode{% endif %}",
want: []*Node{
{Type: NodeText, Content: "Value: "},
{Type: NodeExpression, Content: " val "},
{Type: NodeText, Content: " "},
{Type: NodeComment, Content: " comment "},
{Type: NodeText, Content: " "},
{Type: NodeControlTag, Content: "if debug", Control: &ControlTagInfo{Type: ControlIf, Expression: "debug"}},
{Type: NodeText, Content: "Debug Mode"},
{Type: NodeControlTag, Content: "endif", Control: &ControlTagInfo{Type: ControlEndIf}},
},
},
{
name: "list literal",
template: "{{ [1, '2', three] }}",
want: []*Node{
{Type: NodeExpression, Content: " [1, '2', three] "},
},
},
{
name: "nested list literal",
template: "{{ [1, [2]] }}",
want: []*Node{
{Type: NodeExpression, Content: " [1, [2]] "},
},
},
{
name: "dict expression",
template: "{{ {'a': 123} }}",
want: []*Node{
{Type: NodeExpression, Content: " {'a': 123} "},
},
},
{
name: "nested dict expression",
template: "{{ {'a': {'b': 234}} }}",
want: []*Node{
{Type: NodeExpression, Content: " {'a': {'b': 234}} "},
},
},
{
name: "list in for loop",
template: "{% for item in [1, 2, 3] %}{{ item }}{% endfor %}",
want: []*Node{
{Type: NodeControlTag, Content: "for item in [1, 2, 3]", Control: &ControlTagInfo{Type: ControlFor, Expression: "item in [1, 2, 3]"}},
{Type: NodeExpression, Content: " item "},
{Type: NodeControlTag, Content: "endfor", Control: &ControlTagInfo{Type: ControlEndFor}},
},
},
{
name: "list literal with extra whitespaces",
template: "{{ [ 1, '2' , three ] }}",
want: []*Node{
{Type: NodeExpression, Content: " [ 1, '2' , three ] "},
},
},
{
name: "list of dictionaries in expression",
template: "{{ [{'a': 1}, {'b': 2}] }}",
want: []*Node{
{Type: NodeExpression, Content: " [{'a': 1}, {'b': 2}] "},
},
},
{
name: "dictionary with list value in expression",
template: "{{ {'key': [1, 2, 3]} }}",
want: []*Node{
{Type: NodeExpression, Content: " {'key': [1, 2, 3]} "},
},
},
{
name: "deeply nested mixed structure in expression",
template: "{{ {'a': [1, {'b': [2, {'c': 3}]}]} }}",
want: []*Node{
{Type: NodeExpression, Content: " {'a': [1, {'b': [2, {'c': 3}]}]} "},
},
},
{
name: "expression with string literal containing braces",
template: "{{ \"foo { 'a': 1 } bar\" }}",
want: []*Node{
{Type: NodeExpression, Content: " \"foo { 'a': 1 } bar\" "},
},
},
{
name: "dict in text",
template: "text {{ {'a': 1} }} more text",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeExpression, Content: " {'a': 1} "},
{Type: NodeText, Content: " more text"},
},
},
{
name: "missing closed tag is treated as text",
template: "text {{ {'a': 1} } more text",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeText, Content: "{{ {'a': 1} } more text"},
},
},
{
name: "control tag with dictionary literal",
template: "{% if data == {'key': 'value'} %}",
want: []*Node{
{Type: NodeControlTag, Content: "if data == {'key': 'value'}", Control: &ControlTagInfo{Type: ControlIf, Expression: "data == {'key': 'value'}"}},
},
},
{
name: "control tag with nested dictionary literal",
template: "{% if data == {'a': {'b': 1}} %}",
want: []*Node{
{Type: NodeControlTag, Content: "if data == {'a': {'b': 1}}", Control: &ControlTagInfo{Type: ControlIf, Expression: "data == {'a': {'b': 1}}"}},
},
},
{
name: "comment containing various braces",
template: "{# a comment with { and } and {{ and }} and {% and %} #}",
want: []*Node{
{Type: NodeComment, Content: " a comment with { and } and {{ and }} and {% and %} "},
},
},
{
name: "expression with mixed grouping symbols",
template: "{{ ([{'a': 1}]) }}",
want: []*Node{
{Type: NodeExpression, Content: " ([{'a': 1}]) "},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewParser(tt.template)
var got []*Node
var currentErr error
for {
node, err := p.ParseNext()
if err != nil {
currentErr = err
break
}
if node == nil { // EOF
break
}
nodeCopy := *node // Make a shallow copy for `got`
if node.Control != nil { // Deep copy ControlTagInfo if present
controlCopy := *node.Control
nodeCopy.Control = &controlCopy
}
got = append(got, &nodeCopy)
}
if (currentErr != nil) != tt.wantErr {
t.Errorf("p.ParseNext() error = %v, wantErr %v for template %q\n", currentErr, tt.wantErr, tt.template)
return
}
if currentErr != nil && tt.wantErr {
return
}
if len(tt.want) == 0 && len(got) == 0 {
// Pass
} else if !reflect.DeepEqual(got, tt.want) {
t.Errorf("p.ParseNext() for template %q produced incorrect nodes.\n", tt.template)
t.Logf("Got (%d items):\n", len(got))
for i, n := range got {
t.Logf(" [%d] Type: %v, Content: %q, Control: %+v\n", i, n.Type, n.Content, n.Control)
}
t.Logf("Want (%d items):\n", len(tt.want))
for i, n := range tt.want {
t.Logf(" [%d] Type: %v, Content: %q, Control: %+v\n", i, n.Type, n.Content, n.Control)
}
t.FailNow()
}
})
}
}
// TestParseNext_WithComplexInputs can be removed or merged if TestParser_ParseNext covers sufficiently.
// For now, keeping it separate if it targets different complexities or verbosity.
// If TestParser_ParseNext is comprehensive, this can be deprecated.
/*
func TestParseNext_WithComplexInputs(t *testing.T) {
tests := []struct {
name string
input string
want []*Node // Changed to slice of pointers
}{
{
name: "text, expression, text",
input: "hello {{ name }} world",
want: []*Node{
{Type: NodeText, Content: "hello "},
{Type: NodeExpression, Content: " name "},
{Type: NodeText, Content: " world"},
},
},
{
name: "text with {{ and }} but not an expression due to spacing",
input: "text { {var} } world",
want: []*Node{{Type: NodeText, Content: "text { {var} } world"}},
},
{
name: "Text only containing {{ but not closed",
input: "{{",
want: []*Node{{Type: NodeText, Content: "{{"}},
},
{
name: "Text only containing {# but not closed",
input: "{#",
want: []*Node{{Type: NodeText, Content: "{#"}},
},
{
name: "Text only containing {% but not closed",
input: "{%",
want: []*Node{{Type: NodeText, Content: "{%"}},
},
{
name: "text, comment, expression, text, comment, expression",
input: "A {# B #} C {{ D }} E {# F #} G {{ H }}",
want: []*Node{
{Type: NodeText, Content: "A "},
{Type: NodeComment, Content: " B "},
{Type: NodeText, Content: " C "},
{Type: NodeExpression, Content: " D "},
{Type: NodeText, Content: " E "},
{Type: NodeComment, Content: " F "},
{Type: NodeText, Content: " G "},
{Type: NodeExpression, Content: " H "},
},
},
{
name: "unclosed comment followed by valid expression",
input: "text {# unclosed {{ expr }}",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeText, Content: "{# unclosed "},
{Type: NodeExpression, Content: " expr "},
},
},
{
name: "unclosed expr followed by valid comment",
input: "text {{ unclosed {# comment #}",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeText, Content: "{{ unclosed "},
{Type: NodeComment, Content: " comment "},
},
},
{
name: "unclosed control tag followed by valid expression",
input: "text {% unclosed {{ expr }}",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeText, Content: "{% unclosed "},
{Type: NodeExpression, Content: " expr "},
},
},
{
name: "unclosed expr followed by valid control tag",
input: "text {{ unclosed {% if true %}",
want: []*Node{
{Type: NodeText, Content: "text "},
{Type: NodeText, Content: "{{ unclosed "},
{Type: NodeControlTag, Content: "if true", Control: &ControlTagInfo{Type:ControlIf, Expression: "true"}},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewParser(tt.input)
var got []*Node // Changed to slice of pointers
var currentErr error
for {
node, err := p.ParseNext()
if err != nil {
currentErr = err
break
}
if node == nil { // EOF
break
}
// node is already a pointer, just append it
got = append(got, node)
}
if (currentErr != nil) != false {
t.Errorf("p.ParseNext() error = %v, wantErr false for input %q\n", currentErr, tt.input)
return
}
if len(tt.want) == 0 && len(got) == 0 {
// Pass
} else if !compareNodeSlices(got, tt.want) {
t.Errorf("p.ParseNext() for input %q did not produce the expected nodes.\n", tt.input)
t.Logf("Got (%d items):\n", len(got))
for i, n := range got {
t.Logf(" [%d] Type: %v, Content: %q, Control: %+v\n", i, n.Type, n.Content, n.Control)
}
t.Logf("Want (%d items):\n", len(tt.want))
for i, n := range tt.want {
t.Logf(" [%d] Type: %v, Content: %q, Control: %+v\n", i, n.Type, n.Content, n.Control)
}
t.FailNow()
}
})
}
})
*/
// compareNodeSlices compares two slices of Node pointers for deep equality,
// paying special attention to the Control field.
func compareNodeSlices(got []*Node, want []*Node) bool {
if len(got) != len(want) {
return false
}
for i := range got {
if got[i] == nil && want[i] == nil {
continue
}
if got[i] == nil || want[i] == nil {
return false // One is nil, the other is not
}
if got[i].Type != want[i].Type || got[i].Content != want[i].Content {
return false
}
// Compare Control field
if !reflect.DeepEqual(got[i].Control, want[i].Control) {
return false
}
}
return true
}