-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_json_lexical.cpp
127 lines (112 loc) · 3.13 KB
/
test_json_lexical.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "../source/h2_unit.cpp"
SUITE(json lexical simple)
{
Case(empty)
{
const char* json = "";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(0, lexical.size());
}
Cases(brace, ("{}", " { } "))
{
const char* json = x;
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("{", "}"), lexical);
}
Cases(bracket, ("[]", " [ ] "))
{
const char* json = x;
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("[", "]"), lexical);
}
Case(comma)
{
const char* json = ",";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf(","), lexical);
}
Case(colon)
{
const char* json = ":";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf(":"), lexical);
}
Case(double quote)
{
const char* json = "\"hello\"";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("\"hello\""), lexical);
}
Case(single quote)
{
const char* json = "'hello'";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("'hello'"), lexical);
}
Case(pattern)
{
const char* json = "/hello/";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("/hello/"), lexical);
}
Case(normal string)
{
const char* json = "hello ";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("hello"), lexical);
}
Case(direct number)
{
const char* json = "1234 ";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("1234"), lexical);
}
Case(math expression)
{
const char* json = " 1 +2 ";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("1 +2"), lexical);
}
}
SUITE(json lexical escape)
{
Case(double quote)
{
const char* json = "\"he\\\"llo\"";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("\"he\\\"llo\""), lexical);
}
Case(single quote)
{
const char* json = "'he\\\'llo'";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("'he\\\'llo'"), lexical);
}
Case(normal)
{
const char* json = "\\\nhe\\\"llo";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("\\\nhe\\\"llo"), lexical);
}
}
CASE(json lexical complex)
{
const char* json = "{\"a1\": true, 'a2' : hello world, a3: [abc, 123, null]}";
h2::h2_vector<h2::h2_string> lexical;
h2::h2_json_lexical::parse(lexical, json);
OK(ListOf("{", "\"a1\"", ":", "true", ",", "'a2'", ":", "hello world", ",", "a3", ":", "[", "abc", ",", "123", ",", "null", "]", "}"), lexical);
}