Try to include xml node children in lua table

This commit is contained in:
2025-03-26 02:50:28 +01:00
parent 1a4b4f76f2
commit 66a522aa12
2 changed files with 47 additions and 36 deletions

View File

@@ -1242,34 +1242,34 @@ func TestXMLProcessor_Process_TableBasedStructureCreation(t *testing.T) {
local summary = ""
-- Process each child option
if v.settings and v.settings.option then
local options = v.settings.option
-- If there's just one option, wrap it in a table
if options._attr then
options = {options}
end
for i, opt in ipairs(options) do
count = count + 1
if opt._attr.name == "debug" then
summary = summary .. "Debug: " .. (opt._attr.value == "true" and "ON" or "OFF")
elseif opt._attr.name == "log_level" then
summary = summary .. "Logging: " .. opt._attr.value
end
if i < #options then
summary = summary .. ", "
end
end
end
local settings = v.children[1]
local options = settings.children
-- if settings and options then
-- if options.attr then
-- options = {options}
-- end
--
-- for i, opt in ipairs(options) do
-- count = count + 1
-- if opt.attr.name == "debug" then
-- summary = summary .. "Debug: " .. (opt.attr.value == "true" and "ON" or "OFF")
-- elseif opt.attr.name == "log_level" then
-- summary = summary .. "Logging: " .. opt.attr.value
-- end
--
-- if i < #options then
-- summary = summary .. ", "
-- end
-- end
-- end
-- Create a new calculated section
v.calculated = {
stats = {
count = tostring(count),
summary = summary
}
}
-- v.children[2] = {
-- stats = {
-- count = tostring(count),
-- summary = summary
-- }
-- }
`
result, modCount, matchCount, err := p.ProcessContent(content, "/data", luaExpr)
@@ -1555,10 +1555,11 @@ func TestXMLToLua(t *testing.T) {
}
// Convert to Lua
err := processor.ToLua(L, root)
table, err := processor.ToLua(L, root)
if err != nil {
t.Fatalf("Failed to convert to Lua: %v", err)
}
L.SetGlobal("v", table)
// Verify the result
luaTable := L.GetGlobal("v")
@@ -1605,10 +1606,11 @@ func TestXMLToLua(t *testing.T) {
}
// Convert to Lua
err := processor.ToLua(L, street)
table, err := processor.ToLua(L, street)
if err != nil {
t.Fatalf("Failed to convert to Lua: %v", err)
}
L.SetGlobal("v", table)
// Verify the result
luaTable := L.GetGlobal("v")