]> git.huck.website - metaforge.git/commitdiff
parser works on pattern files
authorHuck Boles <huck@huck.website>
Thu, 4 May 2023 16:46:22 +0000 (11:46 -0500)
committerHuck Boles <huck@huck.website>
Thu, 4 May 2023 16:46:22 +0000 (11:46 -0500)
src/metafile.rs
src/tests/test_parser.rs
src/tests/test_pattern.meta [new file with mode: 0644]

index a82d8097f31dc9cee4dfdf557a4862bcce7903ba..9b6ec42e1df69b85a0c8c06f547fffa71b3dfbef 100644 (file)
@@ -19,13 +19,13 @@ impl<'a> MetaFile<'a> {
     }
 }
 
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq)]
 pub enum Source<'a> {
     Str(&'a str),
     Sub(Substitution<'a>),
 }
 
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, PartialEq)]
 pub enum Substitution<'a> {
     Variable(&'a str),
     Array(&'a str),
index db62c2448bb7df56b30c7ff47e6ac1fcb672f245..c03cb3caa0486d97c8b1c8af18972089d0a79a21 100644 (file)
@@ -1,7 +1,8 @@
-use crate::parse_file;
+use crate::{parse_file, Source, Substitution};
 use color_eyre::Result;
 
 static SOURCE: &str = include_str!("test_source.meta");
+static PATTERN: &str = include_str!("test_pattern.meta");
 
 #[test]
 fn build_meta_file() -> Result<()> {
@@ -32,3 +33,25 @@ fn build_meta_file() -> Result<()> {
 
     Ok(())
 }
+
+#[test]
+fn build_pattern_file() -> Result<()> {
+    macro_rules! source (
+        (var($s:literal)) => { Source::Sub(Substitution::Variable($s))};
+        (arr($s:literal)) => { Source::Sub(Substitution::Array($s))};
+        (pat($s:literal)) => { Source::Sub(Substitution::Pattern($s))};
+        ($s:literal) => { Source::Str($s)};
+    );
+
+    let mut pattern_src = parse_file(PATTERN)?.source.into_iter();
+
+    pattern_src.next();
+    assert_eq!(pattern_src.next().unwrap(), source!(var("${var}")));
+    pattern_src.next();
+    assert_eq!(pattern_src.next().unwrap(), source!(pat("&{pat}")));
+    assert_eq!(pattern_src.next().unwrap(), source!(arr("@{array}")));
+    pattern_src.next();
+    assert_eq!(pattern_src.next().unwrap(), source!(var("${blank}")));
+
+    Ok(())
+}
diff --git a/src/tests/test_pattern.meta b/src/tests/test_pattern.meta
new file mode 100644 (file)
index 0000000..4c083a4
--- /dev/null
@@ -0,0 +1,15 @@
+<body>
+    <h1>This is a test for pattern.meta files</h1>
+
+    <p> inserted variable: ${var}</p>
+
+    &{pat}
+
+    @{array}
+
+    <ul>
+        <li> with-{ inline comment} html </li>
+        <li> type syntax including :${blank} blank variables
+        <li> and symbols: !@$%#&*(){}
+    </ul>
+</body>