-
Notifications
You must be signed in to change notification settings - Fork 0
/
t_jel_test.go
45 lines (38 loc) · 850 Bytes
/
t_jel_test.go
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
45
package sqlb
import (
"testing"
"time"
)
func Test_Jel_Transcode(t *testing.T) {
type Internal struct {
InternalTime *time.Time `json:"internalTime" db:"internal_time"`
}
type External struct {
ExternalName string `json:"externalName" db:"external_name"`
Internal Internal `json:"internal" db:"internal"`
}
const src = `
["and",
["or",
false,
["=", "externalName", ["externalName", "literal string"]]
],
["and",
true,
["<", "internal.internalTime", ["internal.internalTime", "9999-01-01T00:00:00Z"]]
]
]
`
expr := Jel{typeElemOf((*External)(nil)), src}
text, args := Reify(expr)
eq(
t,
`(($1 or ("external_name" = $2)) and ($3 and (("internal")."internal_time" < $4)))`,
text,
)
eq(
t,
[]any{false, `literal string`, true, parseTime(`9999-01-01T00:00:00Z`)},
args,
)
}