-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSONUtilTest.vdmsl
47 lines (41 loc) · 2 KB
/
JSONUtilTest.vdmsl
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
module JSONUtilTest
imports from JSONUtil
types
VALUE renamed VALUE;
functions
strictParseJSON renamed strictParseJSON;
printJSON renamed printJSON;
exports all
definitions
values
NUMBERS = {0, 441, -39, 0.0, 3.14, -3.14, 3.14e0, 3.14e-1, 3.14e1};
STRINGS = {"abc", "abc\n", "\x41\x42", "\u0041\u0042"};
CONSTANTS = {true, false, nil};
ARRAYS = {[], [0], ["a", "b"]};
OBJECTS = {{|->}, {"key"|->"value"}, {""|->1, "key2"|->"value2"}};
VALUES = NUMBERS union STRINGS union CONSTANTS union ARRAYS union OBJECTS;
SEPARATORS = {"", " ", "\t", "\n", " "};
operations
assertEquals : VALUE * (bool * VALUE) ==> VALUE
assertEquals(expected, mk_(success, actual)) == return actual
pre success and expected = actual;
traces
print_and_parse_array:
let e1, e2 in set VALUES in
let v1 = [e1, e2] in
assertEquals(v1, strictParseJSON(printJSON(v1)));
print_and_parse_object:
let e1, e2 in set VALUES in
let key in set STRINGS in
let v1 = {key^"1"|->e1, key^"2"|->e2} in
assertEquals(v1, strictParseJSON(printJSON(v1)));
spaces_in_array:
let s1, s2, s3 in set SEPARATORS in
(assertEquals([true, false], strictParseJSON(s1^"["^s2^"true"^s3^","^s1^"false"^s2^"]"^s3));
assertEquals([true, false], strictParseJSON(s1^"["^s2^"true"^s3^","^s3^"false"^s1^"]"^s2)));
spaces_in_object:
let s1, s2, s3 in set SEPARATORS in
(assertEquals({"key1"|->true,"key2"|->false}, strictParseJSON(s1^"{"^s2^['\x22']^"key1"^['\x22']^s3^":"^s1^"true"^s2^","^s3^['\x22']^"key2"^['\x22']^s1^":"^s2^"false"^s3^"}"^s1));
assertEquals({"key1"|->true,"key2"|->false}, strictParseJSON(s1^"{"^s2^['\x22']^"key1"^['\x22']^s3^":"^s2^"true"^s3^","^s1^['\x22']^"key2"^['\x22']^s3^":"^s1^"false"^s2^"}"^s2));
assertEquals({"key1"|->true,"key2"|->false}, strictParseJSON(s1^"{"^s2^['\x22']^"key1"^['\x22']^s3^":"^s3^"true"^s1^","^s2^['\x22']^"key2"^['\x22']^s2^":"^s3^"false"^s1^"}"^s3)));
end JSONUtilTest