summaryrefslogtreecommitdiff
path: root/crates/tor-netdoc/src/test2.rs
blob: cdbd20293471fa9b9851c700bb0886fd6593e25b (plain)
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
// @@ begin test lint list maintained by maint/add_warning @@
#![allow(clippy::bool_assert_comparison)]
#![allow(clippy::clone_on_copy)]
#![allow(clippy::dbg_macro)]
#![allow(clippy::mixed_attributes_style)]
#![allow(clippy::print_stderr)]
#![allow(clippy::print_stdout)]
#![allow(clippy::single_char_pattern)]
#![allow(clippy::unwrap_used)]
#![allow(clippy::unchecked_time_subtraction)]
#![allow(clippy::useless_vec)]
#![allow(clippy::needless_pass_by_value)]
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
#![allow(clippy::needless_borrows_for_generic_args)] // TODO add to maint/add_warning

use std::fmt::Debug;

use anyhow::Context as _;
use derive_deftly::Deftly;
use testresult::TestResult;
use tor_error::ErrorReport as _;

use crate::parse2::{
    ArgumentError as P2AE, ArgumentStream, ErrorProblem as P2EP, ItemObjectParseable,
    NetdocParseable, NetdocParseableFields, ParseError, ParseInput, UnparsedItem, parse_netdoc,
    parse_netdoc_multiple,
};
use crate::types::{Ignored, NotPresent};

fn default<T: Default>() -> T {
    Default::default()
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseable)]
struct Top {
    top_intro: (),
    needed: (String,),
    optional: Option<(String,)>,
    several: Vec<(String,)>,
    not_present: NotPresent,
    #[deftly(netdoc(default))]
    defaulted: (String,),
    #[deftly(netdoc(keyword = "renamed"))]
    t4_renamed: Option<(String,)>,
    #[deftly(netdoc(subdoc))]
    sub1: Sub1,
    #[deftly(netdoc(subdoc))]
    sub2: Option<Sub2>,
    #[deftly(netdoc(subdoc))]
    sub3: Vec<Sub3>,
    #[deftly(netdoc(subdoc, default))]
    sub4: Sub4,
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseable)]
struct Sub1 {
    sub1_intro: (),
    sub1_field: Option<(String,)>,
    #[deftly(netdoc(flatten))]
    flatten: Flat1,
}
#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseableFields)]
struct Flat1 {
    flat_needed: (String,),
    flat_optional: Option<(String,)>,
    flat_several: Vec<(String,)>,
    flat_defaulted: Option<(String,)>,
    #[deftly(netdoc(single_arg))]
    flat_arg_needed: String,
    #[deftly(netdoc(single_arg))]
    flat_arg_optional: Option<String>,
    #[deftly(netdoc(single_arg))]
    flat_arg_several: Vec<String>,
    #[deftly(netdoc(single_arg, default))]
    flat_arg_defaulted: String,
    #[deftly(netdoc(with = "needs_with_parse"))]
    flat_with_needed: NeedsWith,
    #[deftly(netdoc(with = "needs_with_parse"))]
    flat_with_optional: Option<NeedsWith>,
    #[deftly(netdoc(with = "needs_with_parse"))]
    flat_with_several: Vec<NeedsWith>,
    #[deftly(netdoc(flatten))]
    flat_flat: FlatInner,
}
#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseableFields)]
struct FlatInner {
    flat_inner_optional: Option<(String,)>,
}
#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseable)]
struct Sub2 {
    #[deftly(netdoc(with = "needs_with_intro"))]
    sub2_intro: NeedsWith,
    sub2_field: Option<(String,)>,
    #[deftly(netdoc(single_arg))]
    arg_needed: String,
    #[deftly(netdoc(single_arg))]
    arg_optional: Option<String>,
    #[deftly(netdoc(single_arg))]
    arg_several: Vec<String>,
    #[deftly(netdoc(single_arg, default))]
    arg_defaulted: String,
    #[deftly(netdoc(with = "needs_with_parse"))]
    with_needed: NeedsWith,
    #[deftly(netdoc(with = "needs_with_parse"))]
    with_optional: Option<NeedsWith>,
    #[deftly(netdoc(with = "needs_with_parse"))]
    with_several: Vec<NeedsWith>,
    #[deftly(netdoc(subdoc))]
    subsub: SubSub,
}
#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseable)]
struct Sub3 {
    sub3_intro: (),
    sub3_field: Option<(String,)>,
}
#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseable)]
struct Sub4 {
    sub4_intro: (),
    sub4_field: Option<(String,)>,
}
#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseable)]
struct SubSub {
    #[deftly(netdoc(single_arg))]
    subsub_intro: String,
    subsub_field: Option<(String,)>,
}

