]> git.huck.website - metaforge.git/commitdiff
meta source test
authorHuck Boles <huck@huck.website>
Wed, 3 May 2023 23:51:01 +0000 (18:51 -0500)
committerHuck Boles <huck@huck.website>
Wed, 3 May 2023 23:51:01 +0000 (18:51 -0500)
src/tests.rs
src/tests/test_parser.rs [new file with mode: 0644]
src/tests/test_source.meta [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..33567a09b1b9f4f4d1d644d65e18b7dbfc3fa17b 100644 (file)
@@ -0,0 +1 @@
+mod test_parser;
diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs
new file mode 100644 (file)
index 0000000..c404f84
--- /dev/null
@@ -0,0 +1,35 @@
+use crate::parse_file;
+use color_eyre::Result;
+
+static SOURCE: &str = include_str!("test_source.meta");
+
+#[test]
+fn build_meta_file() -> Result<()> {
+    let source = parse_file(SOURCE)?;
+
+    assert_eq!(source.variables.get("var").unwrap(), &"good");
+    assert_eq!(source.variables.get("blank"), None);
+    assert_eq!(source.variables.get("not_here"), None);
+
+    assert_eq!(
+        source.arrays.get("sub.array").unwrap(),
+        &vec!["sub", "value"]
+    );
+    assert_eq!(
+        source.arrays.get("arr").unwrap(),
+        &vec!["split", "up", "values"]
+    );
+    assert_eq!(
+        source.arrays.get("with_spaces").unwrap(),
+        &vec!["stuff", "with", "spaces"]
+    );
+    assert_eq!(source.arrays.get("not_defined"), None);
+    assert_eq!(source.arrays.get("blank"), None);
+
+    assert_eq!(source.patterns.get("pat").unwrap(), &"pattern");
+    assert_eq!(source.patterns.get("pat.sub_pat"), None);
+    assert_eq!(source.patterns.get("blank_pat"), None);
+    assert_eq!(source.patterns.get("not_defined"), None);
+
+    Ok(())
+}
diff --git a/src/tests/test_source.meta b/src/tests/test_source.meta
new file mode 100644 (file)
index 0000000..21fb37b
--- /dev/null
@@ -0,0 +1,30 @@
+${
+    var = "good"
+    blank = BLANK
+}
+
+@{
+    sub.array = ["sub","value"]
+    arr = ["split","up","values"]
+    blank = BLANK
+    -{ with_spaces = [ "stuff", "with" , "spaces" ] }
+}
+
+&{
+    pat = "pattern"
+    pat.sub_pat = DEFAULT
+    blank_pat = BLANK
+}
+
+#THIS IS A TEST
+
+with included variables: ${var}
+
+and patterns: &{pat}
+
+and subpatterns: &{pat.sub_pat}
+
+-{ and inline comments }
+and arrays: @{arr} and nested @{sub.array}
+
+and all the other symbols: !@#$%^&*(){}_+