summaryrefslogtreecommitdiffstats
path: root/vendor/toml/tests/testsuite/spanned_impls.rs
blob: 5e866f92a78db6427db4596ae4482042c5ee6ea2 (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
use std::cmp::{Ord, Ordering, PartialOrd};

use serde::Deserialize;
use toml::{from_str, Spanned};

#[test]
fn test_spans_impls() {
    #[derive(Deserialize)]
    struct Foo {
        bar: Spanned<bool>,
        baz: Spanned<String>,
    }
    let f: Foo = from_str(
        "
    bar = true
    baz = \"yes\"
    ",
    )
    .unwrap();
    let g: Foo = from_str(
        "
    baz = \"yes\"
    bar = true
    ",
    )
    .unwrap();
    assert!(f.bar.span() != g.bar.span());
    assert!(f.baz.span() != g.baz.span());

    // test that eq still holds
    assert_eq!(f.bar, g.bar);
    assert_eq!(f.baz, g.baz);

    // test that Ord returns equal order
    assert_eq!(f.bar.cmp(&g.bar), Ordering::Equal);
    assert_eq!(f.baz.cmp(&g.baz), Ordering::Equal);

    // test that PartialOrd returns equal order
    assert_eq!(f.bar.partial_cmp(&g.bar), Some(Ordering::Equal));
    assert_eq!(f.baz.partial_cmp(&g.baz), Some(Ordering::Equal));
}