-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_json.p8
74 lines (53 loc) · 1.45 KB
/
test_json.p8
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
-- Unit tests for the json module
-- by sparr
-- to run the tests use `pico8 -x tests/test_json.p8`
#include ../pico8lib/class.lua
#include ../pico8lib/strings.lua
#include ../pico8lib/log.lua
#include ../pico8lib/functions.lua
#include ../pico8lib/tables.lua
#include ../pico8lib/test.lua
#include ../pico8lib/json.lua
local suite = TestSuite("json.p8")
-- Parse test case
local Parse = TestCase("Parse")
function Parse:test_parse_integer ()
self:assert_equal(json'123', 123)
end
function Parse:test_parse_decimal ()
self:assert_equal(json'1.5', 1.5)
end
function Parse:test_parse_hex ()
self:assert_equal(json'0xa.a', 10+5/8)
end
function Parse:test_parse_binary ()
self:assert_equal(json'0b1010', 10)
end
function Parse:test_parse_string ()
self:assert_equal(json'"abc"', "abc")
end
function Parse:test_parse_null ()
self:assert_equal(json'null', json.null)
end
function Parse:test_parse_true ()
self:assert_equal(json'true', true)
end
function Parse:test_parse_false ()
self:assert_equal(json'false', false)
end
function Parse:test_parse_deep ()
self:assert_equal(json'{"abc":[1,2,{"def":[1,"xyz"]}]}'.abc[3].def[2], "xyz")
end
function Parse:test_parse_multiline ()
self:assert_equal(json[[
{"1 a":"abc"}
]]["1 a"], "abc")
end
function Parse:test_parse_whitespace ()
self:assert_equal(json' [ { "a b" : "c d" } ] '[1]["a b"], "c d")
end
suite:add_test_case(Parse)
run_suites{suite}