-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathminify_test.go
More file actions
72 lines (64 loc) · 1.43 KB
/
minify_test.go
File metadata and controls
72 lines (64 loc) · 1.43 KB
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
package minify
import (
"bytes"
"testing"
)
type Test struct {
Before string;
Expected string;
}
func TestRemoveComments(t *testing.T) {
tests := []Test {
{
Before: `
// this is a JSON file with comments
{
"foo": "bar", // this is cool
"bar": [
"baz", "bum", "zam"
],
/* the rest of this document is just fluff
in case you are interested. */
"something": 10,
"else": 20
}
/* NOTE: You can easily strip the whitespace and comments
from such a file with the JSON.minify() project hosted
here on github at http://github.com/getify/JSON.minify
*/`,
Expected: `{"foo":"bar","bar":["baz","bum","zam"],"something":10,"else":20}`,
},
{
Before: `
{"/*":"*/","//":"",/*"//"*/"/*/"://
"//"}
`,
Expected: `{"/*":"*/","//":"","/*/":"//"}`,
},
{
Before: `
/*
this is a
multi line comment */{
"foo"
:
"bar/*"// something
, "b\\\"az":/*
something else */"blah"
}`,
Expected: `{"foo":"bar/*","b\\\"az":"blah"}`,
},
{
Before: `
{"foo": "ba\\\"r//", "bar\\\\": "b\\\\\\\"a/*z",
"baz\\\\\\\\": /* yay */ "fo\\\\\\\\\\\"*/o"
}`,
Expected: `{"foo":"ba\\\"r//","bar\\\\":"b\\\\\\\"a/*z","baz\\\\\\\\":"fo\\\\\\\\\\\"*/o"}`,
}};
for _, test := range tests {
after := JsonMinify(test.Before, true)
if !bytes.Equal([]byte(after), []byte(test.Expected)) {
t.Fatalf("Not the same:\nreal: %s\nExpected:%s\n", after, test.Expected)
}
}
}