Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Sep 11, 2022
1 parent 5a66cc4 commit 7f694ad
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7532,6 +7532,42 @@ func TestCastRealAsTime(t *testing.T) {
"<nil> <nil> <nil>"))
}

func TestJSONDepth(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a JSON)")
tk.MustGetErrCode(`insert into t
with recursive c1 as (select cast(1 as signed) c, json_array(1) as a
union
select c + 1, json_array_insert(a, concat('$', repeat('[0]', c)), json_array(1))
from c1
where c < 101)
select a from c1 where c > 100;`, errno.ErrJSONDocumentTooDeep)
tk.MustExec(`insert into t
with recursive c1 as (select cast(1 as signed) c, json_array(1) as a
union
select c + 1, json_array_insert(a, concat('$', repeat('[0]', c)), json_array(1))
from c1
where c < 100)
select a from c1 where c > 99;`)

err := tk.QueryToErr(`select json_array(a, 1) from t`)
require.Error(t, err)
// FIXME: mysql client shows the error.
//err = tk.QueryToErr(`select json_objectagg(1, a) from t;`)
//require.Error(t, err)
err = tk.QueryToErr(`select json_object(1, a) from t;`)
require.Error(t, err)
err = tk.QueryToErr(`select json_set(a, concat('$', repeat('[0]', 100)), json_array(json_array(3))) from t;`)
require.Error(t, err)
err = tk.QueryToErr(`select json_array_append(a, concat('$', repeat('[0]', 100)), 1) from t;`)
require.Error(t, err)
// FIXME: mysql client shows the error.
//err = tk.QueryToErr(`select json_arrayagg(a) from t;`)
//require.Error(t, err)
}

func TestCastJSONTimeDuration(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down

0 comments on commit 7f694ad

Please sign in to comment.