]> git.huck.website - metaforge.git/commitdiff
Revert "test site passes"
authorHuck Boles <huck@huck.website>
Wed, 10 May 2023 14:57:20 +0000 (09:57 -0500)
committerHuck Boles <huck@huck.website>
Wed, 10 May 2023 14:57:20 +0000 (09:57 -0500)
This reverts commit cfc6c92adb9c063078305139076ce558113313a9.

24 files changed:
bacon.toml
src/filetype/builder.rs
src/parser/parse.rs
src/tests/test_metafile.rs
tests/files/expanded
tests/files/test_site/pattern/base/default.meta [moved from test_site/pattern/base/default.meta with 100% similarity]
tests/files/test_site/pattern/pat/default.meta [moved from test_site/pattern/pat/default.meta with 100% similarity]
tests/files/test_site/pattern/pat/pattern.meta [moved from test_site/pattern/pat/pattern.meta with 100% similarity]
tests/files/test_site/pattern/test/array.meta [moved from test_site/pattern/test/array.meta with 100% similarity]
tests/files/test_site/pattern/test/blank/default.meta [moved from test_site/pattern/test/blank/default.meta with 100% similarity]
tests/files/test_site/pattern/test/default/default.meta [moved from test_site/pattern/test/default/default.meta with 100% similarity]
tests/files/test_site/pattern/test/new/default.meta [moved from test_site/pattern/test/new/default.meta with 100% similarity]
tests/files/test_site/pattern/test/new/new.meta [moved from test_site/pattern/test/new/new.meta with 100% similarity]
tests/files/test_site/pattern/test/overwrite/default.meta [moved from test_site/pattern/test/overwrite/default.meta with 100% similarity]
tests/files/test_site/pattern/test/overwrite/overwrite.meta [moved from test_site/pattern/test/overwrite/overwrite.meta with 100% similarity]
tests/files/test_site/pattern/test/parent/default.meta [moved from test_site/pattern/test/parent/default.meta with 100% similarity]
tests/files/test_site/pattern/test/parent/parent.meta [moved from test_site/pattern/test/parent/parent.meta with 100% similarity]
tests/files/test_site/pattern/test/pattern.meta [moved from test_site/pattern/test/pattern.meta with 100% similarity]
tests/files/test_site/pattern/test/sub_pat/default.meta [moved from test_site/pattern/test/sub_pat/default.meta with 100% similarity]
tests/files/test_site/pattern/test/sub_pat/sub_pattern.meta [moved from test_site/pattern/test/sub_pat/sub_pattern.meta with 100% similarity]
tests/files/test_site/source/expand.meta [moved from test_site/source/expand.meta with 100% similarity]
tests/files/test_site/source/sub_dir/sub_source.meta [moved from test_site/source/sub_dir/sub_source.meta with 100% similarity]
tests/files/test_site/source/test_source.meta [moved from test_site/source/test_source.meta with 100% similarity]
tests/metafile_builder.rs

