MCPcopy Index your code
hub / github.com/expr-lang/expr / TestRun_Cast

Function TestRun_Cast

vm/vm_test.go:63–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestRun_Cast(t *testing.T) {
64 tests := []struct {
65 input string
66 expect reflect.Kind
67 want any
68 }{
69 {
70 input: `1`,
71 expect: reflect.Float64,
72 want: float64(1),
73 },
74 {
75 input: `1`,
76 expect: reflect.Int,
77 want: int(1),
78 },
79 {
80 input: `1`,
81 expect: reflect.Int64,
82 want: int64(1),
83 },
84 {
85 input: `true`,
86 expect: reflect.Bool,
87 want: true,
88 },
89 {
90 input: `false`,
91 expect: reflect.Bool,
92 want: false,
93 },
94 {
95 input: `nil`,
96 expect: reflect.Bool,
97 want: false,
98 },
99 }
100
101 for _, tt := range tests {
102 t.Run(fmt.Sprintf("%v %v", tt.expect, tt.input), func(t *testing.T) {
103 tree, err := parser.Parse(tt.input)
104 require.NoError(t, err)
105
106 program, err := compiler.Compile(tree, &conf.Config{Expect: tt.expect})
107 require.NoError(t, err)
108
109 out, err := vm.Run(program, nil)
110 require.NoError(t, err)
111
112 require.Equal(t, tt.want, out)
113 })
114 }
115}
116
117func TestRun_Helpers(t *testing.T) {
118 values := []any{

Callers

nothing calls this directly

Calls 7

ParseFunction · 0.92
NoErrorFunction · 0.92
CompileFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92
RunMethod · 0.80
SprintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…