|
5 | 5 | package json5
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "bytes" |
9 | 8 | "math"
|
10 | 9 | "math/rand"
|
11 |
| - "reflect" |
12 | 10 | "testing"
|
13 | 11 | )
|
14 | 12 |
|
@@ -43,88 +41,6 @@ var ex1i = `[
|
43 | 41 | -5e+2
|
44 | 42 | ]`
|
45 | 43 |
|
46 |
| -func TestCompact(t *testing.T) { |
47 |
| - var buf bytes.Buffer |
48 |
| - for _, tt := range examples { |
49 |
| - buf.Reset() |
50 |
| - if err := Compact(&buf, []byte(tt.compact)); err != nil { |
51 |
| - t.Errorf("Compact(%#q): %v", tt.compact, err) |
52 |
| - } else if s := buf.String(); s != tt.compact { |
53 |
| - t.Errorf("Compact(%#q) = %#q, want original", tt.compact, s) |
54 |
| - } |
55 |
| - |
56 |
| - buf.Reset() |
57 |
| - if err := Compact(&buf, []byte(tt.indent)); err != nil { |
58 |
| - t.Errorf("Compact(%#q): %v", tt.indent, err) |
59 |
| - continue |
60 |
| - } else if s := buf.String(); s != tt.compact { |
61 |
| - t.Errorf("Compact(%#q) = %#q, want %#q", tt.indent, s, tt.compact) |
62 |
| - } |
63 |
| - } |
64 |
| -} |
65 |
| - |
66 |
| -func TestCompactSeparators(t *testing.T) { |
67 |
| - // U+2028 and U+2029 should be escaped inside strings. |
68 |
| - // They should not appear outside strings. |
69 |
| - tests := []struct { |
70 |
| - in, compact string |
71 |
| - }{ |
72 |
| - {"{\"\u2028\": 1}", `{"\u2028":1}`}, |
73 |
| - {"{\"\u2029\" :2}", `{"\u2029":2}`}, |
74 |
| - } |
75 |
| - for _, tt := range tests { |
76 |
| - var buf bytes.Buffer |
77 |
| - if err := Compact(&buf, []byte(tt.in)); err != nil { |
78 |
| - t.Errorf("Compact(%q): %v", tt.in, err) |
79 |
| - } else if s := buf.String(); s != tt.compact { |
80 |
| - t.Errorf("Compact(%q) = %q, want %q", tt.in, s, tt.compact) |
81 |
| - } |
82 |
| - } |
83 |
| -} |
84 |
| - |
85 |
| -func TestIndent(t *testing.T) { |
86 |
| - var buf bytes.Buffer |
87 |
| - for _, tt := range examples { |
88 |
| - buf.Reset() |
89 |
| - if err := Indent(&buf, []byte(tt.indent), "", "\t"); err != nil { |
90 |
| - t.Errorf("Indent(%#q): %v", tt.indent, err) |
91 |
| - } else if s := buf.String(); s != tt.indent { |
92 |
| - t.Errorf("Indent(%#q) = %#q, want original", tt.indent, s) |
93 |
| - } |
94 |
| - |
95 |
| - buf.Reset() |
96 |
| - if err := Indent(&buf, []byte(tt.compact), "", "\t"); err != nil { |
97 |
| - t.Errorf("Indent(%#q): %v", tt.compact, err) |
98 |
| - continue |
99 |
| - } else if s := buf.String(); s != tt.indent { |
100 |
| - t.Errorf("Indent(%#q) = %#q, want %#q", tt.compact, s, tt.indent) |
101 |
| - } |
102 |
| - } |
103 |
| -} |
104 |
| - |
105 |
| -type indentErrorTest struct { |
106 |
| - in string |
107 |
| - err error |
108 |
| -} |
109 |
| - |
110 |
| -var indentErrorTests = []indentErrorTest{ |
111 |
| - {`{"X": "foo", "Y"}`, &SyntaxError{"invalid character '}' after object key", 17}}, |
112 |
| - {`{"X": "foo" "Y": "bar"}`, &SyntaxError{"invalid character '\"' after object key:value pair", 13}}, |
113 |
| -} |
114 |
| - |
115 |
| -func TestIndentErrors(t *testing.T) { |
116 |
| - for i, tt := range indentErrorTests { |
117 |
| - slice := make([]uint8, 0) |
118 |
| - buf := bytes.NewBuffer(slice) |
119 |
| - if err := Indent(buf, []uint8(tt.in), "", ""); err != nil { |
120 |
| - if !reflect.DeepEqual(err, tt.err) { |
121 |
| - t.Errorf("#%d: Indent: %#v", i, err) |
122 |
| - continue |
123 |
| - } |
124 |
| - } |
125 |
| - } |
126 |
| -} |
127 |
| - |
128 | 44 | func diff(t *testing.T, a, b []byte) {
|
129 | 45 | for i := 0; ; i++ {
|
130 | 46 | if i >= len(a) || i >= len(b) || a[i] != b[i] {
|
|
0 commit comments