|
| 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