brink-syntax 0.0.17

Syntax types and parser for inkle's ink narrative scripting language
Documentation
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
use crate::parser::tests::cst::{ExpectedNode, assert_equivalent};
use crate::{SyntaxKind, parse};

// ── INCLUDE statements ─────────────────────────────────────────

/// `INCLUDE story.ink` — basic include with `FILE_PATH` child.
#[test]
fn include_basic() {
    assert_equivalent(
        parse("INCLUDE story.ink\n"),
        cst!(SOURCE_FILE {
            INCLUDE_STMT {
                FILE_PATH
            }
        }),
    );
}

/// `INCLUDE path/to/story.ink` — path with slashes.
#[test]
fn include_path_with_slashes() {
    assert_equivalent(
        parse("INCLUDE path/to/story.ink\n"),
        cst!(SOURCE_FILE {
            INCLUDE_STMT {
                FILE_PATH
            }
        }),
    );
}

/// `INCLUDE file with spaces.ink` — file path with spaces.
#[test]
fn include_file_with_spaces() {
    assert_equivalent(
        parse("INCLUDE file with spaces.ink\n"),
        cst!(SOURCE_FILE {
            INCLUDE_STMT {
                FILE_PATH
            }
        }),
    );
}

// ── EXTERNAL declarations ──────────────────────────────────────

/// `EXTERNAL func()` — no params, no `FUNCTION_PARAM_LIST`.
#[test]
fn external_no_params() {
    assert_equivalent(
        parse("EXTERNAL func()\n"),
        cst!(SOURCE_FILE {
            EXTERNAL_DECL {
                IDENTIFIER
            }
        }),
    );
}

/// `EXTERNAL func(a)` — single param.
#[test]
fn external_single_param() {
    assert_equivalent(
        parse("EXTERNAL func(a)\n"),
        cst!(SOURCE_FILE {
            EXTERNAL_DECL {
                IDENTIFIER
                FUNCTION_PARAM_LIST {
                    IDENTIFIER
                }
            }
        }),
    );
}

/// `EXTERNAL func(a, b)` — two params.
#[test]
fn external_two_params() {
    assert_equivalent(
        parse("EXTERNAL func(a, b)\n"),
        cst!(SOURCE_FILE {
            EXTERNAL_DECL {
                IDENTIFIER
                FUNCTION_PARAM_LIST {
                    IDENTIFIER
                    IDENTIFIER
                }
            }
        }),
    );
}

/// `EXTERNAL func(a, b, c)` — three params.
#[test]
fn external_three_params() {
    assert_equivalent(
        parse("EXTERNAL func(a, b, c)\n"),
        cst!(SOURCE_FILE {
            EXTERNAL_DECL {
                IDENTIFIER
                FUNCTION_PARAM_LIST {
                    IDENTIFIER
                    IDENTIFIER
                    IDENTIFIER
                }
            }
        }),
    );
}

// ── VAR declarations ───────────────────────────────────────────

/// `VAR x = 5` — integer literal.
#[test]
fn var_integer() {
    assert_equivalent(
        parse("VAR x = 5\n"),
        cst!(SOURCE_FILE {
            VAR_DECL {
                IDENTIFIER
                INTEGER_LIT
            }
        }),
    );
}

/// `VAR name = "hello"` — string literal.
#[test]
fn var_string() {
    assert_equivalent(
        parse("VAR name = \"hello\"\n"),
        cst!(SOURCE_FILE {
            VAR_DECL {
                IDENTIFIER
                STRING_LIT
            }
        }),
    );
}

/// `VAR flag = true` — boolean literal.
#[test]
fn var_boolean() {
    assert_equivalent(
        parse("VAR flag = true\n"),
        cst!(SOURCE_FILE {
            VAR_DECL {
                IDENTIFIER
                BOOLEAN_LIT
            }
        }),
    );
}

/// `VAR x = 3.14` — float literal.
#[test]
fn var_float() {
    assert_equivalent(
        parse("VAR x = 3.14\n"),
        cst!(SOURCE_FILE {
            VAR_DECL {
                IDENTIFIER
                FLOAT_LIT
            }
        }),
    );
}

/// `VAR x = y` — variable reference (PATH child).
#[test]
fn var_reference() {
    assert_equivalent(
        parse("VAR x = y\n"),
        cst!(SOURCE_FILE {
            VAR_DECL {
                IDENTIFIER
                PATH
            }
        }),
    );
}

