From 068f06524a00d6d33d942a7b648425930caaabeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Bertin?= Date: Sun, 14 Nov 2021 17:38:37 +0000 Subject: [PATCH] XML::ADDED:: Tests --- tests/Makefile.am | 8 ++++++++ tests/field_xml.sh | 36 ++++++++++++++++++++++++++++++++++++ tests/field_xml_jsoncnf.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tests/field_xml.sh create mode 100644 tests/field_xml_jsoncnf.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index 8e2fdb2b..40a735da 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -158,6 +158,10 @@ REGEXP_TESTS = \ field_tokenized_with_regex.sh \ field_regex_while_regex_support_is_disabled.sh +XML_TESTS = \ + field_xml.sh \ + field_xml_jsoncnf.sh + EXTRA_DIST = exec.sh \ $(TESTS_SHELLSCRIPTS) \ $(REGEXP_TESTS) \ @@ -167,3 +171,7 @@ EXTRA_DIST = exec.sh \ if ENABLE_REGEXP TESTS += $(REGEXP_TESTS) endif + +if ENABLE_XML +TESTS += $(XML_TESTS) +endif diff --git a/tests/field_xml.sh b/tests/field_xml.sh new file mode 100644 index 00000000..2102a325 --- /dev/null +++ b/tests/field_xml.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# added 2021-11-14 by Theo Bertin +# This file is part of the liblognorm project, released under ASL 2.0 +. $srcdir/exec.sh + +test_def $0 "XML field" +add_rule 'version=2' +add_rule 'rule=:%field:xml%' + +execute 'This is a simple note' +assert_output_json_eq '{ "field": { "note": "This is a simple note"} }' + +execute 'first notesecond note' +assert_output_json_eq '{ "field": { "note": { "one": "first note", "two": "second note" } } }' + +# execute '@cee: {"f1": "1", "f2": 2}' +# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }' + +# execute '@cee: {"f1": "1", "f2": 2}' +# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }' + +# +# Things that MUST NOT work +# +execute 'This is a simple note ' # note the trailing space +assert_output_json_eq '{ "originalmsg": "This is a simple note<\/note> ", "unparsed-data": " " }' + +execute 'This is a simple note' +assert_output_json_eq '{ "originalmsg": "This is a simple note", "unparsed-data": "This is a simple note" }' + +execute 'This is a simple note' +assert_output_json_eq '{ "originalmsg": "This is a simple note", "unparsed-data": "This is a simple note" }' + + +cleanup_tmp_files + diff --git a/tests/field_xml_jsoncnf.sh b/tests/field_xml_jsoncnf.sh new file mode 100644 index 00000000..2bbaa5e2 --- /dev/null +++ b/tests/field_xml_jsoncnf.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# added 2021-11-14 by Theo Bertin +# This file is part of the liblognorm project, released under ASL 2.0 +. $srcdir/exec.sh + +test_def $0 "XML field" +add_rule 'version=2' +add_rule 'rule=:%{"name":"field", "type":"xml"}%' + +execute 'This is a simple note' +assert_output_json_eq '{ "field": { "note": "This is a simple note"} }' + +execute 'first notesecond note' +assert_output_json_eq '{ "field": { "note": { "one": "first note", "two": "second note" } } }' + +# execute '@cee: {"f1": "1", "f2": 2}' +# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }' + +# execute '@cee: {"f1": "1", "f2": 2}' +# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }' + +# +# Things that MUST NOT work +# +execute 'This is a simple note ' # note the trailing space +assert_output_json_eq '{ "originalmsg": "This is a simple note<\/note> ", "unparsed-data": " " }' + +execute 'This is a simple note' +assert_output_json_eq '{ "originalmsg": "This is a simple note", "unparsed-data": "This is a simple note" }' + +execute 'This is a simple note' +assert_output_json_eq '{ "originalmsg": "This is a simple note", "unparsed-data": "This is a simple note" }' + + +cleanup_tmp_files +