mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
add test cases
This commit is contained in:
@@ -5,6 +5,7 @@ package sqlbuilder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func ExampleUpdateBuilder() {
|
||||
@@ -33,3 +34,26 @@ func ExampleUpdateBuilder() {
|
||||
// UPDATE demo.user SET type = ?, credit = credit + 1, modified_at = UNIX_TIMESTAMP(NOW()) WHERE id > ? AND name LIKE ? AND (id_card IS NULL OR status IN (?, ?, ?)) AND modified_at > created_at + ?
|
||||
// [sys 1234 %Du 1 2 5 86400]
|
||||
}
|
||||
|
||||
func TestUpdateAssignments(t *testing.T) {
|
||||
cases := map[string]func(ub *UpdateBuilder) string{
|
||||
"f = f + 1|[]": func(ub *UpdateBuilder) string { return ub.Incr("f") },
|
||||
"f = f - 1|[]": func(ub *UpdateBuilder) string { return ub.Decr("f") },
|
||||
"f = f + $0|[123]": func(ub *UpdateBuilder) string { return ub.Add("f", 123) },
|
||||
"f = f - $0|[123]": func(ub *UpdateBuilder) string { return ub.Sub("f", 123) },
|
||||
"f = f * $0|[123]": func(ub *UpdateBuilder) string { return ub.Mul("f", 123) },
|
||||
"f = f / $0|[123]": func(ub *UpdateBuilder) string { return ub.Div("f", 123) },
|
||||
}
|
||||
|
||||
for expected, f := range cases {
|
||||
ub := NewUpdateBuilder()
|
||||
s := f(ub)
|
||||
ub.Set(s)
|
||||
_, args := ub.Build()
|
||||
actual := fmt.Sprintf("%v|%v", s, args)
|
||||
|
||||
if actual != expected {
|
||||
t.Fatalf("invalid assignment result. [expected:%v] [actual:%v]", expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user