aboutsummaryrefslogtreecommitdiff
path: root/tests/helpers
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2022-03-26 20:13:37 -0600
committerMelody Horn <melody@boringcactus.com>2022-03-26 20:13:37 -0600
commit73740e6dd0723113e22a26aa389e545085f58857 (patch)
tree6da14cdf3e3f336d602a5a086d2478be50b78c1c /tests/helpers
parent26a20cf4f3a71ccdd7c6abb06cffd4c12d08395e (diff)
downloadkdl-schema-73740e6dd0723113e22a26aa389e545085f58857.tar.gz
kdl-schema-73740e6dd0723113e22a26aa389e545085f58857.zip
refactor lib out of modules and test helper into a module
Diffstat (limited to 'tests/helpers')
-rw-r--r--tests/helpers/mod.rs54
1 files changed, 54 insertions, 0 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);
+ }
+}