From 541f983def407f1f2a3ebed859e37d9f00c83111 Mon Sep 17 00:00:00 2001 From: Qrius Date: Thu, 26 Sep 2024 00:11:05 +0200 Subject: Initial commit --- tests/example_include.smp | 1 + tests/macro_processor.rs | 244 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 tests/example_include.smp create mode 100644 tests/macro_processor.rs (limited to 'tests') diff --git a/tests/example_include.smp b/tests/example_include.smp new file mode 100644 index 0000000..ce45d39 --- /dev/null +++ b/tests/example_include.smp @@ -0,0 +1 @@ +define(SMP)DNL diff --git a/tests/macro_processor.rs b/tests/macro_processor.rs new file mode 100644 index 0000000..0c3651c --- /dev/null +++ b/tests/macro_processor.rs @@ -0,0 +1,244 @@ +use skaldpress::macro_processor::MacroProcessor; + +fn run_macro_processor(input: &str) -> String { + let mut macro_processor = MacroProcessor::new(); + macro_processor.process_input(&input) +} + +#[test] +fn test_smn_empty_string() { + assert_eq!( + run_macro_processor(""), + "" + ); +} + +#[test] +fn test_smp_non_macro_html() { + assert_eq!( + run_macro_processor( +" +

This is a test

+"), + +" +

This is a test

+", + ); +} + +#[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 +test"), + +"test", + ); +} + +#[test] +fn test_smp_dnl_3() { + assert_eq!( + run_macro_processor( +"define(MAC1, test)DNL +MAC1 DNL +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)DNL +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)DNL +ifndef(MAC, MAC_ISNDEF, MAC_ISDEF)"), + +"MAC_ISDEF", + ); +} + +#[test] +fn test_smp_ifndef_3() { + assert_eq!( + run_macro_processor( +"define(MAC, test)DNL +ifndef(MAC, MAC_ISNDEF)"), + +"", + ); +} + +#[test] +fn test_include_1() { + assert_eq!( + run_macro_processor( +"include(tests/example_include.smp)"), + +"", + ); +} + +#[test] +fn test_include_2() { + assert_eq!( + run_macro_processor( +"include(tests/example_include.smp)DNL +ifdef(SMP, SMP_ISDEF, SMP_ISNDEF)"), + +"SMP_ISDEF", + ); +} + +#[test] +fn test_ifeq_1() { + assert_eq!( + run_macro_processor("ifeq(a, a, true, false)"), + "true", + ); +} + +#[test] +fn test_ifeq_2() { + assert_eq!( + run_macro_processor("ifeq(a, b, true, false)"), + "false", + ); +} + +#[test] +fn test_ifeq_3() { + assert_eq!( + run_macro_processor("ifeq(a, a, true)"), + "true", + ); +} + +#[test] +fn test_ifeq_4() { + assert_eq!( + run_macro_processor("ifeq(a, b, true)"), + "", + ); +} + +#[test] +fn test_ifneq_1() { + assert_eq!( + run_macro_processor("ifneq(a, a, true, false)"), + "false", + ); +} + +#[test] +fn test_ifneq_2() { + assert_eq!( + run_macro_processor("ifneq(a, b, true, false)"), + "true", + ); +} + +#[test] +fn test_ifneq_3() { + assert_eq!( + run_macro_processor("ifneq(a, a, true)"), + "", + ); +} + +#[test] +fn test_ifneq_4() { + assert_eq!( + run_macro_processor("ifneq(a, b, true)"), + "true", + ); +} -- cgit v1.2.3