From d5fcf7f8a2878f174be011d48f173ff1323cabad Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Wed, 10 May 2023 09:57:20 -0500 Subject: [PATCH] Revert "test site passes" This reverts commit cfc6c92adb9c063078305139076ce558113313a9. --- bacon.toml | 4 +-- src/filetype/builder.rs | 35 ++++--------------- src/parser/parse.rs | 12 +++---- src/tests/test_metafile.rs | 19 +++++----- tests/files/expanded | 14 ++++---- .../test_site}/pattern/base/default.meta | 0 .../files/test_site}/pattern/pat/default.meta | 0 .../files/test_site}/pattern/pat/pattern.meta | 0 .../files/test_site}/pattern/test/array.meta | 0 .../pattern/test/blank/default.meta | 0 .../pattern/test/default/default.meta | 0 .../test_site}/pattern/test/new/default.meta | 0 .../test_site}/pattern/test/new/new.meta | 0 .../pattern/test/overwrite/default.meta | 0 .../pattern/test/overwrite/overwrite.meta | 0 .../pattern/test/parent/default.meta | 0 .../pattern/test/parent/parent.meta | 0 .../test_site}/pattern/test/pattern.meta | 0 .../pattern/test/sub_pat/default.meta | 0 .../pattern/test/sub_pat/sub_pattern.meta | 0 .../files/test_site}/source/expand.meta | 0 .../test_site}/source/sub_dir/sub_source.meta | 0 .../files/test_site}/source/test_source.meta | 0 tests/metafile_builder.rs | 7 ++-- 24 files changed, 31 insertions(+), 60 deletions(-) rename {test_site => tests/files/test_site}/pattern/base/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/pat/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/pat/pattern.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/array.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/blank/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/default/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/new/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/new/new.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/overwrite/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/overwrite/overwrite.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/parent/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/parent/parent.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/pattern.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/sub_pat/default.meta (100%) rename {test_site => tests/files/test_site}/pattern/test/sub_pat/sub_pattern.meta (100%) rename {test_site => tests/files/test_site}/source/expand.meta (100%) rename {test_site => tests/files/test_site}/source/sub_dir/sub_source.meta (100%) rename {test_site => tests/files/test_site}/source/test_source.meta (100%) diff --git a/bacon.toml b/bacon.toml index ae7b891..a4c3c37 100644 --- a/bacon.toml +++ b/bacon.toml @@ -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"] diff --git a/src/filetype/builder.rs b/src/filetype/builder.rs index f3320d3..f1f3c64 100644 --- a/src/filetype/builder.rs +++ b/src/filetype/builder.rs @@ -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 { - 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 { - 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) }) diff --git a/src/parser/parse.rs b/src/parser/parse.rs index 37df17e..c509760 100644 --- a/src/parser/parse.rs +++ b/src/parser/parse.rs @@ -104,15 +104,11 @@ fn parse_assign(pair: Pair) -> (&'_ 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 ' ... ' diff --git a/src/tests/test_metafile.rs b/src/tests/test_metafile.rs index 04cc4ea..144849c 100644 --- a/src/tests/test_metafile.rs +++ b/src/tests/test_metafile.rs @@ -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(()) diff --git a/tests/files/expanded b/tests/files/expanded index bc2fff8..8e3f4dd 100644 --- a/tests/files/expanded +++ b/tests/files/expanded @@ -6,22 +6,20 @@ var2 [BLANK]: var3 [VAL WITH SPACES]: GOOD GOOD + arr1 [VALUE]: GOOD arr2 [BLANK]: Pattern subs: -test [WITH ARRAY]: -

-GOOD -

-GOOD GOOD -

+test [WITH ARRAY]: +

GOOD

+

GOOD GOOD

test.sub_pat:

SUBPATTERN

test.default:

DEFAULT

