Skip to content

Commit 7f286f5

Browse files
mccxjcoocood
authored andcommitted
types: add one more space to make json pretty (pingcap#7389)
1 parent 82a6c10 commit 7f286f5

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

executor/executor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ func (s *testSuite) TestJSON(c *C) {
12371237

12381238
var result *testkit.Result
12391239
result = tk.MustQuery(`select tj.a from test_json tj order by tj.id`)
1240-
result.Check(testkit.Rows(`{"a":[1,"2",{"aa":"bb"},4],"b":true}`, "null", "<nil>", "true", "3", "4", `"string"`))
1240+
result.Check(testkit.Rows(`{"a": [1, "2", {"aa": "bb"}, 4], "b": true}`, "null", "<nil>", "true", "3", "4", `"string"`))
12411241

12421242
// Check json_type function
12431243
result = tk.MustQuery(`select json_type(a) from test_json tj order by tj.id`)
@@ -1481,7 +1481,7 @@ func (s *testSuite) TestGeneratedColumnRead(c *C) {
14811481
tk.MustExec(`CREATE TABLE test_gc_read_cast_2( a JSON, b JSON AS (a->>'$.a'))`)
14821482
tk.MustExec(`INSERT INTO test_gc_read_cast_2(a) VALUES ('{"a": "{ \\\"key\\\": \\\"\\u6d4b\\\" }"}')`)
14831483
result = tk.MustQuery(`SELECT b FROM test_gc_read_cast_2`)
1484-
result.Check(testkit.Rows(`{"key":"测"}`))
1484+
result.Check(testkit.Rows(`{"key": "测"}`))
14851485

14861486
_, err := tk.Exec(`INSERT INTO test_gc_read_cast_1 (a, b) VALUES ('{"a": "invalid"}', '$.a')`)
14871487
c.Assert(err, NotNil)

executor/write_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ func (s *testSuite) TestUpdateCastOnlyModifiedValues(c *C) {
10491049
r.Check(testkit.Rows("300"))
10501050
tk.MustExec(`UPDATE update_with_diff_type SET b = '{"a": "\\u6d4b\\u8bd5"}'`)
10511051
r = tk.MustQuery("SELECT b FROM update_with_diff_type")
1052-
r.Check(testkit.Rows(`{"a":"测试"}`))
1052+
r.Check(testkit.Rows(`{"a": "测试"}`))
10531053
}
10541054

10551055
func (s *testSuite) fillMultiTableForUpdate(tk *testkit.TestKit) {
@@ -1782,13 +1782,13 @@ func (s *testSuite) TestInsertCalculatedValue(c *C) {
17821782
tk.MustExec("insert into t (b) value (a->'$.a'+1)")
17831783
tk.MustQuery("select * from t").Check(testkit.Rows("<nil> <nil> <nil>", "<nil> <nil> <nil>"))
17841784
tk.MustExec(`insert into t (a, b) value ('{"a": 1}', a->'$.a'+1)`)
1785-
tk.MustQuery("select * from t where c = 1").Check(testkit.Rows(`{"a":1} 2 1`))
1785+
tk.MustQuery("select * from t where c = 1").Check(testkit.Rows(`{"a": 1} 2 1`))
17861786
tk.MustExec("truncate table t")
17871787
tk.MustExec("insert t set b = c + 1")
17881788
tk.MustQuery("select * from t").Check(testkit.Rows("<nil> <nil> <nil>"))
17891789
tk.MustExec("truncate table t")
17901790
tk.MustExec(`insert t set a = '{"a": 1}', b = c`)
1791-
tk.MustQuery("select * from t").Check(testkit.Rows(`{"a":1} <nil> 1`))
1791+
tk.MustQuery("select * from t").Check(testkit.Rows(`{"a": 1} <nil> 1`))
17921792

17931793
tk.MustExec("drop table if exists t")
17941794
tk.MustExec("create table t(a int auto_increment key, b int)")

types/json/binary.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (bj BinaryJSON) marshalArrayTo(buf []byte) ([]byte, error) {
245245
buf = append(buf, '[')
246246
for i := 0; i < elemCount; i++ {
247247
if i != 0 {
248-
buf = append(buf, ',')
248+
buf = append(buf, ", "...)
249249
}
250250
var err error
251251
buf, err = bj.arrayGetElem(i).marshalTo(buf)
@@ -261,10 +261,10 @@ func (bj BinaryJSON) marshalObjTo(buf []byte) ([]byte, error) {
261261
buf = append(buf, '{')
262262
for i := 0; i < elemCount; i++ {
263263
if i != 0 {
264-
buf = append(buf, ',')
264+
buf = append(buf, ", "...)
265265
}
266266
buf = marshalStringTo(buf, bj.objectGetKey(i))
267-
buf = append(buf, ':')
267+
buf = append(buf, ": "...)
268268
var err error
269269
buf, err = bj.objectGetVal(i).marshalTo(buf)
270270
if err != nil {

types/json/binary_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func TestT(t *testing.T) {
2929

3030
func (s *testJSONSuite) TestBinaryJSONMarshalUnmarshal(c *C) {
3131
strs := []string{
32-
`{"a":[1,"2",{"aa":"bb"},4,null],"b":true,"c":null}`,
33-
`{"aaaaaaaaaaa":[1,"2",{"aa":"bb"},4.1],"bbbbbbbbbb":true,"ccccccccc":"d"}`,
34-
`[{"a":1,"b":true},3,3.5,"hello, world",null,true]`,
32+
`{"a": [1, "2", {"aa": "bb"}, 4, null], "b": true, "c": null}`,
33+
`{"aaaaaaaaaaa": [1, "2", {"aa": "bb"}, 4.1], "bbbbbbbbbb": true, "ccccccccc": "d"}`,
34+
`[{"a": 1, "b": true}, 3, 3.5, "hello, world", null, true]`,
3535
}
3636
for _, str := range strs {
3737
parsedBJ := mustParseBinaryFromString(c, str)
@@ -115,7 +115,7 @@ func (s *testJSONSuite) TestBinaryJSONUnquote(c *C) {
115115
{j: "\"\\u4f60\"", unquoted: "你"},
116116
{j: `true`, unquoted: "true"},
117117
{j: `null`, unquoted: "null"},
118-
{j: `{"a": [1, 2]}`, unquoted: `{"a":[1,2]}`},
118+
{j: `{"a": [1, 2]}`, unquoted: `{"a": [1, 2]}`},
119119
{j: `"\""`, unquoted: `"`},
120120
{j: `"'"`, unquoted: `'`},
121121
{j: `"''"`, unquoted: `''`},

0 commit comments

Comments
 (0)