46 lines
760 B
Go
46 lines
760 B
Go
|
package sqladapter
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"git.hexq.cn/tiglog/mydb"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
_ mydb.Collection = &collectionWithSession{}
|
||
|
_ Collection = &collectionWithSession{}
|
||
|
)
|
||
|
|
||
|
func TestReplaceWithDollarSign(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
in string
|
||
|
out string
|
||
|
}{
|
||
|
{
|
||
|
`SELECT ?`,
|
||
|
`SELECT $1`,
|
||
|
},
|
||
|
{
|
||
|
`SELECT ? FROM ? WHERE ?`,
|
||
|
`SELECT $1 FROM $2 WHERE $3`,
|
||
|
},
|
||
|
{
|
||
|
`SELECT ?? FROM ? WHERE ??`,
|
||
|
`SELECT ? FROM $1 WHERE ?`,
|
||
|
},
|
||
|
{
|
||
|
`SELECT ??? FROM ? WHERE ??`,
|
||
|
`SELECT ?$1 FROM $2 WHERE ?`,
|
||
|
},
|
||
|
{
|
||
|
`SELECT ??? FROM ? WHERE ????`,
|
||
|
`SELECT ?$1 FROM $2 WHERE ??`,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, test := range tests {
|
||
|
assert.Equal(t, []byte(test.out), ReplaceWithDollarSign([]byte(test.in)))
|
||
|
}
|
||
|
}
|