dcbor-pattern 0.11.1

Pattern matcher for dCBOR
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
mod common;

use std::collections::HashMap;

use dcbor_parse::parse_dcbor_item;
use dcbor_pattern::{
    FormatPathsOpts, Matcher, Pattern, format_paths_with_captures,
};
use indoc::indoc;

#[cfg(test)]
mod test_comprehensive_variadic_sequences {
    use super::*;

    // ============================================================================
    // PHASE 2.1: Basic Quantifiers (Greedy) - Default behavior
    // ============================================================================

    #[test]
    fn test_zero_or_more_greedy() {
        // Pattern: [(*)*] should match arrays of any length
        let pattern = Pattern::parse("[(*)*]").unwrap();

        // Test cases that should match
        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2, 3]").unwrap();

        // Empty array should match (zero repetitions)
        let (paths, captures) = pattern.paths_with_captures(&empty_array);
        assert!(!paths.is_empty(), "[(*)*] should match empty array");
        assert!(
            captures.is_empty(),
            "No captures expected for basic quantifier"
        );

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_empty = indoc! {r#"
            []
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_empty
        );

        // Single element should match (one repetition)
        let (paths, captures) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)*] should match single element array"
        );

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_single = indoc! {r#"
            [42]
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_single
        );

        // Multiple elements should match (multiple repetitions)
        let (paths, captures) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            !paths.is_empty(),
            "[(*)*] should match multiple element array"
        );

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_multiple = indoc! {r#"
            [1, 2, 3]
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_multiple
        );
    }

    #[test]
    fn test_one_or_more_greedy() {
        // Pattern: [(*)+] should match arrays with at least one element
        let pattern = Pattern::parse("[(*)+]").unwrap();

        // Test cases
        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2, 3]").unwrap();

        // Empty array should NOT match (requires at least one)
        let (paths, captures) = pattern.paths_with_captures(&empty_array);
        assert!(paths.is_empty(), "[(*)+] should NOT match empty array");
        assert!(captures.is_empty(), "No captures expected when no match");

        // Single element should match (one repetition)
        let (paths, captures) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)+] should match single element array"
        );

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_single = indoc! {r#"
            [42]
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_single
        );

        // Multiple elements should match (multiple repetitions)
        let (paths, captures) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            !paths.is_empty(),
            "[(*)+] should match multiple element array"
        );

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_multiple = indoc! {r#"
            [1, 2, 3]
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_multiple
        );
    }

    #[test]
    fn test_zero_or_one_greedy() {
        // Pattern: [(*)?] should match arrays with zero or one element
        let pattern = Pattern::parse("[(*)?]").unwrap();

        // Test cases
        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2]").unwrap();

        // Empty array should match (zero repetitions)
        let (paths, captures) = pattern.paths_with_captures(&empty_array);
        assert!(!paths.is_empty(), "[(*)?] should match empty array");

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_empty = indoc! {r#"
            []
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_empty
        );

        // Single element should match (one repetition)
        let (paths, captures) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)?] should match single element array"
        );

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_single = indoc! {r#"
            [42]
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_single
        );

        // Multiple elements should NOT match (exceeds one repetition)
        let (paths, captures) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            paths.is_empty(),
            "[(*)?] should NOT match multiple element array"
        );
        assert!(captures.is_empty(), "No captures expected when no match");
    }

    #[test]
    fn test_exactly_once_default() {
        // Pattern: [(*)] should match arrays with exactly one element
        // This tests that undecorated parentheses are interpreted as
        // RepeatPattern with "exactly one" quantifier
        let pattern = Pattern::parse("[(*)]").unwrap();

        // Test cases
        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2]").unwrap();

        // Empty array should NOT match (requires exactly one)
        let (paths, _captures) = pattern.paths_with_captures(&empty_array);
        assert!(paths.is_empty(), "[(*)] should NOT match empty array");

        // Single element should match (exactly one repetition)
        let (paths, captures) = pattern.paths_with_captures(&single_element);
        assert!(!paths.is_empty(), "[(*)] should match single element array");

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_single = indoc! {r#"
            [42]
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &captures,
                FormatPathsOpts::default()
            ),
            expected_single
        );

        // Multiple elements should NOT match (exceeds one repetition)
        let (paths, _captures) =
            pattern.paths_with_captures(&multiple_elements);
        assert!(
            paths.is_empty(),
            "[(*)] should NOT match multiple element array"
        );
    }

    // ============================================================================
    // PHASE 2.2: Lazy Quantifiers - Minimal matching
    // ============================================================================

    #[test]
    fn test_zero_or_more_lazy() {
        // Pattern: [(*)*?] should match arrays but prefer fewer repetitions
        let pattern = Pattern::parse("[(*)*?]").unwrap();

        // Test cases that should match (same as greedy for basic matching)
        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2, 3]").unwrap();

        // All arrays should match, but lazy behavior is more relevant in
        // complex patterns
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(!paths.is_empty(), "[(*)*?] should match empty array");

        let (paths, _) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)*?] should match single element array"
        );

        let (paths, _) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            !paths.is_empty(),
            "[(*)*?] should match multiple element array"
        );
    }

    #[test]
    fn test_one_or_more_lazy() {
        // Pattern: [(*)+?] should match arrays with at least one element,
        // preferring fewer
        let pattern = Pattern::parse("[(*)+?]").unwrap();

        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2, 3]").unwrap();

        // Empty array should NOT match (requires at least one)
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(paths.is_empty(), "[(*)+?] should NOT match empty array");

        // Non-empty arrays should match
        let (paths, _) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)+?] should match single element array"
        );

        let (paths, _) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            !paths.is_empty(),
            "[(*)+?] should match multiple element array"
        );
    }

    #[test]
    fn test_zero_or_one_lazy() {
        // Pattern: [(*)??] should match zero or one element, preferring zero
        let pattern = Pattern::parse("[(*)??]").unwrap();

        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2]").unwrap();

        // Should match empty and single, not multiple
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(!paths.is_empty(), "[(*)??] should match empty array");

        let (paths, _) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)??] should match single element array"
        );

        let (paths, _) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            paths.is_empty(),
            "[(*)??] should NOT match multiple element array"
        );
    }

    // ============================================================================
    // PHASE 2.3: Possessive Quantifiers - No backtracking
    // ============================================================================

    #[test]
    fn test_zero_or_more_possessive() {
        // Pattern: [(*)*+] should match arrays, no backtracking allowed
        let pattern = Pattern::parse("[(*)*+]").unwrap();

        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2, 3]").unwrap();

        // Should match all arrays (same as greedy for simple cases)
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(!paths.is_empty(), "[(*)*+] should match empty array");

        let (paths, _) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)*+] should match single element array"
        );

        let (paths, _) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            !paths.is_empty(),
            "[(*)*+] should match multiple element array"
        );
    }

    #[test]
    fn test_one_or_more_possessive() {
        // Pattern: [(*)++] should match non-empty arrays, no backtracking
        let pattern = Pattern::parse("[(*)++]").unwrap();

        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2, 3]").unwrap();

        // Empty should not match, others should
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(paths.is_empty(), "[(*)++] should NOT match empty array");

        let (paths, _) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)++] should match single element array"
        );

        let (paths, _) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            !paths.is_empty(),
            "[(*)++] should match multiple element array"
        );
    }

    #[test]
    fn test_zero_or_one_possessive() {
        // Pattern: [(*)?+] should match zero or one element, no backtracking
        let pattern = Pattern::parse("[(*)?+]").unwrap();

        let empty_array = parse_dcbor_item("[]").unwrap();
        let single_element = parse_dcbor_item("[42]").unwrap();
        let multiple_elements = parse_dcbor_item("[1, 2]").unwrap();

        // Should match zero or one, not multiple
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(!paths.is_empty(), "[(*)?+] should match empty array");

        let (paths, _) = pattern.paths_with_captures(&single_element);
        assert!(
            !paths.is_empty(),
            "[(*)?+] should match single element array"
        );

        let (paths, _) = pattern.paths_with_captures(&multiple_elements);
        assert!(
            paths.is_empty(),
            "[(*)?+] should NOT match multiple element array"
        );
    }

    // ============================================================================
    // PHASE 2.4: Interval Quantifiers - Exact count ranges
    // ============================================================================

    #[test]
    fn test_exact_count_interval() {
        // Pattern: [(*){3}] should match arrays with exactly 3 elements
        let pattern = Pattern::parse("[(*){3}]").unwrap();

        let empty_array = parse_dcbor_item("[]").unwrap();
        let two_elements = parse_dcbor_item("[1, 2]").unwrap();
        let three_elements = parse_dcbor_item("[1, 2, 3]").unwrap();
        let four_elements = parse_dcbor_item("[1, 2, 3, 4]").unwrap();

        // Only exactly 3 elements should match
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(paths.is_empty(), "[(*){{3}}] should NOT match empty array");

        let (paths, _) = pattern.paths_with_captures(&two_elements);
        assert!(
            paths.is_empty(),
            "[(*){{3}}] should NOT match 2-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&three_elements);
        assert!(!paths.is_empty(), "[(*){{3}}] should match 3-element array");

        // expected-text-output-rubric:
        #[rustfmt::skip]
        let expected_three = indoc! {r#"
            [1, 2, 3]
        "#}.trim();

        assert_actual_expected!(
            format_paths_with_captures(
                &paths,
                &HashMap::new(),
                FormatPathsOpts::default()
            ),
            expected_three
        );

        let (paths, _) = pattern.paths_with_captures(&four_elements);
        assert!(
            paths.is_empty(),
            "[(*){{3}}] should NOT match 4-element array"
        );
    }

    #[test]
    fn test_range_interval() {
        // Pattern: [(*){2,4}] should match arrays with 2-4 elements
        let pattern = Pattern::parse("[(*){2,4}]").unwrap();

        let one_element = parse_dcbor_item("[1]").unwrap();
        let two_elements = parse_dcbor_item("[1, 2]").unwrap();
        let three_elements = parse_dcbor_item("[1, 2, 3]").unwrap();
        let four_elements = parse_dcbor_item("[1, 2, 3, 4]").unwrap();
        let five_elements = parse_dcbor_item("[1, 2, 3, 4, 5]").unwrap();

        // Only 2-4 elements should match
        let (paths, _) = pattern.paths_with_captures(&one_element);
        assert!(
            paths.is_empty(),
            "[(*){{2,4}}] should NOT match 1-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&two_elements);
        assert!(
            !paths.is_empty(),
            "[(*){{2,4}}] should match 2-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&three_elements);
        assert!(
            !paths.is_empty(),
            "[(*){{2,4}}] should match 3-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&four_elements);
        assert!(
            !paths.is_empty(),
            "[(*){{2,4}}] should match 4-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&five_elements);
        assert!(
            paths.is_empty(),
            "[(*){{2,4}}] should NOT match 5-element array"
        );
    }

    #[test]
    fn test_minimum_interval() {
        // Pattern: [(*){2,}] should match arrays with at least 2 elements
        let pattern = Pattern::parse("[(*){2,}]").unwrap();

        let one_element = parse_dcbor_item("[1]").unwrap();
        let two_elements = parse_dcbor_item("[1, 2]").unwrap();
        let five_elements = parse_dcbor_item("[1, 2, 3, 4, 5]").unwrap();

        // At least 2 elements should match
        let (paths, _) = pattern.paths_with_captures(&one_element);
        assert!(
            paths.is_empty(),
            "[(*){{2,}}] should NOT match 1-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&two_elements);
        assert!(
            !paths.is_empty(),
            "[(*){{2,}}] should match 2-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&five_elements);
        assert!(
            !paths.is_empty(),
            "[(*){{2,}}] should match 5-element array"
        );
    }

    #[test]
    fn test_maximum_interval() {
        // Pattern: [(*){0,3}] should match arrays with at most 3 elements
        let pattern = Pattern::parse("[(*){0,3}]").unwrap();

        let empty_array = parse_dcbor_item("[]").unwrap();
        let two_elements = parse_dcbor_item("[1, 2]").unwrap();
        let three_elements = parse_dcbor_item("[1, 2, 3]").unwrap();
        let four_elements = parse_dcbor_item("[1, 2, 3, 4]").unwrap();

        // At most 3 elements should match
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(!paths.is_empty(), "[(*){{0,3}}] should match empty array");

        let (paths, _) = pattern.paths_with_captures(&two_elements);
        assert!(
            !paths.is_empty(),
            "[(*){{0,3}}] should match 2-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&three_elements);
        assert!(
            !paths.is_empty(),
            "[(*){{0,3}}] should match 3-element array"
        );

        let (paths, _) = pattern.paths_with_captures(&four_elements);
        assert!(
            paths.is_empty(),
            "[(*){{0,3}}] should NOT match 4-element array"
        );
    }

    // ============================================================================
    // PHASE 2.5: Complex Scenarios - Combinations and edge cases
    // ============================================================================

    #[test]
    fn test_quantifiers_with_captures() {
        // Test: [(number)*, @item(text)]
        // This should match arrays with zero or more numbers followed by a
        // captured text
        let pattern = Pattern::parse("[(number)*, @item(text)]").unwrap();

        let numbers_then_text = parse_dcbor_item(r#"[1, 2, "hello"]"#).unwrap();
        let only_text = parse_dcbor_item(r#"["hello"]"#).unwrap();
        let only_numbers = parse_dcbor_item("[1, 2]").unwrap();

        // Numbers then text should match and capture the text
        let (paths, captures) = pattern.paths_with_captures(&numbers_then_text);
        assert!(
            !paths.is_empty(),
            "[(number)*, @item(text)] should match numbers then text"
        );

        // Should have captured the text item
        assert!(captures.contains_key("item"), "Should have @item capture");

        // Only text should match (zero numbers, one text)
        let (paths, captures) = pattern.paths_with_captures(&only_text);
        assert!(
            !paths.is_empty(),
            "[(number)*, @item(text)] should match only text"
        );
        assert!(
            captures.contains_key("item"),
            "Should have @item capture for text-only"
        );

        // Only numbers should NOT match (missing required text)
        let (paths, captures) = pattern.paths_with_captures(&only_numbers);
        assert!(
            paths.is_empty(),
            "[(number)*, @item(text)] should NOT match only numbers"
        );
        assert!(captures.is_empty(), "Should have no captures when no match");

        // Test another pattern: [@first(number), (*)*]
        // This captures the first number and allows any additional elements
        let first_capture_pattern =
            Pattern::parse("[@first(number), (*)*]").unwrap();

        let multi_element = parse_dcbor_item(r#"[42, "text", true]"#).unwrap();
        let (paths, captures) =
            first_capture_pattern.paths_with_captures(&multi_element);

        assert!(
            !paths.is_empty(),
            "[@first(number), (*)*] should match multi-element array"
        );
        assert!(
            captures.contains_key("first"),
            "Should capture the first number"
        );

        // Verify the captured value
        if let Some(first_captures) = captures.get("first") {
            assert_eq!(
                first_captures.len(),
                1,
                "Should capture exactly one first element"
            );
        }
    }

    #[test]
    fn test_multiple_quantifiers_in_pattern() {
        // Pattern: [(number)*, (text)+] should match arrays with zero+ numbers
        // followed by one+ texts
        let pattern = Pattern::parse("[(number)*, (text)+]").unwrap();

        let numbers_then_texts =
            parse_dcbor_item(r#"[1, 2, "a", "b"]"#).unwrap();
        let only_texts = parse_dcbor_item(r#"["a", "b"]"#).unwrap();
        let only_numbers = parse_dcbor_item("[1, 2]").unwrap();
        let empty_array = parse_dcbor_item("[]").unwrap();

        // Numbers then texts should match
        let (paths, _) = pattern.paths_with_captures(&numbers_then_texts);
        assert!(
            !paths.is_empty(),
            "[(number)*, (text)+] should match numbers then texts"
        );

        // Only texts should match (zero numbers, one+ texts)
        let (paths, _) = pattern.paths_with_captures(&only_texts);
        assert!(
            !paths.is_empty(),
            "[(number)*, (text)+] should match only texts"
        );

        // Only numbers should NOT match (missing required texts)
        let (paths, _) = pattern.paths_with_captures(&only_numbers);
        assert!(
            paths.is_empty(),
            "[(number)*, (text)+] should NOT match only numbers"
        );

        // Empty should NOT match (missing required texts)
        let (paths, _) = pattern.paths_with_captures(&empty_array);
        assert!(
            paths.is_empty(),
            "[(number)*, (text)+] should NOT match empty array"
        );
    }
}