From 49ada158b26ad2aa74e9840dd2e70cb90155bd66 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Thu, 4 May 2023 11:46:22 -0500 Subject: [PATCH] parser works on pattern files --- src/metafile.rs | 4 ++-- src/tests/test_parser.rs | 25 ++++++++++++++++++++++++- src/tests/test_pattern.meta | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/tests/test_pattern.meta diff --git a/src/metafile.rs b/src/metafile.rs index a82d809..9b6ec42 100644 --- a/src/metafile.rs +++ b/src/metafile.rs @@ -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), diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index db62c24..c03cb3c 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -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 index 0000000..4c083a4 --- /dev/null +++ b/src/tests/test_pattern.meta @@ -0,0 +1,15 @@ + +

This is a test for pattern.meta files

+ +

inserted variable: ${var}

+ + &{pat} + + @{array} + + + -- 2.45.2