#[derive(Debug, Default, Clone, Eq, PartialEq)]
struct NeedsWith;

impl NeedsWith {
    fn parse_expecting(exp: &str, args: &mut ArgumentStream<'_>) -> Result<NeedsWith, P2AE> {
        let got = args.next().ok_or(P2AE::Missing)?;
        (got == exp).then_some(NeedsWith).ok_or(P2AE::Invalid)
    }
}

mod needs_with_parse {
    use super::*;
    pub(super) fn from_unparsed(mut item: UnparsedItem<'_>) -> Result<NeedsWith, P2EP> {
        NeedsWith::parse_expecting("normal", item.args_mut())
            .map_err(item.args().error_handler("in needs with"))
    }
}
mod needs_with_intro {
    use super::*;
    pub(super) fn from_unparsed(mut item: UnparsedItem<'_>) -> Result<NeedsWith, P2EP> {
        NeedsWith::parse_expecting("intro", item.args_mut())
            .map_err(item.args().error_handler("in needs with"))
    }
}
mod needs_with_arg {
    use super::*;
    pub(super) fn from_args(args: &mut ArgumentStream) -> Result<NeedsWith, P2AE> {
        NeedsWith::parse_expecting("arg", args)
    }
    pub(super) fn from_rest(s: &str) -> Result<NeedsWith, ()> {
        (s == "rest of line").then_some(NeedsWith).ok_or(())
    }
}

fn t_ok<D>(doc: &str, exp: &[D]) -> TestResult<()>
where
    D: NetdocParseable + Debug + PartialEq,
{
    let input = ParseInput::new(doc, "<literal>");

    if exp.len() == 1 {
        let got = parse_netdoc::<D>(&input).context(doc.to_owned())?;
        assert_eq!(got, exp[0], "doc={doc}");
    }

    let got = parse_netdoc_multiple::<D>(&input)?;
    assert_eq!(got, exp, "doc={doc}");
    Ok(())
}

#[allow(clippy::unnecessary_wraps)] // Result for consistency
fn t_err_raw<D>(
    exp_lno: usize,
    exp_col: Option<usize>,
    exp_err: &str,
    doc: &str,
) -> TestResult<ParseError>
where
    D: NetdocParseable + Debug,
{
    let input = ParseInput::new(doc, "<massaged>");
    let got = parse_netdoc::<D>(&input).expect_err("unexpectedly parsed ok");
    let got_err = got.problem.to_string();
    assert_eq!(
        (got.lno, got.column),
        (exp_lno, exp_col),
        "doc\n====\n{doc}====\n got={}\n exp={exp_err}",
        got_err
    );
    assert_eq!(
        got_err, exp_err,
        "doc\n====\n{doc}====\n got={}\n exp={exp_err}",
        got_err
    );
    Ok(got)
}

/// Test an error case with embedded error message
///
/// `case` should be the input document, but exactly one line should
/// contain `" # "`, with the expected error message as a "comment".
///
/// Iff the expected message is supposed to have a column number,
/// the comment part should end with ` @<column>`.
///
/// `t_err` will check that that error is reported, at that line.
fn t_err<D>(mut case: &str) -> TestResult<ParseError>
where
    D: NetdocParseable + Debug,
{
    let mut exp = None;
    let mut doc = String::new();
    let mut lno = 0;
    while let Some((l, r)) = case.split_once('\n') {
        lno += 1;
        case = r;
        if let Some((l, r)) = l.split_once(" # ") {
            assert!(exp.is_none());
            exp = Some((lno, r.trim()));
            let l = l.trim_end();
            doc += l;
        } else {
            doc += l;
        }
        doc += "\n";
    }
    if !case.is_empty() {
        panic!("missing final newline");
    }
    let (exp_lno, exp_err) = exp.expect("missing # error indication in test case");
    let (exp_err, exp_col) = if let Some((l, r)) = exp_err.rsplit_once(" @") {
        (l, Some(r.parse().unwrap()))
    } else {
        (exp_err, None)
    };
    println!("==== 8<- ====\n{doc}==== ->8 ====");
    t_err_raw::<D>(exp_lno, exp_col, exp_err, &doc)
}

