-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility_test.go
63 lines (61 loc) · 1.75 KB
/
utility_test.go
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
package goscripter
import (
"testing"
)
func TestBuildJavascript(t *testing.T) {
type testbuild struct {
body string
expect string
}
testcases := []testbuild{
{
body: "console.log('Awkarin is back!');",
expect: "<script type='text/javascript'>console.log('Awkarin is back!');</script>",
},
}
for _, vtc := range testcases {
actual := BuildJavascriptBundle(vtc.body)
if actual != vtc.expect {
t.Errorf("Mismatched on testcase : %+v", vtc)
}
}
}
func TestBuildCSS(t *testing.T) {
type testbuild struct {
body string
expect string
}
testcases := []testbuild{
{
body: "#awkarin{background:#AAAAAA;}",
expect: "<style>#awkarin{background:#AAAAAA;}</style>",
},
}
for _, vtc := range testcases {
actual := BuildCSSBundle(vtc.body)
if actual != vtc.expect {
t.Errorf("Mismatched on testcase : %+v", vtc)
}
}
}
func TestIsValidJSONString(t *testing.T) {
type testValidJSONString struct {
paramValue string
expectedValid bool
actualValid bool
}
testCases := []testValidJSONString{
{paramValue: "I still love my ex-girlfriend", expectedValid: false},
{paramValue: "{\"data\":\"bla bla bla\"}", expectedValid: true},
{paramValue: "{\"data\":{\"productID\":666,\"productName\":\"Jenglot\",\"productPrice\":45000,\"productPriceCurrency\":\"USD\"}}", expectedValid: true},
{paramValue: "{666}", expectedValid: false},
{paramValue: "{data:666}", expectedValid: false},
{paramValue: "{\"productIDs\":[123,234,345,456,567,678,789]}", expectedValid: true},
}
for _, test := range testCases {
test.actualValid = ValidateJSON(test.paramValue)
if test.actualValid != test.expectedValid {
t.Error("Result JSON Validation mismatched. Expected : ", test.expectedValid, " But got ", test.actualValid)
}
}
}