test_json.lua 771 B

1234567891011121314151617181920212223242526272829303132
  1. --
  2. -- tests/base/test_json.lua
  3. -- Tests the json API
  4. -- Copyright (c) 2017 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("premake_json")
  8. function suite.json_encode()
  9. local result = json.encode({foo = "bar"})
  10. result = result:gsub('%s*', ''),
  11. test.isequal(result, '{"foo":"bar"}')
  12. end
  13. function suite.json_decode()
  14. local result = json.decode('{ "foo": "bar" }')
  15. test.isequal(result, { foo = "bar" })
  16. end
  17. function suite.json_encode_error()
  18. local result, err = json.encode({ fubar = function() end })
  19. test.isnil(result)
  20. test.isequal(type(err), "string")
  21. end
  22. function suite.json_decode_error()
  23. local result, err = json.decode("fubar string")
  24. test.isnil(result)
  25. test.isequal(type(err), "string")
  26. end