From: Huck Boles Date: Wed, 3 May 2023 23:51:01 +0000 (-0500) Subject: meta source test X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=9dbef9fd6959b40b7252849265883699fe41b82a;p=metaforge.git meta source test --- diff --git a/src/tests.rs b/src/tests.rs index e69de29..33567a0 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -0,0 +1 @@ +mod test_parser; diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs new file mode 100644 index 0000000..c404f84 --- /dev/null +++ b/src/tests/test_parser.rs @@ -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 index 0000000..21fb37b --- /dev/null +++ b/src/tests/test_source.meta @@ -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: !@#$%^&*(){}_+