summaryrefslogtreecommitdiff
path: root/tests/macro_processor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/macro_processor.rs')
-rw-r--r--tests/macro_processor.rs244
1 files changed, 244 insertions, 0 deletions
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(
+"<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
+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",
+ );
+}