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

Function TestParamSet_Add

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

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestParamSet_Add(t *testing.T) {
6 t.Parallel()
7
8 type test struct {
9 pset *ParamSet
10 param Param
11 expected int
12 }
13
14 named := NewParamSet(nil, true)
15 populatedNamed := NewParamSet(map[int]bool{1: true, 2: true, 4: true, 5: true, 6: true}, true)
16 populatedUnnamed := NewParamSet(map[int]bool{1: true, 2: true, 4: true, 5: true, 6: true}, false)
17 unnamed := NewParamSet(nil, false)
18 p1 := NewParam("hello")
19 p2 := NewParam("world")
20
21 tests := []test{
22 // First parameter should be 1
23 {named, p1, 1},
24 // Duplicate first parameters should be 1
25 {named, p1, 1},
26 // A new parameter receives a new parameter number
27 {named, p2, 2},
28 // An additional new parameter does _not_ receive a new
29 {named, p2, 2},
30
31 // First parameter should be 1
32 {unnamed, p1, 1},
33 // Duplicate first parameters should increment argn
34 {unnamed, p1, 2},
35 // A new parameter receives a new parameter number
36 {unnamed, p2, 3},
37 // An additional new parameter still does receive a new argn
38 {unnamed, p2, 4},
39
40 // First parameter of a pre-populated should be 3
41 {populatedNamed, p1, 3},
42 {populatedNamed, p1, 3},
43 {populatedNamed, p2, 7},
44 {populatedNamed, p2, 7},
45
46 {populatedUnnamed, p1, 3},
47 {populatedUnnamed, p1, 7},
48 {populatedUnnamed, p2, 8},
49 {populatedUnnamed, p2, 9},
50 }
51
52 for _, spec := range tests {
53 actual := spec.pset.Add(spec.param)
54 if actual != spec.expected {
55 t.Errorf("ParamSet.Add(%s) expected %v; got %v", spec.param.name, spec.expected, actual)
56 }
57 }
58}

Callers

nothing calls this directly

Calls 3

NewParamSetFunction · 0.85
NewParamFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected