-
Notifications
You must be signed in to change notification settings - Fork 0
/
safesql_test.go
42 lines (38 loc) · 881 Bytes
/
safesql_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
40
41
42
package safesql_test
import (
"strings"
"testing"
"github.com/empijei/safesql"
)
func TestString(t *testing.T) {
initial := safesql.New("SELECT * FROM")
withTable := safesql.StringJoin([]safesql.String{
initial,
safesql.New("myTable"),
safesql.New("WHERE"),
safesql.StringConcat(safesql.New("userID"),
safesql.New("="),
safesql.NewFromNumber(1),
),
}, safesql.New(" "))
{
gotQ := withTable.String()
wantQ := "SELECT * FROM myTable WHERE userID=1"
if gotQ != wantQ {
t.Errorf("Joining Query: got %q want %q", gotQ, wantQ)
}
}
{
spl := safesql.StringSplit(withTable, " ")
var sb strings.Builder
for _, s := range spl {
sb.WriteString(s.String())
sb.WriteRune('|')
}
gotQ := sb.String()
wantQ := "SELECT|*|FROM|myTable|WHERE|userID=1|"
if gotQ != wantQ {
t.Errorf("Splitting Query: got %q want %q", gotQ, wantQ)
}
}
}