MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestConvertToNativeJSONStructure

Function TestConvertToNativeJSONStructure

cel/cel_test.go:349–384  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

347}
348
349func TestConvertToNativeJSONStructure(t *testing.T) {
350 env, err := NewEnv()
351 if err != nil {
352 t.Fatalf("NewEnv() failed: %v", err)
353 }
354 ast, issues := env.Compile(`{
355 "parts": [{"kind": "text"}]
356 }`)
357 if issues != nil && issues.Err() != nil {
358 t.Fatal(issues.Err())
359 }
360
361 prg, err := env.Program(ast)
362 if err != nil {
363 t.Fatal(err)
364 }
365
366 result, _, err := prg.Eval(map[string]any{})
367 if err != nil {
368 t.Fatal(err)
369 }
370
371 native, err := result.ConvertToNative(types.JSONValueType)
372 if err != nil {
373 t.Fatal(err)
374 }
375
376 jsonBytes, err := json.Marshal(native)
377 if err != nil {
378 t.Fatalf("json.Marshal failed: %v", err)
379 }
380 want := `{"parts":[{"kind":"text"}]}`
381 if string(jsonBytes) != want {
382 t.Errorf("json.Marshal() failed, got : %s, wanted ", jsonBytes)
383 }
384}
385
386func TestCustomEnvError(t *testing.T) {
387 env, err := NewCustomEnv(StdLib(), StdLib())

Callers

nothing calls this directly

Calls 6

CompileMethod · 0.95
ProgramMethod · 0.95
ErrMethod · 0.80
NewEnvFunction · 0.70
EvalMethod · 0.65
ConvertToNativeMethod · 0.65

Tested by

no test coverage detected