/// Test an error case with embedded error message
///
/// `case` should be the input document, but exactly one line should
/// contain `" # "`, with the expected error message as a "comment".
///
/// Iff the expected message is supposed to have a column number,
/// the comment part should end with ` @<column>`.
///
/// `t_err` will check that that error is reported, at that column.
fn t_err_chk_msg<D>(case: &str, msg: &str) -> TestResult
where
    D: NetdocParseable + Debug,
{
    let err = t_err::<D>(case)?;
    assert_eq!(err.report().to_string(), msg);
    Ok(())
}

#[test]
fn various_docs() -> TestResult<()> {
    let val = |s: &str| (s.to_owned(),);
    let sval = |s: &str| Some(val(s));

    let sub1_minimal = Sub1 {
        flatten: Flat1 {
            flat_needed: val("FN"),
            flat_arg_needed: "FAN".into(),
            ..default()
        },
        ..default()
    };
    let subsub_minimal = SubSub {
        subsub_intro: "SSI".into(),
        ..default()
    };
    let sub2_minimal = Sub2 {
        arg_needed: "AN".into(),
        subsub: subsub_minimal.clone(),
        ..default()
    };

    t_ok(
        r#"top-intro
needed N
sub1-intro
flat-needed FN
flat-arg-needed FAN
flat-with-needed normal
"#,
        &[Top {
            needed: val("N"),
            sub1: sub1_minimal.clone(),
            ..default()
        }],
    )?;

    t_ok(
        r#"top-intro
needed N
sub1-intro
flat-needed FN
flat-arg-needed FAN
flat-with-needed normal
sub2-intro intro
with-needed normal
arg-needed AN
subsub-intro SSI
sub3-intro
sub3-intro
sub4-intro
"#,
        &[Top {
            needed: val("N"),
            sub1: sub1_minimal.clone(),
            sub2: Some(sub2_minimal.clone()),
            sub3: vec![default(); 2],
            ..default()
        }],
    )?;

    t_ok(
        r#"top-intro
needed N
optional O
several 1
not-present oh yes it is
not-present but it is ignored
several 2
defaulted D
renamed R
sub1-intro
flat-several FS1
flat-needed FN
flat-with-needed normal
flat-inner-optional nested
sub1-field A
flat-with-several normal
flat-with-several normal
flat-optional FO
flat-arg-needed FAN
flat-with-optional normal
flat-several FS2
flat-defaulted FD
flat-arg-optional FAO
flat-arg-several FAS1 ignored
flat-arg-several FAS2
flat-arg-defaulted FAD
sub2-intro intro
with-several normal
with-several normal
with-several normal
sub2-field B
arg-needed AN
arg-optional AO
with-optional normal
arg-defaulted AD
arg-several A1
arg-several A2
with-needed normal
subsub-intro SSI
subsub-field BS
sub3-intro
sub3-field C1
sub3-intro
sub3-field C2
sub4-intro
sub4-field D
"#,
        &[Top {
            needed: val("N"),
            optional: sval("O"),
            several: ["1", "2"].map(val).into(),
            defaulted: val("D"),
            t4_renamed: sval("R"),
            sub1: Sub1 {
                sub1_field: sval("A"),
                flatten: Flat1 {
                    flat_needed: val("FN"),
                    flat_optional: sval("FO"),
                    flat_several: ["FS1", "FS2"].map(val).into(),
                    flat_defaulted: sval("FD"),
                    flat_arg_needed: "FAN".into(),
                    flat_arg_several: ["FAS1", "FAS2"].map(Into::into).into(),
                    flat_arg_optional: Some("FAO".into()),
                    flat_arg_defaulted: "FAD".into(),
                    flat_with_optional: Some(NeedsWith),
                    flat_with_several: vec![NeedsWith; 2],
                    flat_flat: FlatInner {
                        flat_inner_optional: sval("nested"),
                    },
                    ..Flat1::default()
                },
                ..default()
            },
            sub2: Some(Sub2 {
                sub2_field: sval("B"),
                arg_optional: Some("AO".into()),
                arg_defaulted: "AD".into(),
                arg_several: ["A1", "A2"].map(Into::into).into(),
                with_optional: Some(NeedsWith),
                with_several: vec![NeedsWith; 3],
                subsub: SubSub {
                    subsub_field: sval("BS"),
                    ..subsub_minimal.clone()
                },
                ..sub2_minimal.clone()
            }),
            sub3: ["C1", "C2"]
                .map(|s| Sub3 {
                    sub3_field: sval(s),
                    ..default()
                })
                .into(),
            sub4: Sub4 {
                sub4_field: sval("D"),
                ..default()
            },
            ..default()
        }],
    )?;

    t_err_raw::<Top>(0, None, "empty document", r#""#)?;

    let wrong_document = r#"wrong-keyword # wrong document type
"#;
    t_err_chk_msg::<Top>(
        wrong_document,
        "error: failed to parse network document, type top-intro: <massaged>:1: wrong document type",
    )?;

    t_err::<Top>(
        r#"top-intro
sub4-intro # missing item needed
"#,
    )?;

    t_err::<Top>(
        r#"top-intro
sub1-intro
flat-arg-needed arg
flat-with-needed normal
sub4-intro # missing item flat-needed
"#,
    )?;

    t_err::<Top>(
        r#"top-intro
sub1-intro
flat-needed flat
flat-with-needed normal
sub4-intro # missing item flat-arg-needed
"#,
    )?;

    t_err::<Top>(
        r#"top-intro
sub1-intro
flat-arg-needed FAN
flat-with-needed normal
flat-needed FN
sub4-intro # missing item needed
"#,
    )?;

    t_err::<Top>(
        r#"top-intro
needed N
sub3-intro
sub4-intro # missing item sub1-intro
"#,
    )?;

    t_err::<Top>(
        r#"top-intro
needed N
sub1-intro
flat-needed FN1
flat-arg-needed FAN
flat-with-needed normal
sub1-intro # item repeated when not allowed
flat-needed FN2
"#,
    )?;

    t_err::<Top>(
        r#"top-intro
needed N
sub2-intro # missing argument in needs with
"#,
    )?;

    let wrong_value = r#"top-intro
needed N
sub2-intro wrong-value # invalid value for argument in needs with @12
"#;
    t_err_chk_msg::<Top>(
        wrong_value,
        "error: failed to parse network document, type top-intro: <massaged>:3.12: invalid value for argument in needs with",
    )?;

    t_err::<Top>(
        r#"top-intro
sub1-intro
flat-needed FN
flat-arg-needed arg
sub4-intro # missing item flat-with-needed
"#,
    )?;

    t_err::<Top>(
        r#"top-intro
sub1-intro
flat-needed FN
flat-arg-needed arg
flat-with-needed normal
sub2-intro intro
arg-needed AN
flat-arg-needed arg
sub3-intro # missing item with-needed
"#,
    )?;

    Ok(())
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(NetdocParseable)]
struct TopMinimal {
    test_item0: TestItem0,
    test_item: Option<TestItem>,
    test_item_rest: Option<TestItemRest>,
    test_item_rest_with: Option<TestItemRestWith>,
    test_item_object_not_present: Option<TestItemObjectNotPresent>,
    test_item_object_ignored: Option<TestItemObjectIgnored>,
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(ItemValueParseable)]
#[deftly(netdoc(no_extra_args))]
struct TestItem0 {
    #[deftly(netdoc(object(label = "UTF-8 STRING"), with = "string_data_object"))]
    object: Option<String>,
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(ItemValueParseable)]
struct TestItem {
    needed: String,
    #[deftly(netdoc(with = "needs_with_arg"))]
    optional: Option<NeedsWith>,
    rest: Vec<String>,
    #[deftly(netdoc(object))]
    object: TestObject,
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(ItemValueParseable)]
struct TestItemRest {
    optional: Option<String>,
    #[deftly(netdoc(rest))]
    rest: String,
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(ItemValueParseable)]
struct TestItemRestWith {
    #[deftly(netdoc(rest, with = "needs_with_arg::from_rest"))]
    rest: NeedsWith,
}

#[derive(Debug, Default, Clone, Eq, PartialEq)]
struct TestObject(String);

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(ItemValueParseable)]
struct TestItemObjectNotPresent {
    #[deftly(netdoc(object))]
    object: NotPresent,
}

