MCPcopy Create free account
hub / github.com/expr-lang/expr / TestBytesLiteral

Function TestBytesLiteral

expr_test.go:2952–2978  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2950}
2951
2952func TestBytesLiteral(t *testing.T) {
2953 tests := []struct {
2954 code string
2955 want []byte
2956 }{
2957 {`b"hello"`, []byte("hello")},
2958 {`b'world'`, []byte("world")},
2959 {`b""`, []byte{}},
2960 {`b'\x00\xff'`, []byte{0, 255}},
2961 {`b"\x41\x42\x43"`, []byte("ABC")},
2962 {`b'\101\102\103'`, []byte("ABC")},
2963 {`b'\n\t\r'`, []byte{'\n', '\t', '\r'}},
2964 {`b'hello\x00world'`, []byte("hello\x00world")},
2965 {`b"ÿ"`, []byte{0xc3, 0xbf}}, // UTF-8 encoding of ÿ
2966 }
2967
2968 for _, tt := range tests {
2969 t.Run(tt.code, func(t *testing.T) {
2970 program, err := expr.Compile(tt.code)
2971 require.NoError(t, err)
2972
2973 output, err := expr.Run(program, nil)
2974 require.NoError(t, err)
2975 assert.Equal(t, tt.want, output)
2976 })
2977 }
2978}
2979
2980func TestBytesLiteral_type(t *testing.T) {
2981 env := map[string]any{

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…