Skip to content

Commit

Permalink
fix(xml): refactor for lazy require
Browse files Browse the repository at this point in the history
See #126
  • Loading branch information
rcarriga committed Oct 9, 2022
1 parent 79a3535 commit bd24d46
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/neotest/lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ M.xml = {
---@param xml_data string
---@return table
parse = function(xml_data)
local handler = xml_tree:new()
local handler = xml_tree()
local parser = xml.parser(handler)
parser:parse(xml_data)
return handler.root
Expand Down
4 changes: 3 additions & 1 deletion lua/neotest/lib/xml/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,6 @@ end
---Parses CDATA tag content.
tree.cdata = tree.text
tree.__index = tree
return tree
return function()
return tree:new()
end
43 changes: 43 additions & 0 deletions tests/unit/lib/xml_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local lib = require("neotest.lib")

describe("When receiving valid XML", function()
it("it is parsed correctly", function()
local xml_data = [[<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="TestProject\UserTest" file="my_file" tests="1" assertions="3" errors="0" warnings="0" failures="0" skipped="0" time="0.000923">
<testcase name="testClassConstructor" class="TestProject\UserTest" classname="TestProject.UserTest" file="my_file" line="13" assertions="3" time="0.000923"/>
</testsuite>
</testsuites>]]

local expected = {
testsuites = {
testsuite = {
_attr = {
assertions = "3",
errors = "0",
failures = "0",
file = "my_file",
name = "TestProject\\UserTest",
skipped = "0",
tests = "1",
time = "0.000923",
warnings = "0",
},
testcase = {
_attr = {
assertions = "3",
class = "TestProject\\UserTest",
classname = "TestProject.UserTest",
file = "my_file",
line = "13",
name = "testClassConstructor",
time = "0.000923",
},
},
},
},
}

assert.are.same(lib.xml.parse(xml_data), expected)
end)
end)

0 comments on commit bd24d46

Please sign in to comment.