/// `VAR x = a + b` — expression (`INFIX_EXPR` child).
#[test]
fn var_expression() {
    assert_equivalent(
        parse("VAR x = a + b\n"),
        cst!(SOURCE_FILE {
            VAR_DECL {
                IDENTIFIER
                INFIX_EXPR {
                    PATH
                    PATH
                }
            }
        }),
    );
}

// ── CONST declarations ─────────────────────────────────────────

/// `CONST PI = 3` — integer literal.
#[test]
fn const_integer() {
    assert_equivalent(
        parse("CONST PI = 3\n"),
        cst!(SOURCE_FILE {
            CONST_DECL {
                IDENTIFIER
                INTEGER_LIT
            }
        }),
    );
}

/// `CONST NAME = "ink"` — string literal.
#[test]
fn const_string() {
    assert_equivalent(
        parse("CONST NAME = \"ink\"\n"),
        cst!(SOURCE_FILE {
            CONST_DECL {
                IDENTIFIER
                STRING_LIT
            }
        }),
    );
}

/// `CONST FLAG = false` — boolean literal.
#[test]
fn const_boolean() {
    assert_equivalent(
        parse("CONST FLAG = false\n"),
        cst!(SOURCE_FILE {
            CONST_DECL {
                IDENTIFIER
                BOOLEAN_LIT
            }
        }),
    );
}

// ── LIST declarations ──────────────────────────────────────────

/// `LIST colors = red, green, blue` — simple members (all `LIST_MEMBER_OFF`).
#[test]
fn list_simple_off() {
    assert_equivalent(
        parse("LIST colors = red, green, blue\n"),
        cst!(SOURCE_FILE {
            LIST_DECL {
                IDENTIFIER
                LIST_DEF {
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                }
            }
        }),
    );
}

/// `LIST items = (sword), (shield)` — all on (`LIST_MEMBER_ON`, no values).
#[test]
fn list_all_on() {
    assert_equivalent(
        parse("LIST items = (sword), (shield)\n"),
        cst!(SOURCE_FILE {
            LIST_DECL {
                IDENTIFIER
                LIST_DEF {
                    LIST_MEMBER {
                        LIST_MEMBER_ON
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_ON
                    }
                }
            }
        }),
    );
}

/// `LIST items = (sword = 1), shield, (potion = 3)` — mixed on/off with values.
#[test]
fn list_mixed_on_off_with_values() {
    assert_equivalent(
        parse("LIST items = (sword = 1), shield, (potion = 3)\n"),
        cst!(SOURCE_FILE {
            LIST_DECL {
                IDENTIFIER
                LIST_DEF {
                    LIST_MEMBER {
                        LIST_MEMBER_ON
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_ON
                    }
                }
            }
        }),
    );
}

/// `LIST single = item` — single member.
#[test]
fn list_single_member() {
    assert_equivalent(
        parse("LIST single = item\n"),
        cst!(SOURCE_FILE {
            LIST_DECL {
                IDENTIFIER
                LIST_DEF {
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                }
            }
        }),
    );
}

/// `LIST items = (x = 1)` — single on member with value.
#[test]
fn list_single_on_with_value() {
    assert_equivalent(
        parse("LIST items = (x = 1)\n"),
        cst!(SOURCE_FILE {
            LIST_DECL {
                IDENTIFIER
                LIST_DEF {
                    LIST_MEMBER {
                        LIST_MEMBER_ON
                    }
                }
            }
        }),
    );
}

/// `LIST kw = or, and, not` — keyword members (off).
#[test]
fn list_keyword_members_off() {
    assert_equivalent(
        parse("LIST kw = or, and, not\n"),
        cst!(SOURCE_FILE {
            LIST_DECL {
                IDENTIFIER
                LIST_DEF {
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_OFF
                    }
                }
            }
        }),
    );
}

/// `LIST kw = (or), (and)` — keyword members (on).
#[test]
fn list_keyword_members_on() {
    assert_equivalent(
        parse("LIST kw = (or), (and)\n"),
        cst!(SOURCE_FILE {
            LIST_DECL {
                IDENTIFIER
                LIST_DEF {
                    LIST_MEMBER {
                        LIST_MEMBER_ON
                    }
                    LIST_MEMBER {
                        LIST_MEMBER_ON
                    }
                }
            }
        }),
    );
}

// ── Variant uniformity ─────────────────────────────────────────
//
// Every declaration must wrap in exactly its expected node kind.

