@@ -89,13 +89,13 @@ func TestJsonFunctions(t *testing.T) {
8989 name : "json_extract invalid path" ,
9090 funcName : "json_extract" ,
9191 args : []interface {}{`{"name":"test"}` , "invalid_path" },
92- wantErr : true ,
92+ expected : nil ,
9393 },
9494 {
9595 name : "json_extract non-object" ,
9696 funcName : "json_extract" ,
9797 args : []interface {}{`[1,2,3]` , "$.name" },
98- wantErr : true ,
98+ expected : nil ,
9999 },
100100 {
101101 name : "json_valid true" ,
@@ -205,6 +205,42 @@ func TestJsonFunctions(t *testing.T) {
205205 args : []interface {}{`"hello"` },
206206 wantErr : true ,
207207 },
208+ {
209+ name : "json_extract map input" ,
210+ funcName : "json_extract" ,
211+ args : []interface {}{map [string ]interface {}{"name" : "test" , "value" : 123 }, "$.name" },
212+ expected : "test" ,
213+ },
214+ {
215+ name : "json_extract map input number" ,
216+ funcName : "json_extract" ,
217+ args : []interface {}{map [string ]interface {}{"name" : "test" , "value" : 123 }, "$.value" },
218+ expected : 123 ,
219+ },
220+ {
221+ name : "json_extract array input" ,
222+ funcName : "json_extract" ,
223+ args : []interface {}{[]interface {}{10 , 20 , 30 }, "$[1]" },
224+ expected : 20 ,
225+ },
226+ {
227+ name : "json_extract nested map" ,
228+ funcName : "json_extract" ,
229+ args : []interface {}{`{"a": {"b": 100}}` , "$.a.b" },
230+ expected : float64 (100 ),
231+ },
232+ {
233+ name : "json_extract nested array" ,
234+ funcName : "json_extract" ,
235+ args : []interface {}{`{"list": [1, 2, 3]}` , "$.list[2]" },
236+ expected : float64 (3 ),
237+ },
238+ {
239+ name : "json_extract complex path" ,
240+ funcName : "json_extract" ,
241+ args : []interface {}{map [string ]interface {}{"users" : []interface {}{map [string ]interface {}{"id" : 1 }, map [string ]interface {}{"id" : 2 }}}, "$.users[1].id" },
242+ expected : 2 ,
243+ },
208244 }
209245
210246 for _ , tt := range tests {
@@ -309,38 +345,38 @@ func TestJsonFunctionValidation(t *testing.T) {
309345// TestJsonFunctionCreation 测试JSON函数创建
310346func TestJsonFunctionCreation (t * testing.T ) {
311347 tests := []struct {
312- name string
313- constructor func () Function
348+ name string
349+ constructor func () Function
314350 expectedName string
315351 }{
316352 {
317- name : "ToJsonFunction" ,
318- constructor : func () Function { return NewToJsonFunction () },
353+ name : "ToJsonFunction" ,
354+ constructor : func () Function { return NewToJsonFunction () },
319355 expectedName : "to_json" ,
320356 },
321357 {
322- name : "FromJsonFunction" ,
323- constructor : func () Function { return NewFromJsonFunction () },
358+ name : "FromJsonFunction" ,
359+ constructor : func () Function { return NewFromJsonFunction () },
324360 expectedName : "from_json" ,
325361 },
326362 {
327- name : "JsonExtractFunction" ,
328- constructor : func () Function { return NewJsonExtractFunction () },
363+ name : "JsonExtractFunction" ,
364+ constructor : func () Function { return NewJsonExtractFunction () },
329365 expectedName : "json_extract" ,
330366 },
331367 {
332- name : "JsonValidFunction" ,
333- constructor : func () Function { return NewJsonValidFunction () },
368+ name : "JsonValidFunction" ,
369+ constructor : func () Function { return NewJsonValidFunction () },
334370 expectedName : "json_valid" ,
335371 },
336372 {
337- name : "JsonTypeFunction" ,
338- constructor : func () Function { return NewJsonTypeFunction () },
373+ name : "JsonTypeFunction" ,
374+ constructor : func () Function { return NewJsonTypeFunction () },
339375 expectedName : "json_type" ,
340376 },
341377 {
342- name : "JsonLengthFunction" ,
343- constructor : func () Function { return NewJsonLengthFunction () },
378+ name : "JsonLengthFunction" ,
379+ constructor : func () Function { return NewJsonLengthFunction () },
344380 expectedName : "json_length" ,
345381 },
346382 }
0 commit comments