-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplaceholder_test.go
39 lines (31 loc) · 1.36 KB
/
placeholder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package bob_test
import (
"testing"
"github.com/aldy505/bob"
)
func TestReplacePlaceholder(t *testing.T) {
t.Run("should be able to replace placeholder to dollar", func(t *testing.T) {
sql := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?);"
result := bob.ReplacePlaceholder(sql, bob.Dollar)
should := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9);"
if result != should {
t.Fatal("result string doesn't match:", result)
}
})
t.Run("should be able to replace placeholder to colon", func(t *testing.T) {
sql := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?);"
result := bob.ReplacePlaceholder(sql, bob.Colon)
should := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (:1, :2, :3), (:4, :5, :6), (:7, :8, :9);"
if result != should {
t.Fatal("result string doesn't match:", result)
}
})
t.Run("should be able to replace placeholder to @p", func(t *testing.T) {
sql := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?);"
result := bob.ReplacePlaceholder(sql, bob.AtP)
should := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (@p1, @p2, @p3), (@p4, @p5, @p6), (@p7, @p8, @p9);"
if result != should {
t.Fatal("result string doesn't match:", result)
}
})
}