Skip to content

Commit ccfb96b

Browse files
authored
Merge pull request #69 from strongdm/IDX-461-simplify-string
Allow to use types defined from bool, string, int and int64 as ast Values
2 parents 257623d + 2809a97 commit ccfb96b

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

ast/ast_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212
)
1313

1414
func TestASTByTable(t *testing.T) {
15+
type CustomString string
16+
type CustomBool bool
17+
type CustomInt int
18+
type CustomInt64 int64
1519
t.Parallel()
1620
tests := []struct {
1721
name string
@@ -143,6 +147,16 @@ func TestASTByTable(t *testing.T) {
143147
ast.Permit().When(ast.Boolean(true)),
144148
internalast.Permit().When(internalast.Boolean(true)),
145149
},
150+
{
151+
"customValueBoolFalse",
152+
ast.Permit().When(ast.Boolean(CustomBool(false))),
153+
internalast.Permit().When(internalast.Boolean(false)),
154+
},
155+
{
156+
"customValueBoolTrue",
157+
ast.Permit().When(ast.Boolean(CustomBool(true))),
158+
internalast.Permit().When(internalast.Boolean(true)),
159+
},
146160
{
147161
"valueTrue",
148162
ast.Permit().When(ast.True()),
@@ -158,6 +172,21 @@ func TestASTByTable(t *testing.T) {
158172
ast.Permit().When(ast.String("cedar")),
159173
internalast.Permit().When(internalast.String("cedar")),
160174
},
175+
{
176+
"customValueString",
177+
ast.Permit().When(ast.String(CustomString("cedar"))),
178+
internalast.Permit().When(internalast.String("cedar")),
179+
},
180+
{
181+
"customValueInt",
182+
ast.Permit().When(ast.Long(CustomInt(42))),
183+
internalast.Permit().When(internalast.Long(42)),
184+
},
185+
{
186+
"customValueInt64",
187+
ast.Permit().When(ast.Long(CustomInt64(42))),
188+
internalast.Permit().When(internalast.Long(42)),
189+
},
161190
{
162191
"valueLong",
163192
ast.Permit().When(ast.Long(42)),

ast/value.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// Boolean creates a value node containing a Boolean.
12-
func Boolean[T bool | types.Boolean](b T) Node {
12+
func Boolean[T ~bool](b T) Node {
1313
return wrapNode(ast.Boolean(types.Boolean(b)))
1414
}
1515

@@ -24,12 +24,12 @@ func False() Node {
2424
}
2525

2626
// String creates a value node containing a String.
27-
func String[T string | types.String](s T) Node {
27+
func String[T ~string](s T) Node {
2828
return wrapNode(ast.String(types.String(s)))
2929
}
3030

3131
// Long creates a value node containing a Long.
32-
func Long[T int | int64 | types.Long](l T) Node {
32+
func Long[T ~int | ~int64](l T) Node {
3333
return wrapNode(ast.Long(types.Long(l)))
3434
}
3535

0 commit comments

Comments
 (0)