const DECL_KINDS: [SyntaxKind; 5] = [
    SyntaxKind::INCLUDE_STMT,
    SyntaxKind::EXTERNAL_DECL,
    SyntaxKind::VAR_DECL,
    SyntaxKind::CONST_DECL,
    SyntaxKind::LIST_DECL,
];

/// Assert that `src` produces exactly one top-level declaration of `expected_kind`,
/// and none of the other declaration kinds.
fn assert_decl_uniformity(src: &str, expected_kind: SyntaxKind) {
    let p = parse(src);
    assert!(p.errors().is_empty(), "unexpected errors: {:?}", p.errors());
    let root = p.syntax();

    // The expected kind should appear exactly once as a direct child of SOURCE_FILE.
    let matching: Vec<_> = root
        .children()
        .filter(|c| c.kind() == expected_kind)
        .collect();
    assert_eq!(
        matching.len(),
        1,
        "expected exactly one {expected_kind:?} in `{src}`, found {}",
        matching.len(),
    );

    // No other declaration kinds should appear anywhere in the tree.
    for kind in &DECL_KINDS {
        if *kind == expected_kind {
            continue;
        }
        let has_other = root.descendants().any(|n| n.kind() == *kind);
        assert!(
            !has_other,
            "`{src}` should not contain {kind:?}, but it does",
        );
    }
}

#[test]
fn uniformity_include() {
    assert_decl_uniformity("INCLUDE story.ink\n", SyntaxKind::INCLUDE_STMT);
}

#[test]
fn uniformity_external() {
    assert_decl_uniformity("EXTERNAL func(a)\n", SyntaxKind::EXTERNAL_DECL);
}

#[test]
fn uniformity_var() {
    assert_decl_uniformity("VAR x = 5\n", SyntaxKind::VAR_DECL);
}

#[test]
fn uniformity_const() {
    assert_decl_uniformity("CONST PI = 3\n", SyntaxKind::CONST_DECL);
}

#[test]
fn uniformity_list() {
    assert_decl_uniformity("LIST colors = red, green, blue\n", SyntaxKind::LIST_DECL);
}

// ── Positive/negative assertions ───────────────────────────────

/// `INCLUDE_STMT` is not any other declaration kind.
#[test]
fn include_not_other_decls() {
    let p = parse("INCLUDE story.ink\n");
    let root = p.syntax();
    assert!(
        root.descendants()
            .any(|n| n.kind() == SyntaxKind::INCLUDE_STMT)
    );
    assert!(
        !root
            .descendants()
            .any(|n| n.kind() == SyntaxKind::EXTERNAL_DECL)
    );
    assert!(!root.descendants().any(|n| n.kind() == SyntaxKind::VAR_DECL));
    assert!(
        !root
            .descendants()
            .any(|n| n.kind() == SyntaxKind::CONST_DECL)
    );
    assert!(
        !root
            .descendants()
            .any(|n| n.kind() == SyntaxKind::LIST_DECL)
    );
}

/// `EXTERNAL_DECL` is not any other declaration kind.
#[test]
fn external_not_other_decls() {
    let p = parse("EXTERNAL func()\n");
    let root = p.syntax();
    assert!(
        root.descendants()
            .any(|n| n.kind() == SyntaxKind::EXTERNAL_DECL)
    );
    assert!(
        !root
            .descendants()
            .any(|n| n.kind() == SyntaxKind::INCLUDE_STMT)
    );
    assert!(!root.descendants().any(|n| n.kind() == SyntaxKind::VAR_DECL));
    assert!(
        !root
            .descendants()
            .any(|n| n.kind() == SyntaxKind::CONST_DECL)
    );
    assert!(
        !root
            .descendants()
            .any(|n| n.kind() == SyntaxKind::LIST_DECL)
    );
}

/// `VAR_DECL` is not `CONST_DECL` — structurally identical but different wrapper.
#[test]
fn var_not_const() {
    let p = parse("VAR x = 5\n");
    let root = p.syntax();
    assert!(root.descendants().any(|n| n.kind() == SyntaxKind::VAR_DECL));
    assert!(
        !root
            .descendants()
            .any(|n| n.kind() == SyntaxKind::CONST_DECL)
    );
}

/// `CONST_DECL` is not `VAR_DECL`.
#[test]
fn const_not_var() {
    let p = parse("CONST PI = 3\n");
    let root = p.syntax();
    assert!(
        root.descendants()
            .any(|n| n.kind() == SyntaxKind::CONST_DECL)
    );
    assert!(!root.descendants().any(|n| n.kind() == SyntaxKind::VAR_DECL));
}

