Skip to content

Commit

Permalink
XML::ADDED:: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frikilax committed Nov 14, 2021
1 parent 38533d9 commit 068f065
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -167,3 +171,7 @@ EXTRA_DIST = exec.sh \
if ENABLE_REGEXP
TESTS += $(REGEXP_TESTS)
endif

if ENABLE_XML
TESTS += $(XML_TESTS)
endif
36 changes: 36 additions & 0 deletions tests/field_xml.sh
Original file line number Diff line number Diff line change
@@ -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 '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note>'
assert_output_json_eq '{ "field": { "note": "This is a simple note"} }'

execute '<?xml version="1.0" encoding="UTF-8"?><note><one>first note</one><two>second note</two></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 '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note> ' # note the trailing space
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note<\/note> ", "unparsed-data": " " }'

execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note'
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note", "unparsed-data": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note" }'

execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note2>'
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note</note2>", "unparsed-data": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note</note2>" }'


cleanup_tmp_files

36 changes: 36 additions & 0 deletions tests/field_xml_jsoncnf.sh
Original file line number Diff line number Diff line change
@@ -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 '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note>'
assert_output_json_eq '{ "field": { "note": "This is a simple note"} }'

execute '<?xml version="1.0" encoding="UTF-8"?><note><one>first note</one><two>second note</two></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 '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note> ' # note the trailing space
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note<\/note> ", "unparsed-data": " " }'

execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note'
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note", "unparsed-data": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note" }'

execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note2>'
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note</note2>", "unparsed-data": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note</note2>" }'


cleanup_tmp_files

0 comments on commit 068f065

Please sign in to comment.