forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparam_test.go
More file actions
82 lines (68 loc) · 2.03 KB
/
param_test.go
File metadata and controls
82 lines (68 loc) · 2.03 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package named
import "testing"
func TestMergeParamNullability(t *testing.T) {
type test struct {
a Param
b Param
notNull bool
message string
}
name := "name"
unspec := NewParam(name)
inferredNotNull := NewInferredParam(name, true)
inferredNull := NewInferredParam(name, false)
userDefNull := NewUserNullableParam(name)
const notNull = true
const null = false
tests := []test{
// Unspecified nullability parameter works
{unspec, inferredNotNull, notNull, "Unspec + inferred(not null) = not null"},
{unspec, inferredNull, null, "Unspec + inferred(not null) = null"},
{unspec, userDefNull, null, "Unspec + userdef(null) = null"},
// Inferred nullability agreeing with user defined nullabilty
{inferredNull, userDefNull, null, "inferred(null) + userdef(null) = null"},
// Inferred nullability disagreeing with user defined nullabilty
{inferredNotNull, userDefNull, null, "inferred(not null) + userdef(null) = null"},
}
for _, spec := range tests {
a := spec.a
b := spec.b
actual := mergeParam(a, b).NotNull()
expected := spec.notNull
if actual != expected {
t.Errorf("Combine(%s,%s) expected %v; got %v", a.nullability, b.nullability, expected, actual)
}
// We have already tried Combine(a, b) the same result should be true for Combine(b, a)
actual = mergeParam(b, a).NotNull()
if actual != expected {
t.Errorf("Combine(%s,%s) expected %v; got %v", b.nullability, a.nullability, expected, actual)
}
}
}
func TestMergeParamName(t *testing.T) {
type test struct {
a Param
b Param
name string
}
a := NewParam("a")
b := NewParam("b")
blank := NewParam("")
tests := []test{
// should prefer the first param's name if both specified
{a, b, "a"},
{b, a, "b"},
// should prefer non-blank names
{a, blank, "a"},
{blank, a, "a"},
}
for _, spec := range tests {
a := spec.a
b := spec.b
actual := mergeParam(a, b).Name()
expected := spec.name
if actual != expected {
t.Errorf("Combine(%s,%s) expected %v; got %v", a.name, b.name, expected, actual)
}
}
}