diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/helpers/mod.rs | 54 | ||||
-rw-r--r-- | tests/schema-via-knuffel.rs | 56 |
2 files changed, 57 insertions, 53 deletions
diff --git a/tests/helpers/mod.rs b/tests/helpers/mod.rs new file mode 100644 index 0000000..09499ad --- /dev/null +++ b/tests/helpers/mod.rs @@ -0,0 +1,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); + } +} diff --git a/tests/schema-via-knuffel.rs b/tests/schema-via-knuffel.rs index b0d1a1c..147c905 100644 --- a/tests/schema-via-knuffel.rs +++ b/tests/schema-via-knuffel.rs @@ -1,59 +1,9 @@ #![cfg(feature = "knuffel")] -use std::fmt::Debug; +use kdl_schema::{Schema, SCHEMA_SCHEMA}; -use kdl_schema::*; - -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 node::Prop {} -impl DeepAssertEq for node::Value {} -impl DeepAssertEq for node::Children { - fn deep_assert_eq(left: &Self, right: &Self) { - DeepAssertEq::deep_assert_eq(&left.nodes, &right.nodes); - assert_eq!(left, right); - } -} +mod helpers; +use helpers::DeepAssertEq; #[test] fn schema_loads() -> miette::Result<()> { |