MCPcopy
hub / github.com/sqlc-dev/sqlc / TestMergeParamNullability

Function TestMergeParamNullability

internal/sql/named/param_test.go:5–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestMergeParamNullability(t *testing.T) {
6 type test struct {
7 a Param
8 b Param
9 notNull bool
10 message string
11 }
12
13 name := "name"
14 unspec := NewParam(name)
15 inferredNotNull := NewInferredParam(name, true)
16 inferredNull := NewInferredParam(name, false)
17 userDefNull := NewUserNullableParam(name)
18
19 const notNull = true
20 const null = false
21
22 tests := []test{
23 // Unspecified nullability parameter works
24 {unspec, inferredNotNull, notNull, "Unspec + inferred(not null) = not null"},
25 {unspec, inferredNull, null, "Unspec + inferred(not null) = null"},
26 {unspec, userDefNull, null, "Unspec + userdef(null) = null"},
27
28 // Inferred nullability agreeing with user defined nullabilty
29 {inferredNull, userDefNull, null, "inferred(null) + userdef(null) = null"},
30
31 // Inferred nullability disagreeing with user defined nullabilty
32 {inferredNotNull, userDefNull, null, "inferred(not null) + userdef(null) = null"},
33 }
34
35 for _, spec := range tests {
36 a := spec.a
37 b := spec.b
38 actual := mergeParam(a, b).NotNull()
39 expected := spec.notNull
40 if actual != expected {
41 t.Errorf("Combine(%s,%s) expected %v; got %v", a.nullability, b.nullability, expected, actual)
42 }
43
44 // We have already tried Combine(a, b) the same result should be true for Combine(b, a)
45 actual = mergeParam(b, a).NotNull()
46 if actual != expected {
47 t.Errorf("Combine(%s,%s) expected %v; got %v", b.nullability, a.nullability, expected, actual)
48 }
49 }
50}
51
52func TestMergeParamName(t *testing.T) {
53 type test struct {

Callers

nothing calls this directly

Calls 5

NewParamFunction · 0.85
NewInferredParamFunction · 0.85
NewUserNullableParamFunction · 0.85
mergeParamFunction · 0.85
NotNullMethod · 0.80

Tested by

no test coverage detected