More func tests.

This commit is contained in:
go-jet 2019-07-20 14:23:42 +02:00
parent 35d607a62c
commit f0cb772b7a
7 changed files with 19 additions and 8 deletions

View file

@ -168,7 +168,7 @@ func UPPER(stringExpression StringExpression) StringExpression {
// in characters (a space by default) from the start and end of string // in characters (a space by default) from the start and end of string
func BTRIM(stringExpression StringExpression, trimChars ...StringExpression) StringExpression { func BTRIM(stringExpression StringExpression, trimChars ...StringExpression) StringExpression {
if len(trimChars) > 0 { if len(trimChars) > 0 {
return newStringFunc("LTRIM", stringExpression, trimChars[0]) return newStringFunc("BTRIM", stringExpression, trimChars[0])
} }
return newStringFunc("BTRIM", stringExpression) return newStringFunc("BTRIM", stringExpression)
} }

View file

@ -155,3 +155,8 @@ func TestFuncLEAST(t *testing.T) {
assertClauseSerialize(t, LEAST(table1ColFloat), "LEAST(table1.col_float)") assertClauseSerialize(t, LEAST(table1ColFloat), "LEAST(table1.col_float)")
assertClauseSerialize(t, LEAST(Float(11.2222), NULL, String("str")), "LEAST($1, NULL, $2)", float64(11.2222), "str") assertClauseSerialize(t, LEAST(Float(11.2222), NULL, String("str")), "LEAST($1, NULL, $2)", float64(11.2222), "str")
} }
func TestTO_ASCII(t *testing.T) {
assertClauseSerialize(t, TO_ASCII(String("Karel")), `TO_ASCII($1)`, "Karel")
assertClauseSerialize(t, TO_ASCII(String("Karel")), `TO_ASCII($1)`, "Karel")
}

View file

@ -127,7 +127,10 @@ func TestStringOperators(t *testing.T) {
LOWER(AllTypes.CharacterVaryingPtr), LOWER(AllTypes.CharacterVaryingPtr),
UPPER(AllTypes.Character), UPPER(AllTypes.Character),
BTRIM(AllTypes.CharacterVarying), BTRIM(AllTypes.CharacterVarying),
BTRIM(AllTypes.CharacterVarying, String("AA")),
LTRIM(AllTypes.CharacterVarying),
LTRIM(AllTypes.CharacterVarying, String("A")), LTRIM(AllTypes.CharacterVarying, String("A")),
RTRIM(AllTypes.CharacterVarying),
RTRIM(AllTypes.CharacterVarying, String("B")), RTRIM(AllTypes.CharacterVarying, String("B")),
CHR(Int(65)), CHR(Int(65)),
//CONCAT(String("string1"), Int(1), Float(11.12)), //CONCAT(String("string1"), Int(1), Float(11.12)),
@ -143,13 +146,16 @@ func TestStringOperators(t *testing.T) {
RIGHT(String("abcde"), Int(2)), RIGHT(String("abcde"), Int(2)),
LENGTH(String("jose")), LENGTH(String("jose")),
LENGTH(String("jose"), String("UTF8")), LENGTH(String("jose"), String("UTF8")),
LPAD(String("Hi"), Int(5)),
LPAD(String("Hi"), Int(5), String("xy")), LPAD(String("Hi"), Int(5), String("xy")),
RPAD(String("Hi"), Int(5)),
RPAD(String("Hi"), Int(5), String("xy")), RPAD(String("Hi"), Int(5), String("xy")),
MD5(AllTypes.CharacterVarying), MD5(AllTypes.CharacterVarying),
REPEAT(AllTypes.Text, Int(33)), REPEAT(AllTypes.Text, Int(33)),
REPLACE(AllTypes.Character, String("BA"), String("AB")), REPLACE(AllTypes.Character, String("BA"), String("AB")),
REVERSE(AllTypes.CharacterVarying), REVERSE(AllTypes.CharacterVarying),
STRPOS(AllTypes.Text, String("A")), STRPOS(AllTypes.Text, String("A")),
SUBSTR(AllTypes.CharacterPtr, Int(3)),
SUBSTR(AllTypes.CharacterPtr, Int(3), Int(2)), SUBSTR(AllTypes.CharacterPtr, Int(3), Int(2)),
TO_HEX(AllTypes.IntegerPtr), TO_HEX(AllTypes.IntegerPtr),
) )

View file

@ -73,7 +73,7 @@ func TestDeleteQueryContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel() defer cancel()
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Millisecond)
dest := []model.Link{} dest := []model.Link{}
err := deleteStmt.QueryContext(ctx, db, &dest) err := deleteStmt.QueryContext(ctx, db, &dest)
@ -91,7 +91,7 @@ func TestDeleteExecContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel() defer cancel()
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Millisecond)
_, err := deleteStmt.ExecContext(ctx, db) _, err := deleteStmt.ExecContext(ctx, db)

View file

@ -258,7 +258,7 @@ func TestInsertWithQueryContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel() defer cancel()
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Millisecond)
dest := []model.Link{} dest := []model.Link{}
err := stmt.QueryContext(ctx, db, &dest) err := stmt.QueryContext(ctx, db, &dest)
@ -275,7 +275,7 @@ func TestInsertWithExecContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel() defer cancel()
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Millisecond)
_, err := stmt.ExecContext(ctx, db) _, err := stmt.ExecContext(ctx, db)

View file

@ -62,7 +62,7 @@ func TestLockExecContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel() defer cancel()
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Millisecond)
tx, _ := db.Begin() tx, _ := db.Begin()
defer tx.Rollback() defer tx.Rollback()

View file

@ -254,7 +254,7 @@ func TestUpdateQueryContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel() defer cancel()
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Millisecond)
dest := []model.Link{} dest := []model.Link{}
err := updateStmt.QueryContext(ctx, db, &dest) err := updateStmt.QueryContext(ctx, db, &dest)
@ -273,7 +273,7 @@ func TestUpdateExecContext(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Microsecond)
defer cancel() defer cancel()
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Millisecond)
_, err := updateStmt.ExecContext(ctx, db) _, err := updateStmt.ExecContext(ctx, db)