index ae7b891377eee935fec06302b6cd4d3ecc847b2f..a4c3c37f49bea017e3519804c71e797c81ba8458 100644 (file)
@@ -24,8 +24,8 @@ command = [
 need_stdout = false
 
 [jobs.test]
-command = [ "cargo", "test", "--color", "always", "--", "--color", "always" ]
-need_stdout = false
+command = [ "cargo", "test", "--color", "always" ]
+need_stdout = true
 
 [jobs.doc]
 command = ["cargo", "doc", "--color", "always", "--no-deps"]
index f3320d34e13f68c4aa24ce215b00177ef9f94af8..f1f3c646ca2b50652125c282e2c64afe362d7a0e 100644 (file)
@@ -14,8 +14,7 @@ pub fn build_metafile(file: &MetaFile, dirs: &RootDirs, path: &Path) -> Result<(
 }
 
 pub fn metafile_to_string(file: &MetaFile, dirs: &RootDirs, name: Option<&str>) -> Result<String> {
-    let mut output = String::new();
-    let mut arrays = false;
+    let mut output = String::default();
 
     for section in file.source.iter() {
         match section {
@@ -28,53 +27,30 @@ pub fn metafile_to_string(file: &MetaFile, dirs: &RootDirs, name: Option<&str>)
                 let expanded = match sub {
                     Substitution::Variable(key) => file
                         .get_var(key)
-                        .filter(|val| *val != "BLANK")
                         .map(|val| val.to_string())
                         .unwrap_or_default(),
                     Substitution::Pattern(key) => get_pattern(key, file, dirs)?,
                     // comments have already been removed at this point,
                     // so we use them to mark keys for array substitution
-                    Substitution::Array(key) => {
-                        arrays = true;
-                        format!("-{{{key}}}")
-                    }
+                    Substitution::Array(key) => format!("-{{{key}}}"),
                 };
                 output.push_str(&format!("\n{}\n", expanded));
             }
         }
     }
 
-    println!("{}", output);
-
     // deal with arrays
-    if arrays {
-        expand_arrays(output, file, name)
-    } else {
-        Ok(output)
-    }
+    expand_arrays(output, file, name)
 }
 
 fn get_pattern(key: &str, file: &MetaFile, dirs: &RootDirs) -> Result<String> {
-    let mut filename = file.get_pat(key).unwrap_or("default");
-    if filename == "BLANK" {
-        return Ok(String::new());
-    };
-
-    if filename == "DEFAULT" {
-        filename = "default";
-    }
+    let filename = file.get_pat(key).unwrap_or("default");
 
     let pattern_path = key.replace('.', "/") + "/" + filename;
     let mut path = dirs.pattern.join(pattern_path);
     path.set_extension("meta");
-    eprintln!("{:?}", path);
     let pattern = &fs::read_to_string(path.to_str().unwrap_or_default())?;
-    let mut pattern = parse_file(pattern)?;
-
-    pattern.variables = file.variables.clone();
-    pattern.arrays = file.arrays.clone();
-    pattern.patterns = file.patterns.clone();
-
+    let pattern = parse_file(pattern)?;
     metafile_to_string(&pattern, dirs, Some(key))
 }
 
@@ -107,6 +83,7 @@ fn expand_arrays(output: String, file: &MetaFile, name: Option<&str>) -> Result<
             } else {
                 key = array.to_string();
             }
+            // let key = dbg!(name.unwrap_or_default().to_owned() + "." + array);
             let value = file.get_arr(&key).unwrap_or_default();
             (*array, value)
         })
