diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-04 15:37:47 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-04 15:37:47 -0600 |
commit | 813049bf86f73015b6656cca38364df5aa06b098 (patch) | |
tree | 1094229ab2e650253f514effaf74102289f47f0d /src/makefile | |
parent | 050a3b166123be17c8dfdbd47e1b439040101884 (diff) | |
download | makers-813049bf86f73015b6656cca38364df5aa06b098.tar.gz makers-813049bf86f73015b6656cca38364df5aa06b098.zip |
add more function tests
Diffstat (limited to 'src/makefile')
-rw-r--r-- | src/makefile/functions.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index 9cd78f8..6e04b7a 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -373,6 +373,13 @@ mod test { } #[test] + fn strip() -> R { + let result = call!(strip " this is\tweirdly spaced text "); + assert_eq!(result, "this is weirdly spaced text"); + Ok(()) + } + + #[test] fn filter() -> R { let result = call!(filter "word", "this contains a word inside it"); assert_eq!(result, "word"); @@ -447,6 +454,95 @@ mod test { } #[test] + fn test_if() -> R { + let mut macros = MacroSet::new(); + macros.set( + "test1".to_owned(), + MacroSource::File, + TokenString::text("something"), + ); + macros.set("test2".to_owned(), MacroSource::File, TokenString::text("")); + + assert_eq!( + call( + "if", + &[ + TokenString::r#macro("test1"), + TokenString::text("success"), + TokenString::r#macro("failed"), + ], + ¯os + )?, + "success" + ); + assert_eq!( + call( + "if", + &[ + TokenString::r#macro("test2"), + "$(error failed)".parse()?, + TokenString::text("pass"), + ], + ¯os + )?, + "pass" + ); + Ok(()) + } + + #[test] + fn or() -> R { + assert_eq!( + call( + "or", + &[TokenString::text("yep"), TokenString::text("yeah")], + &MacroSet::new() + )?, + "yep" + ); + assert_eq!( + call( + "or", + &[ + TokenString::text(""), + TokenString::text("yeet"), + "$(error fail)".parse().unwrap() + ], + &MacroSet::new() + )?, + "yeet" + ); + + Ok(()) + } + + #[test] + fn and() -> R { + assert_eq!( + call( + "and", + &[TokenString::text("yep"), TokenString::text("yeah")], + &MacroSet::new() + )?, + "yeah" + ); + assert_eq!( + call( + "and", + &[ + TokenString::text("maybe"), + TokenString::text(""), + "$(error fail)".parse().unwrap() + ], + &MacroSet::new() + )?, + "" + ); + + Ok(()) + } + + #[test] fn foreach() -> R { let mut macros = MacroSet::new(); macros.set( |