#[derive(Deftly, Debug, Default, Clone, Eq, PartialEq)]
#[derive_deftly(ItemValueParseable)]
struct TestItemObjectIgnored {
    #[deftly(netdoc(object))]
    object: Ignored,
}

/// Conversion module for `String` as Object with [`ItemValueParseable`]
mod string_data_object {
    /// Parse the data
    pub(super) fn try_from(data: Vec<u8>) -> Result<String, std::string::FromUtf8Error> {
        String::from_utf8(data)
    }
}

impl ItemObjectParseable for TestObject {
    fn check_label(label: &str) -> Result<(), P2EP> {
        if label != "TEST OBJECT" {
            return Err(P2EP::ObjectIncorrectLabel);
        }
        Ok(())
    }
    fn from_bytes(data: &[u8]) -> Result<Self, P2EP> {
        Ok(TestObject(
            String::from_utf8(data.to_owned()).map_err(|_| P2EP::ObjectInvalidData)?,
        ))
    }
}

#[test]
fn various_items() -> TestResult<()> {
    let test_item_minimal = TestItem {
        needed: "N".into(),
        object: TestObject("hello".into()),
        ..default()
    };

    t_ok(
        r#"test-item0
"#,
        &[TopMinimal { ..default() }],
    )?;

    t_ok(
        r#"test-item0
test-item N
-----BEGIN TEST OBJECT-----
aGVsbG8=
-----END TEST OBJECT-----
"#,
        &[TopMinimal {
            test_item: Some(test_item_minimal.clone()),
            ..default()
        }],
    )?;

    t_ok(
        r#"test-item0
test-item N arg
-----BEGIN TEST OBJECT-----
aGVsbG8=
-----END TEST OBJECT-----
"#,
        &[TopMinimal {
            test_item: Some(TestItem {
                optional: Some(NeedsWith),
                ..test_item_minimal.clone()
            }),
            ..default()
        }],
    )?;

    t_ok(
        r#"test-item0
-----BEGIN UTF-8 STRING-----
aGVsbG8=
-----END UTF-8 STRING-----
test-item N arg R1 R2
-----BEGIN TEST OBJECT-----
aGVsbG8=
-----END TEST OBJECT-----
test-item-rest O  and  the rest
test-item-rest-with   rest of line
test-item-object-not-present
test-item-object-ignored
-----BEGIN TEST OBJECT-----
aGVsbG8=
-----END TEST OBJECT-----
"#,
        &[TopMinimal {
            test_item0: TestItem0 {
                object: Some("hello".into()),
            },
            test_item: Some(TestItem {
                optional: Some(NeedsWith),
                rest: ["R1", "R2"].map(Into::into).into(),
                ..test_item_minimal.clone()
            }),
            test_item_rest: Some(TestItemRest {
                optional: Some("O".into()),
                rest: "and  the rest".into(),
            }),
            test_item_rest_with: Some(TestItemRestWith { rest: NeedsWith }),
            test_item_object_not_present: Some(TestItemObjectNotPresent { object: NotPresent }),
            test_item_object_ignored: Some(TestItemObjectIgnored { object: Ignored }),
        }],
    )?;

    t_err::<TopMinimal>(
        r#"test-item0 wrong # too many arguments @12
"#,
    )?;
    t_err::<TopMinimal>(
        r#"test-item0 # base64-encoded Object label is not as expected
-----BEGIN WRONG LABEL-----
aGVsbG8=
-----END WRONG LABEL-----
"#,
    )?;
    t_err::<TopMinimal>(
        r#"test-item0 # base64-encoded Object END label does not match BEGIN
-----BEGIN UTF-8 STRING-----
aGVsbG8=
-----END WRONG LABEL-----
"#,
    )?;
    t_err::<TopMinimal>(
        r#"test-item0
test-item-object-not-present # base64-encoded Object found where none expected
-----BEGIN TEST OBJECT-----
aGVsbG8=
-----END TEST OBJECT-----
"#,
    )?;
    t_err::<TopMinimal>(
        r#"test-item0 # base64-encoded Object has incorrectly formatted delimiter lines
-----BEGIN UTF-8 STRING-----
aGVsbG8=
-----END UTF-8 STRING
"#,
    )?;
    t_err::<TopMinimal>(
        r#"test-item0 # base64-encoded Object contains invalid base64
-----BEGIN UTF-8 STRING-----
bad b64 !
-----END UTF-8 STRING-----

"#,
    )?;
    t_err::<TopMinimal>(
        r#"test-item0 # base64-encoded Object contains invalid data
-----BEGIN UTF-8 STRING-----
hU6Qo2fW7+9PXkcrEyiB62ZDne/gwKPHXBo8lMeV8JCOfVBF5vT4BtKRLP+Jw66x
-----END UTF-8 STRING-----
"#,
    )?;

    Ok(())
}