-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson2huddle_test.tcl
160 lines (111 loc) · 3.92 KB
/
json2huddle_test.tcl
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#puts [::huddle::json2huddle {{"hola":23.3, "caracola": "jeje"}}]
package require tcltest
namespace import ::tcltest::*
source huddle.tcl
source json2huddle.tcl
namespace import ::huddle::json2huddle
test json2huddle-1.1 "test of parsing json string" -body {
json2huddle { "hello world" }
} -result {HUDDLE {s {hello world}}}
test json2huddle-1.2 "test of parsing json string" -body {
json2huddle { "Unicode characters: \u00e0\u00e8\u00ec\u00f2\u00f9\u00e1\u00e9\u00ed\u00f3\u00fa\u00e4\u00eb\u00ef\u00f6\u00fc" }
} -result {HUDDLE {s {Unicode characters: àèìòùáéíóúäëïöü}}}
test json2huddle-1.3 "test of parsing json string" -body {
json2huddle { "escaped tab:\tescaped quote \"" }
} -result {HUDDLE {s {escaped tab: escaped quote "}}}
test json2huddle-2.1 "test of parsing json number" -body {
json2huddle { 4 }
} -result {HUDDLE {num 4}}
test json2huddle-2.2 "test of parsing json number" -body {
json2huddle { 2.7 }
} -result {HUDDLE {num 2.7}}
test json2huddle-2.3 "test of parsing json number" -body {
json2huddle { -2.7e6 }
} -result {HUDDLE {num -2.7e6}}
test json2huddle-2.3 "test of parsing json number" -body {
json2huddle { 2345E-4 }
} -result {HUDDLE {num 2345E-4}}
test json2huddle-3.1 "test of parsing json boolean" -body {
json2huddle { true }
} -result {HUDDLE {b true}}
test json2huddle-3.1 "test of parsing json boolean" -body {
json2huddle { false }
} -result {HUDDLE {b false}}
test json2huddle-4.1 "test of parsing json null" -body {
json2huddle { null }
} -result {HUDDLE null}
test json2huddle-5.1 "test of parsing json array" -body {
json2huddle { [1,2, "3", 4, null, false] }
} -result {HUDDLE {L {{num 1} {num 2} {s 3} {num 4} null {b false}}}}
test json2huddle-5.2 "test of parsing json array" -body {
json2huddle { [ ] }
} -result {HUDDLE {L {}}}
test json2huddle-6.1 "test of parsing json dict" -body {
json2huddle { {"key1":"value1", "key2": 0, "key3": true,"key4":null} }
} -result {HUDDLE {D {key1 {s value1} key2 {num 0} key3 {b true} key4 null}}}
test json2huddle-6.2 "test of parsing json dict" -body {
json2huddle { { } }
} -result {HUDDLE {D {}}}
test json2huddle-7.1 "test of parsing json comments" -body {
json2huddle {
// this is a solidus double comment
"this is a string"
}
} -result {HUDDLE {s {this is a string}}}
test json2huddle-7.2 "test of parsing json comments" -body {
json2huddle {
/* c style
comment
*/
"this is a string"
}
} -result {HUDDLE {s {this is a string}}}
test json2huddle-7.2 "test of parsing json comments" -body {
json2huddle {
/* c style
comment
*/
// this is a solidus double comment
"this is a string"
/* c style comment */
// this is a solidus double comment
}
} -result {HUDDLE {s {this is a string}}}
test json2huddle-7.4 "test of parsing json comments" -body {
json2huddle {
// this is a solidus double comment
[
//another comment here
[],
{},
/* c style
comment
*/
null, false, true,
-5.0e-4]
}
} -result {HUDDLE {L {{L {}} {D {}} null {b false} {b true} {num -5.0e-4}}}}
test json2huddle-8.1 "test of parsing complex data structures in json" -body {
json2huddle {
{"menu1": {
"id": 234,
"value": "File:",
"unival": "\u6021:",
"popup": {
"menuitem": [
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
},
"menu2": {
"selected": true,
"texts": ["open", "close", "save as.."]
}
}
}
} -result {HUDDLE {D {menu1 {D {id {num 234} value {s File:} unival {s 怡:} popup {D {menuitem {L {{D {value {s Open} onclick {s OpenDoc()}}} {D {value {s Close} onclick {s CloseDoc()}}}}}}}}} menu2 {D {selected {b true} texts {L {{s open} {s close} {s {save as..}}}}}}}}}
test json2huddle-9.1 "test of no json" -body {
json2huddle { }
} -returnCodes {error} -result "Nothing to read"
tcltest::cleanupTests