1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
local ucl = require("ucl")
function test_simple()
local expect =
'['..
'"float",1.5,'..
'"integer",5,'..
'"true",true,'..
'"false",false,'..
'"null",null,'..
'"string","hello",'..
'"array",[1,2],'..
'"object",{"key":"value"}'..
']'
-- Input to to_value matches the output of to_string:
local parser = ucl.parser()
local res,err = parser:parse_string(expect)
if not res then
print('parser error: ' .. err)
return 1
end
local obj = parser:get_object()
local got = ucl.to_json(obj, true)
if expect == got then
return 0
else
print(expect .. " == " .. tostring(got))
return 1
end
end
test_simple()
local table = {
str = 'value',
num = 100500,
null = ucl.null,
func = function ()
return 'huh'
end,
badfunc = function()
print("I'm bad")
end
}
print(ucl.to_format(table, 'ucl'))
|