aver-lang 0.18.0

VM and transpiler for Aver, a statically-typed language designed for AI-assisted development
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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
use std::collections::BTreeSet;

use crate::ast::{Expr, FnDef, Literal, Pattern, TopLevel};
use crate::call_graph::find_recursive_fns;
use crate::types::Type;
use crate::types::parse_type_str_strict;

use super::{
    CheckFinding, collect_target_call_args, constructor_tag_from_expr, expr_is_bool_case,
    expr_is_empty_list_case, expr_is_empty_string_case, expr_is_int_literal_case,
    expr_is_non_empty_list_case, expr_is_option_none_case, expr_is_option_some_case,
    expr_is_result_err_case, expr_is_result_ok_case, local_sum_type_constructors,
    merge_verify_blocks, module_name_for_items, verify_cases_block_is_well_formed,
};

fn direct_match_target(f: &FnDef) -> Option<(usize, &[crate::ast::MatchArm])> {
    let Expr::Match { subject, arms, .. } = &f.body.tail_expr()?.node else {
        return None;
    };
    let Expr::Ident(subject_name) = &subject.node else {
        return None;
    };
    let param_index = f.params.iter().position(|(name, _)| name == subject_name)?;
    Some((param_index, arms.as_slice()))
}

fn enum_match_coverage_target(f: &FnDef) -> Option<(usize, Vec<String>)> {
    let (param_index, arms) = direct_match_target(f)?;
    let constructors: BTreeSet<String> = arms
        .iter()
        .filter_map(|arm| super::constructor_tag_from_pattern(&arm.pattern))
        .collect();
    if constructors.is_empty() {
        None
    } else {
        Some((param_index, constructors.into_iter().collect()))
    }
}

fn bool_match_coverage_target(f: &FnDef) -> Option<usize> {
    let (param_index, arms) = direct_match_target(f)?;
    let (_, param_ty) = f.params.get(param_index)?;
    let Ok(Type::Bool) = parse_type_str_strict(param_ty) else {
        return None;
    };
    arms.iter()
        .any(|arm| matches!(arm.pattern, Pattern::Literal(Literal::Bool(_))))
        .then_some(param_index)
}

fn list_match_coverage_target(f: &FnDef) -> Option<usize> {
    let (param_index, arms) = direct_match_target(f)?;
    let (_, param_ty) = f.params.get(param_index)?;
    let Ok(Type::List(_)) = parse_type_str_strict(param_ty) else {
        return None;
    };
    arms.iter()
        .any(|arm| matches!(arm.pattern, Pattern::EmptyList | Pattern::Cons(_, _)))
        .then_some(param_index)
}

pub fn collect_verify_coverage_warnings(items: &[TopLevel]) -> Vec<CheckFinding> {
    collect_verify_coverage_warnings_in(items, None)
}

