1local ucl = require("ucl") 2 3function 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 32end 33 34test_simple() 35 36local 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 48print(ucl.to_format(table, 'ucl')) 49