Skip to content

Commit c21c0be

Browse files
[#5] parse 添加对 tab 的处理
1 parent f2855ec commit c21c0be

File tree

5 files changed

+62
-53
lines changed

5 files changed

+62
-53
lines changed

decode/lexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (l *jsonParser) tokenizer() error {
171171
return errors.WithStack(err)
172172
}
173173
i = (*l).off
174-
case '\n', ' ', '\r':
174+
case '\n', ' ', '\r', 9:
175175
i++
176176
l.off++
177177
default:

parse_test.go

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,70 @@
11
package json_diff
22

33
import (
4+
"fmt"
45
"github.com/520MianXiangDuiXiang520/json-diff/decode"
5-
"io/ioutil"
6+
// "io/ioutil"
67
"testing"
78
)
89

9-
func BenchmarkMarshal(b *testing.B) {
10-
fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
11-
// fileName := "./test_data/hash_test.json"
12-
input, err := ioutil.ReadFile(fileName)
13-
if err != nil {
14-
b.Error("fail to open the ", fileName)
15-
}
16-
node, _ := decode.Unmarshal(input)
17-
b.ResetTimer()
18-
for i := 0; i < b.N; i++ {
19-
_, _ = decode.Marshal(node)
20-
}
10+
func TestUnmarshal(t *testing.T) {
11+
json2 := `{
12+
"A": 1, "B": [1, 3], "C": [2, 1], "D": 6
13+
}`
14+
node, err := decode.Unmarshal([]byte(json2))
15+
fmt.Println(node, err)
2116
}
2217

23-
func BenchmarkMarshalOld(b *testing.B) {
24-
fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
25-
// fileName := "./test_data/hash_test.json"
26-
input, err := ioutil.ReadFile(fileName)
27-
if err != nil {
28-
b.Error("fail to open the ", fileName)
29-
}
30-
node, _ := Unmarshal(input)
31-
b.ResetTimer()
32-
for i := 0; i < b.N; i++ {
33-
_, _ = Marshal(node)
34-
}
35-
}
36-
37-
func BenchmarkUnmarshal(b *testing.B) {
38-
fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
39-
// fileName := "./test_data/hash_test.json"
40-
input, err := ioutil.ReadFile(fileName)
41-
if err != nil {
42-
b.Error("fail to open the ", fileName)
43-
}
44-
b.ResetTimer()
45-
for i := 0; i < b.N; i++ {
46-
_, _ = decode.Unmarshal(input)
47-
}
48-
}
49-
50-
func BenchmarkUnmarshalOld(b *testing.B) {
51-
fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
52-
// fileName := "./test_data/hash_test.json"
53-
input, err := ioutil.ReadFile(fileName)
54-
if err != nil {
55-
b.Error("fail to open the ", fileName)
56-
}
57-
b.ResetTimer()
58-
for i := 0; i < b.N; i++ {
59-
_, _ = Unmarshal(input)
60-
}
61-
}
18+
// func BenchmarkMarshal(b *testing.B) {
19+
// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
20+
// // fileName := "./test_data/hash_test.json"
21+
// input, err := ioutil.ReadFile(fileName)
22+
// if err != nil {
23+
// b.Error("fail to open the ", fileName)
24+
// }
25+
// node, _ := decode.Unmarshal(input)
26+
// b.ResetTimer()
27+
// for i := 0; i < b.N; i++ {
28+
// _, _ = decode.Marshal(node)
29+
// }
30+
// }
31+
//
32+
// func BenchmarkMarshalOld(b *testing.B) {
33+
// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
34+
// // fileName := "./test_data/hash_test.json"
35+
// input, err := ioutil.ReadFile(fileName)
36+
// if err != nil {
37+
// b.Error("fail to open the ", fileName)
38+
// }
39+
// node, _ := Unmarshal(input)
40+
// b.ResetTimer()
41+
// for i := 0; i < b.N; i++ {
42+
// _, _ = Marshal(node)
43+
// }
44+
// }
45+
//
46+
// func BenchmarkUnmarshal(b *testing.B) {
47+
// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
48+
// // fileName := "./test_data/hash_test.json"
49+
// input, err := ioutil.ReadFile(fileName)
50+
// if err != nil {
51+
// b.Error("fail to open the ", fileName)
52+
// }
53+
// b.ResetTimer()
54+
// for i := 0; i < b.N; i++ {
55+
// _, _ = decode.Unmarshal(input)
56+
// }
57+
// }
58+
//
59+
// func BenchmarkUnmarshalOld(b *testing.B) {
60+
// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json"
61+
// // fileName := "./test_data/hash_test.json"
62+
// input, err := ioutil.ReadFile(fileName)
63+
// if err != nil {
64+
// b.Error("fail to open the ", fileName)
65+
// }
66+
// b.ResetTimer()
67+
// for i := 0; i < b.N; i++ {
68+
// _, _ = Unmarshal(input)
69+
// }
70+
// }
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)