-
Notifications
You must be signed in to change notification settings - Fork 235
/
function_test.go
51 lines (42 loc) · 1.41 KB
/
function_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
46
47
48
49
50
51
package db
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCustomFunctions(t *testing.T) {
t.Run("Nil arguments", func(t *testing.T) {
fn := Func("HELLO")
assert.Equal(t, "HELLO", fn.Name())
assert.Equal(t, []interface{}(nil), fn.Arguments())
})
t.Run("Single argument", func(t *testing.T) {
fn := Func("CONCAT", "a")
assert.Equal(t, "CONCAT", fn.Name())
assert.Equal(t, []interface{}{"a"}, fn.Arguments())
})
t.Run("Two arguments", func(t *testing.T) {
fn := Func("MOD", 29, 9)
assert.Equal(t, "MOD", fn.Name())
assert.Equal(t, []interface{}{29, 9}, fn.Arguments())
})
t.Run("Multiple arguments", func(t *testing.T) {
fn := Func("CONCAT", "a", "b", "c")
assert.Equal(t, "CONCAT", fn.Name())
assert.Equal(t, []interface{}{"a", "b", "c"}, fn.Arguments())
})
t.Run("Slice argument", func(t *testing.T) {
fn := Func("IN", []interface{}{"a", "b", "c"})
assert.Equal(t, "IN", fn.Name())
assert.Equal(t, []interface{}{[]interface{}{"a", "b", "c"}}, fn.Arguments())
})
t.Run("Slice argument with one element", func(t *testing.T) {
fn := Func("IN", []interface{}{"a"})
assert.Equal(t, "IN", fn.Name())
assert.Equal(t, []interface{}{[]interface{}{"a"}}, fn.Arguments())
})
t.Run("Nil slice argument", func(t *testing.T) {
fn := Func("IN", []interface{}(nil))
assert.Equal(t, "IN", fn.Name())
assert.Equal(t, []interface{}{[]interface{}(nil)}, fn.Arguments())
})
}