-use crate::{metafile_to_string, parse_file, RootDirs};
+#![allow(dead_code, unused)]
+use crate::{metafile_to_string, parse_file, source, RootDirs, Source, Substitution};
use color_eyre::Result;
use std::path::PathBuf;
-static SOURCE: &str = include_str!("test_source.meta");
-static PRE_EXPAND: &str = include_str!("test_expand.meta");
-static POST_EXPAND: &str = include_str!("test_expanded");
+static SOURCE: &str = include_str!("./test_files/test_source.meta");
+static PATTERN: &str = include_str!("./test_files/test_pattern.meta");
+static PRE_EXPAND: &str = include_str!("./test_files/test_expand.meta");
+static POST_EXPAND: &str = include_str!("./test_files/test_expanded");
#[test]
fn test_metafile_gets() -> Result<()> {
Ok(())
}
+#[test]
+fn parse_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.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(())
+}
+
+#[test]
+fn parse_pattern_file() -> Result<()> {
+ 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(())
+}
+
+#[ignore = "todo: build tmp directory"]
#[test]
fn test_metafile_to_str() -> Result<()> {
let metafile = parse_file(PRE_EXPAND)?;
let file = metafile_to_string(&metafile, &dirs, None)?;
- assert_eq!(file, "");
+ assert_eq!(file, POST_EXPAND);
Ok(())
}
-use crate::{parse_file, source, Source, Substitution};
-use color_eyre::Result;
+use crate::parse_file;
-static SOURCE: &str = include_str!("test_source.meta");
-static PATTERN: &str = include_str!("test_pattern.meta");
+macro_rules! test_str (
+ ($s: expr) => {
+ let str = $s;
+ parse_file(str).unwrap();
+ };
+);
#[test]
-fn parse_meta_file() -> Result<()> {
- let source = parse_file(SOURCE)?;
+fn no_spaces_def() {
+ test_str!(r#"${v='v'}@{a=['a']}&{p='p'}"#);
+}
- assert_eq!(source.variables.get("var").unwrap(), &"good");
- assert_eq!(source.variables.get("blank"), None);
- assert_eq!(source.variables.get("not_here"), None);
+#[test]
+fn just_source() {
+ test_str!(r#"This is just a &{source} snippet"#);
+}
- 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);
+#[test]
+#[should_panic]
+fn key_with_spaces() {
+ test_str!(r#"${ key with spaces = "value" }"#);
+}
- 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);
+#[test]
+#[should_panic]
+fn value_missing_quote() {
+ test_str!(r#"${ key = "value missing quote }"#);
+}
- Ok(())
+#[test]
+#[should_panic]
+fn mixed_quotes() {
+ test_str!(r#"${ key = "value mixing quotes' }"#);
}
#[test]
-fn parse_pattern_file() -> Result<()> {
- let mut pattern_src = parse_file(PATTERN)?.source.into_iter();
+#[should_panic]
+fn spaces_in_substitution() {
+ test_str!(r#"This ${variable is not allowed}"#);
+}
- 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")));
+#[test]
+#[should_panic]
+fn missing_closing_brace() {
+ test_str!(r#"${ key = "value" "#);
+}
- Ok(())
+#[test]
+#[should_panic]
+fn map_in_source() {
+ test_str!(r#"This map: ${ is = "invalid" }"#);
}