/// `LIST_DECL` contains `LIST_DEF` and `LIST_MEMBER`; other declarations do not.
#[test]
fn list_has_list_def_and_members() {
    let p = parse("LIST colors = red, green\n");
    let root = p.syntax();
    assert!(
        root.descendants()
            .any(|n| n.kind() == SyntaxKind::LIST_DECL)
    );
    assert!(root.descendants().any(|n| n.kind() == SyntaxKind::LIST_DEF));
    assert!(
        root.descendants()
            .any(|n| n.kind() == SyntaxKind::LIST_MEMBER)
    );
}

/// Non-list declarations do not contain `LIST_DEF` or `LIST_MEMBER`.
#[test]
fn non_list_has_no_list_nodes() {
    for src in &[
        "INCLUDE story.ink\n",
        "EXTERNAL func(a)\n",
        "VAR x = 5\n",
        "CONST PI = 3\n",
    ] {
        let p = parse(src);
        let root = p.syntax();
        assert!(
            !root.descendants().any(|n| n.kind() == SyntaxKind::LIST_DEF),
            "`{src}` should not contain LIST_DEF",
        );
        assert!(
            !root
                .descendants()
                .any(|n| n.kind() == SyntaxKind::LIST_MEMBER),
            "`{src}` should not contain LIST_MEMBER",
        );
    }
}

// ── Error recovery / edge cases ────────────────────────────────

/// Missing `=` in VAR — errors but lossless round-trip.
#[test]
fn error_var_missing_eq() {
    let src = "VAR x 5\n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
    assert!(
        !p.errors().is_empty(),
        "expected parse error for missing `=` in VAR",
    );
}

/// Missing `)` in EXTERNAL — errors but lossless round-trip.
#[test]
fn error_external_missing_rparen() {
    let src = "EXTERNAL func(a, b\n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
    assert!(
        !p.errors().is_empty(),
        "expected parse error for missing `)` in EXTERNAL",
    );
}

/// Empty LIST definition `LIST x =\n` — errors but lossless round-trip.
#[test]
fn error_list_empty_def() {
    let src = "LIST x =\n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
    assert!(
        !p.errors().is_empty(),
        "expected parse error for empty LIST definition",
    );
}

/// Missing filename in INCLUDE — lossless round-trip (may or may not error).
#[test]
fn error_include_missing_filename() {
    let src = "INCLUDE \n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
}

// ── C. `INLINE_WS+` notation-vs-code gap (#2695 sibling sweep, #2707) ──
//
// #2695 fixed `knot.rs`'s `stitch_header` doc comment, which claimed
// `INLINE_WS+` (required whitespace) after `=` when the actual parser body
// (`p.bump()` + `p.skip_ws()`) accepts zero-or-more. #2701's review found
// the same shape, un-fixed, in every declaration parser in this file. Each
// function's doc comment above now says `INLINE_WS*`; these tests drive
// the boundary directly so a future comment/code drift fails a test
// instead of waiting for another retro to notice.
//
// `INCLUDE` and `IMPORT`'s bare-list form can actually present a
// whitespace-free input to their respective parse functions (the token
// right after the keyword isn't an identifier character, so it doesn't
// fuse with the keyword) — those two get a real "parses to the expected
// node with zero whitespace" test. `EXTERNAL`/`VAR`/`CONST`/`LIST` (and
// `IMPORT`'s qualified form) are always followed by a bare identifier,
// which *does* fuse with the keyword at the lexer level (`EXTERNALfoo`
// lexes as one `IDENT` token, never `KW_EXTERNAL` + `IDENT` — the same
// shape as the `VARx` example in #2707's own issue body) — those get a
// "confirms the fusion, so no declaration node is produced" pinning test
// instead, which is the acceptance-surface fact the corrected comment
// actually relies on.

/// `INCLUDE../shared.ink` — no whitespace between `INCLUDE` and the file
/// path. Reachable because `.` isn't an identifier character, so `INCLUDE`
/// still lexes as `KW_INCLUDE` on its own.
#[test]
fn include_no_whitespace_after_keyword() {
    assert_equivalent(
        parse("INCLUDE../shared.ink\n"),
        cst!(SOURCE_FILE {
            INCLUDE_STMT {
                FILE_PATH
            }
        }),
    );
}

