Skip to content

Commit 30ad711

Browse files
committed
test: adds a basic c14n test
1 parent c481971 commit 30ad711

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

test/run-test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require("test.test-css-select")
1414
require("test.test-xml-build")
1515
require("test.test-html-build")
1616
require("test.test-document")
17+
require("test.test-document-c14n")
1718
require("test.test-element")
1819
require("test.test-node-set")
1920
require("test.test-text")

test/test-document-c14n.lua

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
local luaunit = require("luaunit")
2+
local xmlua = require("xmlua")
3+
local ffi = require("ffi")
4+
5+
TestDocumentC14N = {}
6+
7+
-- From: https://www.w3.org/2008/xmlsec/Drafts/c14n-20/test-cases/Overview.src.html
8+
9+
function TestDocumentC14N.test_PIs_Comments_and_Outside_of_Document_Element()
10+
-- https://www.w3.org/2008/xmlsec/Drafts/c14n-20/test-cases/files/inC14N1.xml
11+
local input = [[
12+
<?xml version="1.0"?>
13+
14+
<?xml-stylesheet href="doc.xsl"
15+
type="text/xsl" ?>
16+
17+
<!DOCTYPE doc SYSTEM "doc.dtd">
18+
19+
<doc>Hello, world!<!-- Comment 1 --></doc>
20+
21+
<?pi-without-data ?>
22+
23+
<!-- Comment 2 -->
24+
25+
<!-- Comment 3 -->
26+
]]
27+
local options = {}
28+
-- https://www.w3.org/2008/xmlsec/Drafts/c14n-20/test-cases/files/out_inC14N1_c14nDefault.xml
29+
local expected = [[
30+
<?xml-stylesheet href="doc.xsl"
31+
type="text/xsl" ?>
32+
<doc>Hello, world!</doc>
33+
<?pi-without-data?>]]
34+
35+
local document = xmlua.XML.parse(input)
36+
local c14n = document:canonicalize(nil, options)
37+
luaunit.assertEquals(c14n, expected)
38+
end
39+
40+
function TestDocumentC14N.test_PIs_Comments_and_Outside_of_Document_Element_with_comments()
41+
-- https://www.w3.org/2008/xmlsec/Drafts/c14n-20/test-cases/files/inC14N1.xml
42+
local input = [[
43+
<?xml version="1.0"?>
44+
45+
<?xml-stylesheet href="doc.xsl"
46+
type="text/xsl" ?>
47+
48+
<!DOCTYPE doc SYSTEM "doc.dtd">
49+
50+
<doc>Hello, world!<!-- Comment 1 --></doc>
51+
52+
<?pi-without-data ?>
53+
54+
<!-- Comment 2 -->
55+
56+
<!-- Comment 3 -->
57+
]]
58+
local options = {
59+
with_comments = true
60+
}
61+
-- https://www.w3.org/2008/xmlsec/Drafts/c14n-20/test-cases/files/out_inC14N1_c14nComment.xml
62+
local expected = [[
63+
<?xml-stylesheet href="doc.xsl"
64+
type="text/xsl" ?>
65+
<doc>Hello, world!<!-- Comment 1 --></doc>
66+
<?pi-without-data?>
67+
<!-- Comment 2 -->
68+
<!-- Comment 3 -->]]
69+
70+
local document = xmlua.XML.parse(input)
71+
local c14n = document:canonicalize(nil, options)
72+
luaunit.assertEquals(c14n, expected)
73+
end

0 commit comments

Comments
 (0)