Skip to content

Commit

Permalink
add basic happy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Braithwaite committed Mar 31, 2021
1 parent af474fb commit be2db39
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions named_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,57 @@ func TestNamedQueries(t *testing.T) {

})
}

func TestFixBounds(t *testing.T) {
table := []struct {
name, query, expect string
loop int
}{
{
name: `named syntax`,
query: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last)`,
expect: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last),(:name, :age, :first, :last)`,
loop: 2,
},
{
name: `mysql syntax`,
query: `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?)`,
expect: `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?),(?, ?, ?, ?)`,
loop: 2,
},
{
name: `named syntax w/ trailer`,
query: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) ;--`,
expect: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last),(:name, :age, :first, :last) ;--`,
loop: 2,
},
{
name: `mysql syntax w/ trailer`,
query: `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?) ;--`,
expect: `INSERT INTO foo (a,b,c,d) VALUES (?, ?, ?, ?),(?, ?, ?, ?) ;--`,
loop: 2,
},
{
name: `not found test`,
query: `INSERT INTO foo (a,b,c,d) (:name, :age, :first, :last)`,
expect: `INSERT INTO foo (a,b,c,d) (:name, :age, :first, :last)`,
loop: 2,
},
{
name: `found twice test`,
query: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) VALUES (:name, :age, :first, :last)`,
expect: `INSERT INTO foo (a,b,c,d) VALUES (:name, :age, :first, :last) VALUES (:name, :age, :first, :last)`,
loop: 2,
},
}

for _, tc := range table {
t.Run(tc.name, func(t *testing.T) {
res := fixBound(tc.query, tc.loop)
if res != tc.expect {
t.Errorf("mismatched results")
}
})
}

}

0 comments on commit be2db39

Please sign in to comment.