/// `IMPORT{a} FROM mod` — no whitespace between `IMPORT` and the bare-list
/// form's opening `{`. Reachable because `{` isn't an identifier character.
#[test]
fn import_no_whitespace_after_keyword() {
    assert_equivalent(
        parse("IMPORT{a} FROM mod\n"),
        cst!(SOURCE_FILE {
            IMPORT_STMT {
                IMPORT_LIST {
                    IMPORT_ITEM {
                        IDENTIFIER
                    }
                }
                IMPORT_MODULE {
                    IDENTIFIER
                }
            }
        }),
    );
}

/// `EXTERNALfoo(a)` — `EXTERNAL` and the following identifier are both
/// scanned by the same identifier-character loop, so this lexes as a
/// single `IDENT` token `EXTERNALfoo`, not `KW_EXTERNAL` + `IDENT`. No
/// `EXTERNAL_DECL` is produced — the zero-whitespace form of
/// `external_declaration`'s `INLINE_WS*` claim is real but unreachable.
#[test]
fn external_no_whitespace_keyword_fuses() {
    let src = "EXTERNALfoo(a)\n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
    assert!(
        !p.syntax()
            .descendants()
            .any(|n| n.kind() == SyntaxKind::EXTERNAL_DECL),
        "`EXTERNALfoo` should fuse into one identifier, not start an EXTERNAL_DECL"
    );
    // Confirm the identifier text really is the fused `EXTERNALfoo`, not
    // `EXTERNAL` consumed separately from a shorter `foo` name — otherwise
    // this test would pass vacuously if EXTERNAL_DECL merely failed to parse
    // for an unrelated reason.
    let ident = p
        .syntax()
        .descendants_with_tokens()
        .find_map(|e| e.into_token().filter(|t| t.kind() == SyntaxKind::IDENT))
        .expect("IDENT token not found");
    assert_eq!(ident.text(), "EXTERNALfoo");
}

/// `VARfoo = 5` — same keyword/identifier fusion as `EXTERNALfoo` above;
/// no `VAR_DECL` is produced.
#[test]
fn var_no_whitespace_keyword_fuses() {
    let src = "VARfoo = 5\n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
    assert!(
        !p.syntax()
            .descendants()
            .any(|n| n.kind() == SyntaxKind::VAR_DECL),
        "`VARfoo` should fuse into one identifier, not start a VAR_DECL"
    );
    // Confirm the identifier text really is the fused `VARfoo`, not `VAR`
    // consumed separately from a shorter `foo` name.
    let ident = p
        .syntax()
        .descendants_with_tokens()
        .find_map(|e| e.into_token().filter(|t| t.kind() == SyntaxKind::IDENT))
        .expect("IDENT token not found");
    assert_eq!(ident.text(), "VARfoo");
}

/// `CONSTfoo = 5` — same keyword/identifier fusion; no `CONST_DECL` is
/// produced.
#[test]
fn const_no_whitespace_keyword_fuses() {
    let src = "CONSTfoo = 5\n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
    assert!(
        !p.syntax()
            .descendants()
            .any(|n| n.kind() == SyntaxKind::CONST_DECL),
        "`CONSTfoo` should fuse into one identifier, not start a CONST_DECL"
    );
    // Confirm the identifier text really is the fused `CONSTfoo`, not
    // `CONST` consumed separately from a shorter `foo` name.
    let ident = p
        .syntax()
        .descendants_with_tokens()
        .find_map(|e| e.into_token().filter(|t| t.kind() == SyntaxKind::IDENT))
        .expect("IDENT token not found");
    assert_eq!(ident.text(), "CONSTfoo");
}

/// `LISTfoo = a` — same keyword/identifier fusion; no `LIST_DECL` is
/// produced.
#[test]
fn list_no_whitespace_keyword_fuses() {
    let src = "LISTfoo = a\n";
    let p = parse(src);
    assert_eq!(src, p.syntax().text().to_string(), "lossless round-trip");
    assert!(
        !p.syntax()
            .descendants()
            .any(|n| n.kind() == SyntaxKind::LIST_DECL),
        "`LISTfoo` should fuse into one identifier, not start a LIST_DECL"
    );
    // Confirm the identifier text really is the fused `LISTfoo`, not `LIST`
    // consumed separately from a shorter `foo` name.
    let ident = p
        .syntax()
        .descendants_with_tokens()
        .find_map(|e| e.into_token().filter(|t| t.kind() == SyntaxKind::IDENT))
        .expect("IDENT token not found");
    assert_eq!(ident.text(), "LISTfoo");
}