aboutsummaryrefslogtreecommitdiff
path: root/tests/helpers/mod.rs
blob: 09499adffbece0ee8e32c21b632ec39b19149128 (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
use std::fmt::Debug;

use kdl_schema::*;

pub trait DeepAssertEq
where
    Self: PartialEq + Debug,
{
    fn deep_assert_eq(left: &Self, right: &Self) {
        assert_eq!(left, right);
    }
}

impl DeepAssertEq for Schema {
    fn deep_assert_eq(left: &Self, right: &Self) {
        DeepAssertEq::deep_assert_eq(&left.document, &right.document)
    }
}

impl DeepAssertEq for Document {
    fn deep_assert_eq(left: &Self, right: &Self) {
        DeepAssertEq::deep_assert_eq(&left.info, &right.info);
        DeepAssertEq::deep_assert_eq(&left.nodes, &right.nodes);
    }
}

impl<T: DeepAssertEq> DeepAssertEq for Vec<T> {
    fn deep_assert_eq(left: &Self, right: &Self) {
        for (left, right) in left.iter().zip(right.iter()) {
            DeepAssertEq::deep_assert_eq(left, right);
        }
        assert_eq!(left, right);
    }
}

impl DeepAssertEq for Info {}

impl DeepAssertEq for Node {
    fn deep_assert_eq(left: &Self, right: &Self) {
        DeepAssertEq::deep_assert_eq(&left.props, &right.props);
        DeepAssertEq::deep_assert_eq(&left.values, &right.values);
        DeepAssertEq::deep_assert_eq(&left.children, &right.children);
        assert_eq!(left, right);
    }
}

impl DeepAssertEq for Prop {}
impl DeepAssertEq for Value {}
impl DeepAssertEq for Children {
    fn deep_assert_eq(left: &Self, right: &Self) {
        DeepAssertEq::deep_assert_eq(&left.nodes, &right.nodes);
        assert_eq!(left, right);
    }
}