-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathcontext_test.go
More file actions
44 lines (33 loc) · 1.23 KB
/
Copy pathcontext_test.go
File metadata and controls
44 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package super_test
import (
"testing"
"github.com/brimdata/super"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestContextLookupByValueAndLookupTypeValue(t *testing.T) {
sctx := super.NewContext()
recType := sctx.MustLookupTypeRecord(nil)
tv := super.EncodeTypeValue(recType)
typ, err := sctx.LookupByValue(tv)
require.NoError(t, err)
assert.Equal(t, recType, typ)
// Overwriting tv should not affect sctx's cached type value for recType.
super.AppendTypeValue(tv[:0], super.TypeNull)
val := sctx.LookupTypeValue(recType)
assert.Exactly(t, super.EncodeTypeValue(recType), []byte(val.Bytes()))
}
func TestContextLookupTypeNamedErrors(t *testing.T) {
sctx := super.NewContext()
_, err := sctx.LookupTypeNamed("\xff", super.TypeNull)
assert.EqualError(t, err, `bad type name "\xff": invalid UTF-8`)
_, err = sctx.LookupTypeNamed("null", super.TypeNull)
assert.EqualError(t, err, `named type collides with primitive type: null`)
}
func TestContextLookupTypeNamedAndLookupTypeDef(t *testing.T) {
sctx := super.NewContext()
assert.Nil(t, sctx.LookupByName("x"))
named1, err := sctx.LookupTypeNamed("x", super.TypeNull)
require.NoError(t, err)
assert.Same(t, named1, sctx.LookupByName("x"))
}