Skip to content

Commit 624b8fe

Browse files
committed
test: normalize actual values to work with old/new libxml2
1 parent 9d4b75e commit 624b8fe

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

test/test-element.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,19 @@ function TestElement.test_append_element()
337337
})
338338
end
339339

340+
local function normalize_attributes_order(text)
341+
local normalized_text, n_substitutions =
342+
text:gsub([[class="A" id="1"]], [[id="1" class="A"]])
343+
return normalized_text
344+
end
345+
340346
function TestElement.test_append_element_with_attribute()
341347
local document = xmlua.XML.parse("<root/>")
342348
local root = document:root()
343349
local child = root:append_element("child", {id="1", class="A"})
344350
luaunit.assertEquals({
345-
child:to_xml(),
346-
document:to_xml(),
351+
normalize_attributes_order(child:to_xml()),
352+
normalize_attributes_order(document:to_xml()),
347353
},
348354
{
349355
[[<child id="1" class="A"/>]],
@@ -365,9 +371,9 @@ function TestElement.test_append_element_with_namespace()
365371
local root = document:root()
366372
local child = root:append_element("xhtml:child", {id="1", class="A"})
367373
luaunit.assertEquals({
368-
child:to_xml(),
374+
normalize_attributes_order(child:to_xml()),
369375
ffi.string(child.node.ns.href),
370-
document:to_xml(),
376+
normalize_attributes_order(document:to_xml()),
371377
},
372378
{
373379
[[<xhtml:child id="1" class="A"/>]],
@@ -567,8 +573,8 @@ function TestElement.test_insert_element_with_attributes()
567573
local root = document:root()
568574
local child = root:insert_element(2, "new-child", {id="1", class="A"})
569575
luaunit.assertEquals({
570-
child:to_xml(),
571-
document:to_xml(),
576+
normalize_attributes_order(child:to_xml()),
577+
normalize_attributes_order(document:to_xml()),
572578
},
573579
{
574580
[[<new-child id="1" class="A"/>]],
@@ -597,8 +603,8 @@ function TestElement.test_insert_element_with_namespace()
597603
"xhtml:new-child",
598604
{id="1", class="A"})
599605
luaunit.assertEquals({
600-
child:to_xml(),
601-
document:to_xml(),
606+
normalize_attributes_order(child:to_xml()),
607+
normalize_attributes_order(document:to_xml()),
602608
},
603609
{
604610
[[<xhtml:new-child id="1" class="A"/>]],

test/test-xml-build.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ function TestXMLBuild.test_root_namespace()
4343
})
4444
end
4545

46+
local function normalize_attributes_order(text)
47+
local normalized_text, n_substitutions =
48+
text:gsub([[id="1" class="A"]], [[class="A" id="1"]])
49+
normalized_text, n_substitutions =
50+
normalized_text:gsub([[id="2" class="B"]], [[class="B" id="2"]])
51+
return normalized_text
52+
end
53+
4654
function TestXMLBuild.test_root_children()
4755
local tree = {
4856
"root",
@@ -60,7 +68,7 @@ function TestXMLBuild.test_root_children()
6068
}
6169
}
6270
local document = XML.build(tree)
63-
luaunit.assertEquals(document:to_xml(),
71+
luaunit.assertEquals(normalize_attributes_order(document:to_xml()),
6472
[[
6573
<?xml version="1.0" encoding="UTF-8"?>
6674
<root class="A" id="1">This is text.<child class="B" id="2"/></root>
@@ -88,7 +96,7 @@ function TestXMLBuild.test_nested()
8896
}
8997
}
9098
local document = XML.build(tree)
91-
luaunit.assertEquals(document:to_xml(),
99+
luaunit.assertEquals(normalize_attributes_order(document:to_xml()),
92100
[[
93101
<?xml version="1.0" encoding="UTF-8"?>
94102
<root class="A" id="1">root text<child class="B" id="2">child text<grand-child/></child></root>

0 commit comments

Comments
 (0)