-test.blank: +test.blank: -This comment should not be rendered: +This comment should not be rendered: diff --git a/test_site/pattern/base/default.meta b/tests/files/test_site/pattern/base/default.meta similarity index 100% rename from test_site/pattern/base/default.meta rename to tests/files/test_site/pattern/base/default.meta diff --git a/test_site/pattern/pat/default.meta b/tests/files/test_site/pattern/pat/default.meta similarity index 100% rename from test_site/pattern/pat/default.meta rename to tests/files/test_site/pattern/pat/default.meta diff --git a/test_site/pattern/pat/pattern.meta b/tests/files/test_site/pattern/pat/pattern.meta similarity index 100% rename from test_site/pattern/pat/pattern.meta rename to tests/files/test_site/pattern/pat/pattern.meta diff --git a/test_site/pattern/test/array.meta b/tests/files/test_site/pattern/test/array.meta similarity index 100% rename from test_site/pattern/test/array.meta rename to tests/files/test_site/pattern/test/array.meta diff --git a/test_site/pattern/test/blank/default.meta b/tests/files/test_site/pattern/test/blank/default.meta similarity index 100% rename from test_site/pattern/test/blank/default.meta rename to tests/files/test_site/pattern/test/blank/default.meta diff --git a/test_site/pattern/test/default/default.meta b/tests/files/test_site/pattern/test/default/default.meta similarity index 100% rename from test_site/pattern/test/default/default.meta rename to tests/files/test_site/pattern/test/default/default.meta diff --git a/test_site/pattern/test/new/default.meta b/tests/files/test_site/pattern/test/new/default.meta similarity index 100% rename from test_site/pattern/test/new/default.meta rename to tests/files/test_site/pattern/test/new/default.meta diff --git a/test_site/pattern/test/new/new.meta b/tests/files/test_site/pattern/test/new/new.meta similarity index 100% rename from test_site/pattern/test/new/new.meta rename to tests/files/test_site/pattern/test/new/new.meta diff --git a/test_site/pattern/test/overwrite/default.meta b/tests/files/test_site/pattern/test/overwrite/default.meta similarity index 100% rename from test_site/pattern/test/overwrite/default.meta rename to tests/files/test_site/pattern/test/overwrite/default.meta diff --git a/test_site/pattern/test/overwrite/overwrite.meta b/tests/files/test_site/pattern/test/overwrite/overwrite.meta similarity index 100% rename from test_site/pattern/test/overwrite/overwrite.meta rename to tests/files/test_site/pattern/test/overwrite/overwrite.meta diff --git a/test_site/pattern/test/parent/default.meta b/tests/files/test_site/pattern/test/parent/default.meta similarity index 100% rename from test_site/pattern/test/parent/default.meta rename to tests/files/test_site/pattern/test/parent/default.meta diff --git a/test_site/pattern/test/parent/parent.meta b/tests/files/test_site/pattern/test/parent/parent.meta similarity index 100% rename from test_site/pattern/test/parent/parent.meta rename to tests/files/test_site/pattern/test/parent/parent.meta diff --git a/test_site/pattern/test/pattern.meta b/tests/files/test_site/pattern/test/pattern.meta similarity index 100% rename from test_site/pattern/test/pattern.meta rename to tests/files/test_site/pattern/test/pattern.meta diff --git a/test_site/pattern/test/sub_pat/default.meta b/tests/files/test_site/pattern/test/sub_pat/default.meta similarity index 100% rename from test_site/pattern/test/sub_pat/default.meta rename to tests/files/test_site/pattern/test/sub_pat/default.meta diff --git a/test_site/pattern/test/sub_pat/sub_pattern.meta b/tests/files/test_site/pattern/test/sub_pat/sub_pattern.meta similarity index 100% rename from test_site/pattern/test/sub_pat/sub_pattern.meta rename to tests/files/test_site/pattern/test/sub_pat/sub_pattern.meta diff --git a/test_site/source/expand.meta b/tests/files/test_site/source/expand.meta similarity index 100% rename from test_site/source/expand.meta rename to tests/files/test_site/source/expand.meta diff --git a/test_site/source/sub_dir/sub_source.meta b/tests/files/test_site/source/sub_dir/sub_source.meta similarity index 100% rename from test_site/source/sub_dir/sub_source.meta rename to tests/files/test_site/source/sub_dir/sub_source.meta diff --git a/test_site/source/test_source.meta b/tests/files/test_site/source/test_source.meta similarity index 100% rename from test_site/source/test_source.meta rename to tests/files/test_site/source/test_source.meta diff --git a/tests/metafile_builder.rs b/tests/metafile_builder.rs index 80f64e5..262ee9e 100644 --- a/tests/metafile_builder.rs +++ b/tests/metafile_builder.rs @@ -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 { - let dir = PathBuf::from("./test_site"); + let dir = PathBuf::from("./tests/files/test_site"); let dirs = RootDirs { source: dir.join("source"), -- 2.45.2