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