| 2950 | } |
| 2951 | |
| 2952 | func 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 | |
| 2980 | func TestBytesLiteral_type(t *testing.T) { |
| 2981 | env := map[string]any{ |