Skip to content

Commit 068f065

Browse files
committed
XML::ADDED:: Tests
1 parent 38533d9 commit 068f065

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

tests/Makefile.am

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ REGEXP_TESTS = \
158158
field_tokenized_with_regex.sh \
159159
field_regex_while_regex_support_is_disabled.sh
160160

161+
XML_TESTS = \
162+
field_xml.sh \
163+
field_xml_jsoncnf.sh
164+
161165
EXTRA_DIST = exec.sh \
162166
$(TESTS_SHELLSCRIPTS) \
163167
$(REGEXP_TESTS) \
@@ -167,3 +171,7 @@ EXTRA_DIST = exec.sh \
167171
if ENABLE_REGEXP
168172
TESTS += $(REGEXP_TESTS)
169173
endif
174+
175+
if ENABLE_XML
176+
TESTS += $(XML_TESTS)
177+
endif

tests/field_xml.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# added 2021-11-14 by Theo Bertin
3+
# This file is part of the liblognorm project, released under ASL 2.0
4+
. $srcdir/exec.sh
5+
6+
test_def $0 "XML field"
7+
add_rule 'version=2'
8+
add_rule 'rule=:%field:xml%'
9+
10+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note>'
11+
assert_output_json_eq '{ "field": { "note": "This is a simple note"} }'
12+
13+
execute '<?xml version="1.0" encoding="UTF-8"?><note><one>first note</one><two>second note</two></note>'
14+
assert_output_json_eq '{ "field": { "note": { "one": "first note", "two": "second note" } } }'
15+
16+
# execute '@cee: {"f1": "1", "f2": 2}'
17+
# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }'
18+
19+
# execute '@cee: {"f1": "1", "f2": 2}'
20+
# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }'
21+
22+
#
23+
# Things that MUST NOT work
24+
#
25+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note> ' # note the trailing space
26+
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note<\/note> ", "unparsed-data": " " }'
27+
28+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note'
29+
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" }'
30+
31+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note2>'
32+
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>" }'
33+
34+
35+
cleanup_tmp_files
36+

tests/field_xml_jsoncnf.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# added 2021-11-14 by Theo Bertin
3+
# This file is part of the liblognorm project, released under ASL 2.0
4+
. $srcdir/exec.sh
5+
6+
test_def $0 "XML field"
7+
add_rule 'version=2'
8+
add_rule 'rule=:%{"name":"field", "type":"xml"}%'
9+
10+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note>'
11+
assert_output_json_eq '{ "field": { "note": "This is a simple note"} }'
12+
13+
execute '<?xml version="1.0" encoding="UTF-8"?><note><one>first note</one><two>second note</two></note>'
14+
assert_output_json_eq '{ "field": { "note": { "one": "first note", "two": "second note" } } }'
15+
16+
# execute '@cee: {"f1": "1", "f2": 2}'
17+
# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }'
18+
19+
# execute '@cee: {"f1": "1", "f2": 2}'
20+
# assert_output_json_eq '{ "field": { "f1": "1", "f2": 2 } }'
21+
22+
#
23+
# Things that MUST NOT work
24+
#
25+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note> ' # note the trailing space
26+
assert_output_json_eq '{ "originalmsg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note>This is a simple note<\/note> ", "unparsed-data": " " }'
27+
28+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note'
29+
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" }'
30+
31+
execute '<?xml version="1.0" encoding="UTF-8"?><note>This is a simple note</note2>'
32+
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>" }'
33+
34+
35+
cleanup_tmp_files
36+

0 commit comments

Comments
 (0)