pub fn collect_verify_coverage_warnings_in(
    items: &[TopLevel],
    source_file: Option<&str>,
) -> Vec<CheckFinding> {
    let module_name = module_name_for_items(items);
    let recursive_fns = find_recursive_fns(items);
    let fn_defs: std::collections::HashMap<&str, &FnDef> = items
        .iter()
        .filter_map(|item| {
            if let TopLevel::FnDef(f) = item {
                Some((f.name.as_str(), f))
            } else {
                None
            }
        })
        .collect();

    let mut warnings = Vec::new();
    for block in merge_verify_blocks(items) {
        if !verify_cases_block_is_well_formed(&block) {
            continue;
        }
        // Verify-trace blocks route RHS through oracle-bound stubs:
        // `target().result => stub(path, k, args)`. Syntactically the RHS
        // is a FnCall to the stub, not a Result.Ok/.Err or Option
        // constructor — but the stub *does* produce those values at run
        // time. Coverage heuristics here are pure syntactic shape checks,
        // so skip them for trace blocks to avoid spurious "no Result.Ok"
        // warnings on correctly-written verify-trace examples.
        if block.trace {
            continue;
        }
        let Some(f) = fn_defs.get(block.fn_name.as_str()).copied() else {
            continue;
        };

        if let Ok(ret_ty) = parse_type_str_strict(&f.return_type) {
            if matches!(ret_ty, Type::Result(_, _))
                && !block
                    .cases
                    .iter()
                    .any(|(_, right)| expr_is_result_ok_case(right))
            {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not include any Result.Ok case",
                        block.fn_name
                    ),
                    extra_spans: vec![],
                });
            }

            if matches!(ret_ty, Type::Result(_, _))
                && !block
                    .cases
                    .iter()
                    .any(|(_, right)| expr_is_result_err_case(right))
            {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not include any Result.Err case",
                        block.fn_name
                    ),
                    extra_spans: vec![],
                });
            }

            if matches!(ret_ty, Type::Option(_))
                && !block
                    .cases
                    .iter()
                    .any(|(_, right)| expr_is_option_some_case(right))
            {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not include any Option.Some case",
                        block.fn_name
                    ),
                    extra_spans: vec![],
                });
            }

            if matches!(ret_ty, Type::Option(_))
                && !block
                    .cases
                    .iter()
                    .any(|(_, right)| expr_is_option_none_case(right))
            {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not include any Option.None case",
                        block.fn_name
                    ),
                    extra_spans: vec![],
                });
            }

            if matches!(ret_ty, Type::Bool)
                && !block
                    .cases
                    .iter()
                    .any(|(_, right)| expr_is_bool_case(right, true))
            {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not include any `true` result",
                        block.fn_name
                    ),
                    extra_spans: vec![],
                });
            }

            if matches!(ret_ty, Type::Bool)
                && !block
                    .cases
                    .iter()
                    .any(|(_, right)| expr_is_bool_case(right, false))
            {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not include any `false` result",
                        block.fn_name
                    ),
                    extra_spans: vec![],
                });
            }

            if let Type::Named(type_name) = ret_ty
                && let Some(constructors) = local_sum_type_constructors(items, &type_name)
            {
                let mut covered = BTreeSet::new();
                for (_, right) in &block.cases {
                    if let Some(tag) = constructor_tag_from_expr(right)
                        && constructors.contains(&tag)
                    {
                        covered.insert(tag);
                    }
                }
                if covered.len() < constructors.len() {
                    warnings.push(CheckFinding {
                        line: block.line,
                        module: module_name.clone(),
                        file: source_file.map(|s| s.to_string()),
                        fn_name: None,
                        message: format!(
                            "verify examples for {} cover {}/{} output constructors",
                            block.fn_name,
                            covered.len(),
                            constructors.len()
                        ),
                        extra_spans: vec![],
                    });
                }
            }
        }

        if let Some((param_index, constructors)) = enum_match_coverage_target(f) {
            let mut covered = BTreeSet::new();
            for (left, _) in &block.cases {
                let mut args = Vec::new();
                collect_target_call_args(left, &block.fn_name, param_index, &mut args);
                for arg in args {
                    if let Some(tag) = constructor_tag_from_expr(arg)
                        && constructors.contains(&tag)
                    {
                        covered.insert(tag);
                    }
                }
            }
            if covered.len() < constructors.len() {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} cover {}/{} enum constructors",
                        block.fn_name,
                        covered.len(),
                        constructors.len()
                    ),
                    extra_spans: vec![],
                });
            }
        }

        if let Some(param_index) = bool_match_coverage_target(f) {
            let param_name = &f.params[param_index].0;
            let mut args = Vec::new();
            for (left, _) in &block.cases {
                collect_target_call_args(left, &block.fn_name, param_index, &mut args);
            }
            if !args.iter().any(|arg| expr_is_bool_case(arg, true)) {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not cover `{}` = `true`",
                        block.fn_name, param_name
                    ),
                    extra_spans: vec![],
                });
            }
            if !args.iter().any(|arg| expr_is_bool_case(arg, false)) {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not cover `{}` = `false`",
                        block.fn_name, param_name
                    ),
                    extra_spans: vec![],
                });
            }
        }

        if let Some(param_index) = list_match_coverage_target(f) {
            let param_name = &f.params[param_index].0;
            let mut args = Vec::new();
            for (left, _) in &block.cases {
                collect_target_call_args(left, &block.fn_name, param_index, &mut args);
            }
            if !args.iter().any(|arg| expr_is_empty_list_case(arg)) {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not cover empty list input for `{}`",
                        block.fn_name, param_name
                    ),
                    extra_spans: vec![],
                });
            }
            if !args.iter().any(|arg| expr_is_non_empty_list_case(arg)) {
                warnings.push(CheckFinding {
                    line: block.line,
                    module: module_name.clone(),
                    file: source_file.map(|s| s.to_string()),
                    fn_name: None,
                    message: format!(
                        "verify examples for {} do not cover non-empty list input for `{}`",
                        block.fn_name, param_name
                    ),
                    extra_spans: vec![],
                });
            }
        }

        if recursive_fns.contains(&block.fn_name) && f.params.len() == 1 {
            let (param_name, param_ty) = &f.params[0];
            let Ok(param_ty) = parse_type_str_strict(param_ty) else {
                continue;
            };
            let mut args = Vec::new();
            for (left, _) in &block.cases {
                collect_target_call_args(left, &block.fn_name, 0, &mut args);
            }

            match param_ty {
                Type::Int => {
                    let has_zero = args.iter().any(|arg| expr_is_int_literal_case(arg, 0));
                    let has_one = args.iter().any(|arg| expr_is_int_literal_case(arg, 1));
                    if !has_zero && !has_one {
                        warnings.push(CheckFinding {
                                line: block.line,
                                module: module_name.clone(),
                                file: source_file.map(|s| s.to_string()),
                                fn_name: None,
                                message: format!(
                                    "verify examples for recursive function {} may not include a numeric base-case input for `{}` (`0` or `1`)",
                                    block.fn_name, param_name
                                ),
                                extra_spans: vec![],
                            });
                    }
                }
                Type::List(_) if !args.iter().any(|arg| expr_is_empty_list_case(arg)) => {
                    warnings.push(CheckFinding {
                                line: block.line,
                                module: module_name.clone(),
                                file: source_file.map(|s| s.to_string()),
                                fn_name: None,
                                message: format!(
                                    "verify examples for recursive function {} may not include an empty list input for `{}`",
                                    block.fn_name, param_name
                                ),
                                extra_spans: vec![],
                            });
                }
                Type::Str if !args.iter().any(|arg| expr_is_empty_string_case(arg)) => {
                    warnings.push(CheckFinding {
                                line: block.line,
                                module: module_name.clone(),
                                file: source_file.map(|s| s.to_string()),
                                fn_name: None,
                                message: format!(
                                    "verify examples for recursive function {} may not include an empty string input for `{}`",
                                    block.fn_name, param_name
                                ),
                                extra_spans: vec![],
                            });
                }
                _ => {}
            }
        }

        let parser_like = f.name.starts_with("parse") || f.name == "fromString";
        if parser_like {
            let Ok(ret_ty) = parse_type_str_strict(&f.return_type) else {
                continue;
            };
            if matches!(ret_ty, Type::Result(_, _) | Type::Option(_))
                && let Some((param_name, param_ty)) = f.params.first()
            {
                let Ok(Type::Str) = parse_type_str_strict(param_ty) else {
                    continue;
                };
                let mut args = Vec::new();
                for (left, _) in &block.cases {
                    collect_target_call_args(left, &block.fn_name, 0, &mut args);
                }
                if !args.iter().any(|arg| expr_is_empty_string_case(arg)) {
                    warnings.push(CheckFinding {
                        line: block.line,
                        module: module_name.clone(),
                        file: source_file.map(|s| s.to_string()),
                        fn_name: None,
                        message: format!(
                            "verify examples for {} may not include an empty string input for `{}`",
                            block.fn_name, param_name
                        ),
                        extra_spans: vec![],
                    });
                }
            }
        }
    }

    warnings
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::lexer::Lexer;
    use crate::parser::Parser;

    fn parse_items(src: &str) -> Vec<TopLevel> {
        let mut lexer = Lexer::new(src);
        let tokens = lexer.tokenize().expect("lex failed");
        let mut parser = Parser::new(tokens);
        parser.parse().expect("parse failed")
    }

    #[test]
    fn coverage_warns_when_result_verify_has_no_err_example() {
        let items = parse_items(
            r#"
fn mayFail(n: Int) -> Result<Int, String>
    match n
        0 -> Result.Err("zero")
        _ -> Result.Ok(n)

verify mayFail
    mayFail(1) => Result.Ok(1)
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message == "verify examples for mayFail do not include any Result.Err case"
            }),
            "expected missing-err warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_result_verify_has_no_ok_example() {
        let items = parse_items(
            r#"
fn alwaysFail(n: Int) -> Result<Int, String>
    Result.Err("nope")

verify alwaysFail
    alwaysFail(1) => Result.Err("nope")
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message == "verify examples for alwaysFail do not include any Result.Ok case"
            }),
            "expected missing-ok warning, got {:?}",
            warnings
        );
        assert!(
            warnings.iter().any(|w| w.line == 5),
            "expected verify-block line number, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_option_verify_has_no_none_example() {
        let items = parse_items(
            r#"
fn maybe(n: Int) -> Option<Int>
    match n
        0 -> Option.None
        _ -> Option.Some(n)

verify maybe
    maybe(1) => Option.Some(1)
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message == "verify examples for maybe do not include any Option.None case"
            }),
            "expected missing-none warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_option_verify_has_no_some_example() {
        let items = parse_items(
            r#"
fn nope(n: Int) -> Option<Int>
    Option.None

verify nope
    nope(1) => Option.None
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message == "verify examples for nope do not include any Option.Some case"
            }),
            "expected missing-some warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_bool_verify_has_only_one_result_shape() {
        let items = parse_items(
            r#"
fn isZero(n: Int) -> Bool
    n == 0

verify isZero
    isZero(0) => true
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(
                |w| w.message == "verify examples for isZero do not include any `false` result"
            ),
            "expected missing-false warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_sum_output_constructors_are_partial() {
        let items = parse_items(
            r#"
type Outcome
    Win(String)
    Lose(String)
    Continue

fn classify(n: Int) -> Outcome
    match n
        0 -> Outcome.Continue
        1 -> Outcome.Win("yay")
        _ -> Outcome.Lose("no")

verify classify
    classify(0) => Outcome.Continue
    classify(1) => Outcome.Win("yay")
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message == "verify examples for classify cover 2/3 output constructors"
            }),
            "expected output-constructor coverage warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_enum_match_examples_cover_subset_of_constructors() {
        let items = parse_items(
            r#"
type Input
    Help
    Exit
    Echo(String)

fn dispatch(input: Input) -> String
    match input
        Input.Help -> "help"
        Input.Exit -> "exit"
        Input.Echo(value) -> value

verify dispatch
    dispatch(Input.Help) => "help"
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings
                .iter()
                .any(|w| w.message == "verify examples for dispatch cover 1/3 enum constructors"),
            "expected enum-coverage warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_bool_match_input_examples_miss_a_branch() {
        let items = parse_items(
            r#"
fn flagName(flag: Bool) -> String
    match flag
        true -> "yes"
        false -> "no"

verify flagName
    flagName(true) => "yes"
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings
                .iter()
                .any(|w| w.message == "verify examples for flagName do not cover `flag` = `false`"),
            "expected bool-input coverage warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_warns_when_list_match_input_examples_miss_empty_case() {
        let items = parse_items(
            r#"
fn headOrZero(xs: List<Int>) -> Int
    match xs
        [] -> 0
        [head, ..tail] -> head

verify headOrZero
    headOrZero([1, 2]) => 1
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message == "verify examples for headOrZero do not cover empty list input for `xs`"
            }),
            "expected empty-list coverage warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_merges_multiple_verify_blocks_before_checking_shapes() {
        let items = parse_items(
            r#"
fn maybe(n: Int) -> Option<Int>
    match n
        0 -> Option.None
        _ -> Option.Some(n)

verify maybe
    maybe(0) => Option.None

verify maybe
    maybe(1) => Option.Some(1)
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            !warnings.iter().any(|w| w.message.contains("Option.None"))
                && !warnings.iter().any(|w| w.message.contains("Option.Some")),
            "expected merged verify blocks to satisfy coverage, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_soft_warns_when_recursive_int_fn_has_no_zero_or_one_example() {
        let items = parse_items(
            r#"
fn fib(n: Int) -> Int
    match n == 0
        true -> 0
        false -> match n == 1
            true -> 1
            false -> fib(n - 1) + fib(n - 2)

verify fib
    fib(5) => 5
    fib(6) => 8
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message == "verify examples for recursive function fib may not include a numeric base-case input for `n` (`0` or `1`)"
            }),
            "expected recursive boundary warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_soft_warns_when_recursive_list_fn_has_no_empty_input_example() {
        let items = parse_items(
            r#"
fn sum(xs: List<Int>) -> Int
    match xs
        [] -> 0
        [head, ..tail] -> head + sum(tail)

verify sum
    sum([1, 2, 3]) => 6
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message
                    == "verify examples for recursive function sum may not include an empty list input for `xs`"
            }),
            "expected recursive empty-list warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_soft_warns_when_parser_like_fn_has_no_empty_string_example() {
        let items = parse_items(
            r#"
fn fromString(s: String) -> Result<Int, String>
    match s == ""
        true -> Result.Err("empty")
        false -> Result.Ok(1)

verify fromString
    fromString("42") => Result.Ok(1)
    fromString("x") => Result.Err("empty")
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            warnings.iter().any(|w| {
                w.message
                    == "verify examples for fromString may not include an empty string input for `s`"
            }),
            "expected parser empty-string warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_soft_does_not_warn_when_recursive_base_case_is_split_across_verify_blocks() {
        let items = parse_items(
            r#"
fn fib(n: Int) -> Int
    match n == 0
        true -> 0
        false -> match n == 1
            true -> 1
            false -> fib(n - 1) + fib(n - 2)

verify fib
    fib(0) => 0

verify fib
    fib(5) => 5
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(
            !warnings
                .iter()
                .any(|w| w.message.contains("numeric base-case input")),
            "expected merged verify blocks to silence recursive boundary warning, got {:?}",
            warnings
        );
    }

    #[test]
    fn coverage_does_not_warn_when_enum_and_output_examples_are_present() {
        let items = parse_items(
            r#"
type Input
    Help
    Exit

fn run(input: Input) -> Result<String, String>
    match input
        Input.Help -> Result.Ok("help")
        Input.Exit -> Result.Err("exit")

verify run
    run(Input.Help) => Result.Ok("help")
    run(Input.Exit) => Result.Err("exit")
"#,
        );
        let warnings = collect_verify_coverage_warnings(&items);
        assert!(warnings.is_empty(), "unexpected warnings: {:?}", warnings);
    }
}