Skip to content

Commit bf4cdac

Browse files
committed
Add #node_name
1 parent 1ec7d17 commit bf4cdac

25 files changed

+138
-0
lines changed

test/test-attribute.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ local xmlua = require("xmlua")
33

44
TestAttribute = {}
55

6+
function TestAttribute.test_node_name()
7+
local document = xmlua.XML.build({"root", {["id"]="1"}})
8+
local attr = document:search("/root/@id")
9+
luaunit.assertEquals(attr[1]:node_name(),
10+
"attribute")
11+
end
12+
613
function TestAttribute.test_path()
714
local document =
815
xmlua.XML.build({"root", {["id"]="1"}})

test/test-cdata-section.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ local xmlua = require("xmlua")
33

44
TestCDATASection = {}
55

6+
function TestCDATASection.test_node_name()
7+
local document = xmlua.XML.parse([=[
8+
<root><![CDATA[This is <CDATA>]]></root>
9+
]=])
10+
local cdata_section = document:search("/root/text()")
11+
luaunit.assertEquals(cdata_section[1]:node_name(),
12+
"cdata-section")
13+
end
14+
615
function TestCDATASection.test_path()
716
local document = xmlua.XML.parse([=[
817
<root><![CDATA[This is <CDATA>]]></root>

test/test-comment.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ local xmlua = require("xmlua")
33

44
TestComment = {}
55

6+
function TestComment.test_node_Name()
7+
local document = xmlua.XML.parse([[
8+
<root>
9+
<!--This is comment!-->
10+
</root>
11+
]])
12+
local comment = document:search("/root/comment()")
13+
luaunit.assertEquals(comment[1]:node_name(),
14+
"comment")
15+
end
16+
617
function TestComment.test_path()
718
local document = xmlua.XML.parse([[
819
<root>

test/test-document.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ local ffi = require("ffi")
44

55
TestDocument = {}
66

7+
function TestDocument.test_node_name()
8+
local document = xmlua.XML.build({"root"})
9+
luaunit.assertEquals(document:node_name(),
10+
"document")
11+
end
12+
713
function TestDocument.test_create_cdata_section()
814
local document = xmlua.XML.build({"root"})
915
local cdata_section_node =

test/test-element.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ local function get_prop(node, name, namespace_uri)
1212
end
1313
end
1414

15+
function TestElement.test_node_name()
16+
local document = xmlua.XML.parse([[
17+
<html>
18+
<head>
19+
<title>Title</title>
20+
</head>
21+
</html>
22+
]])
23+
local node_set = document:search("//title")
24+
luaunit.assertEquals(node_set[1]:node_name(),
25+
"element")
26+
end
27+
1528
function TestElement.test_to_html()
1629
local document = xmlua.XML.parse([[
1730
<html>

test/test-processing-instruction.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ local xmlua = require("xmlua")
33

44
TestProcessingInstruction = {}
55

6+
function TestProcessingInstruction.test_node_name()
7+
local document = xmlua.XML.parse([[
8+
<?xml version="1.0" encoding="UTF-8" ?>
9+
<?xml-stylesheet href="www.test.com/test-style.xsl" type="text/xsl" ?>
10+
<root/>
11+
]])
12+
local pi = document:search("/processing-instruction()")
13+
luaunit.assertEquals(pi[1]:node_name(),
14+
"processing-instruction")
15+
end
16+
617
function TestProcessingInstruction.test_path()
718
local document = xmlua.XML.parse([[
819
<?xml version="1.0" encoding="UTF-8" ?>

test/test-text.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ local xmlua = require("xmlua")
33

44
TestText = {}
55

6+
function TestText.test_node_name()
7+
local document = xmlua.XML.parse([[
8+
<root>text</root>
9+
]])
10+
local text = document:search("/root/text()")
11+
luaunit.assertEquals(text[1]:node_name(),
12+
"text")
13+
end
14+
615
function TestText.test_path()
716
local document = xmlua.XML.parse([[
817
<root>text</root>

xmlua/attribute-declaration.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function metatable.__index(element, key)
1010
Node[key]
1111
end
1212

13+
function methods:node_name()
14+
return "attribute-declaration"
15+
end
16+
1317
function AttributeDeclaration.new(document, node)
1418
local attribute_declaration = {
1519
document = document,

xmlua/attribute.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function metatable.__index(element, key)
1212
Node[key]
1313
end
1414

15+
function methods:node_name()
16+
return "attribute"
17+
end
18+
1519
function methods:name()
1620
return ffi.string(self.node.name)
1721
end

xmlua/cdata-section.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function metatable.__index(element, key)
1010
Node[key]
1111
end
1212

13+
function methods:node_name()
14+
return "cdata-section"
15+
end
16+
1317
function CDATASection.new(document, node)
1418
local cdata_section = {
1519
document = document,

0 commit comments

Comments
 (0)