From 813049bf86f73015b6656cca38364df5aa06b098 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 4 Apr 2021 15:37:47 -0600 Subject: add more function tests --- src/makefile/functions.rs | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'src') 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 @@ -372,6 +372,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"); @@ -446,6 +453,95 @@ mod test { Ok(()) } + #[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(); -- cgit v1.2.3