use skaldpress::macro_processor::MacroProcessor;
fn run_macro_processor(input: &str) -> String {
let mut macro_processor = MacroProcessor::new();
macro_processor
.process_input(&input)
.expect("macro processing failed")
}
#[test]
fn test_smn_empty_string() {
assert_eq!(run_macro_processor(""), "");
}
#[test]
fn test_smp_non_macro_html() {
assert_eq!(
run_macro_processor(
"<html>
<p>This is a <em>test</em></p>
</html>"
),
"<html>
<p>This is a <em>test</em></p>
</html>",
);
}
#[test]
fn test_smp_define_1() {
assert_eq!(
run_macro_processor(
"define(TEMP, testvalue)
TEMP"
),
"
testvalue",
);
}
#[test]
fn test_smp_define_2() {
assert_eq!(
run_macro_processor("define(TEMP, TEMP2)define(TEMP)ifdef(TEMP2, TEMP2_ISDEF)"),
"TEMP2_ISDEF",
);
}
#[test]
fn test_smp_dnl_1() {
assert_eq!(
run_macro_processor(
"DNL
test"
),
"test",
);
}
#[test]
fn test_smp_dnl_2() {
assert_eq!(
run_macro_processor(
"DNL this is some random text that should not be included
test"
),
"test",
);
}
#[test]
fn test_smp_dnl_3() {
assert_eq!(
run_macro_processor(
"DNL ifdef(a, b, c)
test"
),
"test",
);
}
#[test]
fn test_smp_dnl_4() {
assert_eq!(
run_macro_processor(
"DNL
test"
),
"test",
);
}
#[test]
fn test_smp_snnl_1() {
assert_eq!(
run_macro_processor(
"SNNL
test"
),
"test",
);
}
#[test]
fn test_smp_snnl_2() {
assert_eq!(
run_macro_processor(
"SNNL
test"
),
"test",
);
}
#[test]
fn test_smp_snnl_3() {
assert_eq!(
run_macro_processor(
"define(MAC1, test)SNNL
MAC1 SNNL
test"
),
"test test",
);
}
#[test]
fn test_smp_ifdef_0() {
assert_eq!(
run_macro_processor("define(MAC1, test)ifdef(MAC1, MAC1_ISDEF)"),
"MAC1_ISDEF",
);
}
#[test]
fn test_smp_ifdef_1() {
assert_eq!(
run_macro_processor(
"define(MAC1, test)SNNL
ifdef(MAC1, MAC1_ISDEF)
ifdef(MAC2, MAC2_ISDEF, MAC2_ISNDEF)"
),
"MAC1_ISDEF
MAC2_ISNDEF",
);
}
#[test]
fn test_smp_ifdef_2() {
assert_eq!(run_macro_processor("ifdef(MAC, MAC_ISDEF)"), "",);
}
#[test]
fn test_smp_ifdef_3() {
assert_eq!(
run_macro_processor("ifdef(MAC, MAC_ISDEF, MAC_ISNDEF)"),
"MAC_ISNDEF",
);
}
#[test]
fn test_smp_ifndef_1() {
assert_eq!(run_macro_processor("ifndef(MAC, MAC_ISNDEF)"), "MAC_ISNDEF",);
}
#[test]
fn test_smp_ifndef_2() {
assert_eq!(
run_macro_processor(
"define(MAC, test)SNNL
ifndef(MAC, MAC_ISNDEF, MAC_ISDEF)"
),
"MAC_ISDEF",
);
}
#[test]
fn test_smp_ifndef_3() {
assert_eq!(
run_macro_processor(
"define(MAC, test)SNNL
ifndef(MAC, MAC_ISNDEF)"
),
"",
);
}
#[test]
fn test_smp_include_1() {
assert_eq!(
run_macro_processor("include(tests/example_include.smp)"),
"",
);
}
#[test]
fn test_smp_include_2() {
assert_eq!(
run_macro_processor(
"include(tests/example_include.smp)SNNL
ifdef(SMP, SMP_ISDEF, SMP_ISNDEF)"
),
"SMP_ISDEF",
);
}
#[test]
fn test_smp_ifeq_1() {
assert_eq!(run_macro_processor("ifeq(a, a, true, false)"), "true",);
}
#[test]
fn test_smp_ifeq_2() {
assert_eq!(run_macro_processor("ifeq(a, b, true, false)"), "false",);
}
#[test]
fn test_smp_ifeq_3() {
assert_eq!(run_macro_processor("ifeq(a, a, true)"), "true",);
}
#[test]
fn test_smp_ifeq_4() {
assert_eq!(run_macro_processor("ifeq(a, b, true)"), "",);
}
#[test]
fn test_smp_ifneq_1() {
assert_eq!(run_macro_processor("ifneq(a, a, true, false)"), "false",);
}
#[test]
fn test_smp_ifneq_2() {
assert_eq!(run_macro_processor("ifneq(a, b, true, false)"), "true",);
}
#[test]
fn test_smp_ifneq_3() {
assert_eq!(run_macro_processor("ifneq(a, a, true)"), "",);
}
#[test]
fn test_smp_ifneq_4() {
assert_eq!(run_macro_processor("ifneq(a, b, true)"), "true",);
}
#[test]
fn test_smp_shell_1() {
assert_eq!(run_macro_processor("shell(printf test)"), "test",);
}
#[test]
fn test_smp_expr_1() {
assert_eq!(
run_macro_processor("expr(1, +, 1)"),
"2
",
);
}