MCPcopy Create free account
hub / github.com/araddon/qlbridge / TestIdentityNames

Function TestIdentityNames

expr/node_test.go:85–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83var _ = u.EMPTY
84
85func TestIdentityNames(t *testing.T) {
86 m := map[string]string{
87 `count(visits)`: "ct_visits",
88 `x = y`: "x",
89 `x = y AND q = z`: "x",
90 `min(year)`: "min_year",
91 `todate(year)`: "year",
92 `mapct(name)`: "cts_name",
93 `AND( year > 10)`: "year",
94 }
95 for expr_str, expected := range m {
96 ex, err := expr.ParseExpression(expr_str)
97 assert.Equal(t, nil, err)
98 assert.Equal(t, expected, expr.FindIdentityName(0, ex, ""), "expected: %v for %v", expected, expr_str)
99 }
100 ne := expr.MustParse(`1 + "hello"`)
101 n := expr.MustParse("eq(hello, world)")
102 assert.Equal(t, "", expr.FindFirstIdentity(ne))
103 assert.Equal(t, "hello", expr.FindFirstIdentity(n))
104 assert.Equal(t, []string{"hello", "world"}, expr.FindAllLeftIdentityFields(n))
105 assert.Equal(t, []string{"hello", "world"}, expr.FindAllIdentityField(n))
106
107 assert.Equal(t, []string{"user.name", "world"}, expr.FindAllIdentityField(expr.MustParse("eq(user.name, world)")))
108
109 assert.Equal(t, []string{"user", "world"}, expr.FindAllLeftIdentityFields(expr.MustParse("eq(user.name, world)")))
110
111 assert.Equal(t, "", expr.FindFirstIdentity(expr.MustParse(`6 + toint("world")`)))
112 assert.Equal(t, "name", expr.FindFirstIdentity(expr.MustParse(`AND (
113 6 > 5
114 toint(name)
115 )`)))
116 assert.Equal(t, "email", expr.FindFirstIdentity(expr.MustParse(`AND (
117 NOT EXISTS email
118 X between 4 and 5
119 )`)))
120 assert.Equal(t, "X", expr.FindFirstIdentity(expr.MustParse(`AND (
121 X between 4 and 5
122 )`)))
123 assert.Equal(t, "Z", expr.FindFirstIdentity(expr.MustParse(`AND (
124 "x" in (4,5,Z)
125 )`)))
126 assert.Equal(t, []string{"email", "name"}, expr.FilterSpecialIdentities([]string{"email", "name", "TRUE"}))
127}
128
129func TestValueTypeFromExpression(t *testing.T) {
130 assert.Equal(t, value.UnknownType, expr.ValueTypeFromNode(expr.MustParse(`username`)))

Callers

nothing calls this directly

Calls 8

ParseExpressionFunction · 0.92
FindIdentityNameFunction · 0.92
MustParseFunction · 0.92
FindFirstIdentityFunction · 0.92
FindAllIdentityFieldFunction · 0.92
FilterSpecialIdentitiesFunction · 0.92
EqualMethod · 0.65

Tested by

no test coverage detected