index 37df17e98ed20d90eb9e618683a7c1a65dd3e9ec..c50976049cda8c0477e718e23090ebca0aa5e9d5 100644 (file)
@@ -104,15 +104,11 @@ fn parse_assign(pair: Pair<Rule>) -> (&'_ str, &'_ str) {
         }
         if Rule::value == pair.as_rule() {
             let tmp = pair.as_str();
-
-            if tmp == "BLANK" {
-                return (key, "BLANK");
-            }
-
-            if tmp == "DEFAULT" {
-                return (key, "DEFAULT");
+            // blank and default shoud be handled by whoever is getting the value
+            // set it to empty strings to remove it from the HashMap
+            if tmp == "BLANK" || tmp == "DEFAULT" {
+                return ("", "");
             }
-
             // remove surrounding quotes from values by returning
             // everything except first and last characters
             // a string is defined as " ... " or ' ... '
index 04cc4ea0902ace2f992b0a8566fa2c00f968a0f7..144849c9ba5a742cd71a2bc98c32fda6787de0b0 100644 (file)
@@ -1,9 +1,10 @@
-use crate::{parse_file, source, Source, Substitution};
+use crate::{metafile_to_string, parse_file, source, RootDirs, Source, Substitution};
 use color_eyre::Result;
 use pretty_assertions::assert_eq;
+use std::{fs, path::PathBuf};
 
-static SOURCE: &str = include_str!("../../test_site/source/test_source.meta");
-static PATTERN: &str = include_str!("../../test_site/pattern/test/pattern.meta");
+static SOURCE: &str = include_str!("../../tests/files/test_site/source/test_source.meta");
+static PATTERN: &str = include_str!("../../tests/files//test_site/pattern/test/pattern.meta");
 
 #[test]
 fn test_metafile_gets() -> Result<()> {
@@ -11,7 +12,7 @@ fn test_metafile_gets() -> Result<()> {
 
     assert_eq!(source.get_var("var").unwrap(), "GOOD");
     assert_eq!(source.get_var("single_quotes").unwrap(), "GOOD");
-    assert_eq!(source.get_var("blank").unwrap(), "BLANK");
+    assert_eq!(source.get_var("blank"), None);
     assert_eq!(source.get_var("not_defined"), None);
 
     assert_eq!(source.get_arr("sub.array").unwrap(), ["GOOD", "GOOD"]);
@@ -23,8 +24,8 @@ fn test_metafile_gets() -> Result<()> {
     assert_eq!(source.get_arr("not_defined"), None);
 
     assert_eq!(source.get_pat("test").unwrap(), "pattern");
-    assert_eq!(source.get_pat("test.sub_pat").unwrap(), "DEFAULT");
-    assert_eq!(source.get_pat("blank_pat").unwrap(), "BLANK");
+    assert_eq!(source.get_pat("test.sub_pat"), None);
+    assert_eq!(source.get_pat("blank_pat"), None);
     assert_eq!(source.get_pat("not_defined"), None);
 
     Ok(())
@@ -35,7 +36,7 @@ fn parse_meta_file() -> Result<()> {
     let source = parse_file(SOURCE)?;
 
     assert_eq!(source.variables.get("var").unwrap(), &"GOOD");
-    assert_eq!(source.variables.get("blank").unwrap(), &"BLANK");
+    assert_eq!(source.variables.get("blank"), None);
     assert_eq!(source.variables.get("not_here"), None);
 
     assert_eq!(
@@ -53,8 +54,8 @@ fn parse_meta_file() -> Result<()> {
     assert_eq!(source.arrays.get("not_defined"), None);
 
     assert_eq!(source.patterns.get("test").unwrap(), &"pattern");
-    assert_eq!(source.patterns.get("test.sub_pat").unwrap(), &"DEFAULT");
-    assert_eq!(source.patterns.get("blank_pat").unwrap(), &"BLANK");
+    assert_eq!(source.patterns.get("test.sub_pat"), None);
+    assert_eq!(source.patterns.get("blank_pat"), None);
     assert_eq!(source.patterns.get("not_defined"), None);
 
     Ok(())
index bc2fff8dd1989384dc6367d9ec784315883fa826..8e3f4dd8dc3ef5cd612712e9a39e761559e17095 100644 (file)
@@ -6,22 +6,20 @@ var2 [BLANK]:
 
 var3 [VAL WITH SPACES]:
 GOOD GOOD
+
 arr1 [VALUE]:
 GOOD
 arr2 [BLANK]:
 
 Pattern subs:
 
-test [WITH ARRAY]:
-<p>
-GOOD
-</p><p>
-GOOD GOOD
-</p>
+test [WITH ARRAY]: 
+<p>GOOD</p>
+<p>GOOD GOOD</p>
 test.sub_pat:
 <h1>SUBPATTERN</h1>
 test.default:
 <h1>DEFAULT</h1>
-test.blank:
+test.blank: 
 
-This comment should not be rendered:
+This comment should not be rendered: 
index 80f64e52b4057f6955cd4b4b2e14043c8d754c53..262ee9e56dc8b75d93f0d6bbc34e4d58fdbf5880 100644 (file)
@@ -3,7 +3,7 @@ use metaforge::*;
 use pretty_assertions::assert_eq;
 use std::{fs, path::PathBuf};
 
-static PRE_EXPAND: &str = include_str!("../test_site/source/expand.meta");
+static PRE_EXPAND: &str = include_str!("./files/test_site/source/expand.meta");
 static POST_EXPAND: &str = include_str!("./files/expanded");
 
 #[test]
@@ -13,14 +13,13 @@ fn test_metafile_to_str() -> Result<()> {
 
     let file = metafile_to_string(&metafile, &dirs, None)?;
 
-    eprintln!("{}", file);
-    assert_eq!(file + "\n", POST_EXPAND);
+    assert_eq!(file, POST_EXPAND);
 
     Ok(())
 }
 
 fn build_rootdir() -> Result<RootDirs> {
-    let dir = PathBuf::from("./test_site");
+    let dir = PathBuf::from("./tests/files/test_site");
 
     let dirs = RootDirs {
         source: dir.join("source"),