Skip to content

Commit

Permalink
builtin: add json quote integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
overbool committed Oct 6, 2018
1 parent 03a04d8 commit 8feb23d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3246,6 +3246,22 @@ func (s *testIntegrationSuite) TestFuncJSON(c *C) {
r = tk.MustQuery(`select json_unquote('hello'), json_unquote('world')`)
r.Check(testkit.Rows("hello world"))

r = tk.MustQuery(`select
json_quote(''),
json_quote('""'),
json_quote('a'),
json_quote('3'),
json_quote('{"a": "b"}'),
json_quote('{"a": "b"}'),
json_quote('hello,"quoted string",world'),
json_quote('hello,"宽字符",world'),
json_quote('Invalid Json string is OK'),
json_quote('1\u2232\u22322')
`)
r.Check(testkit.Rows(
`"" "\"\"" "a" "3" "{\"a\": \"b\"}" "{\"a\": \"b\"}" "hello,\"quoted string\",world" "hello,\"宽字符\",world" "Invalid Json string\tis OK" "1u2232u22322"`,
))

r = tk.MustQuery(`select json_extract(a, '$.a[1]'), json_extract(b, '$.b') from table_json`)
r.Check(testkit.Rows("\"2\" true", "<nil> <nil>"))

Expand Down
1 change: 1 addition & 0 deletions types/json/binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (bj BinaryJSON) Type() string {
}
}

// Quote is for JSON_QUOTE
func (bj BinaryJSON) Quote() string {
return strconv.Quote(hack.String(bj.GetString()))
}
Expand Down

0 comments on commit 8feb23d

Please sign in to comment.