snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
82
internal/sql/named/param_test.go
Normal file
82
internal/sql/named/param_test.go
Normal file
@@ -0,0 +1,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user