Improved quoting.

This commit is contained in:
Nuno Cruces
2024-10-07 14:42:09 +01:00
parent 3469460635
commit 911e497891
4 changed files with 47 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
package tests
import (
"database/sql"
"encoding/json"
"math"
"reflect"
"testing"
@@ -19,8 +21,8 @@ func TestQuote(t *testing.T) {
{`a'bc`, "'a''bc'"},
{"\x07bc", "'\abc'"},
{"\x1c\n", "'\x1c\n'"},
{"\xB0\x00\x0B", "'\xB0'"},
{[]byte("\xB0\x00\x0B"), "x'B0000B'"},
{"\xB0\x00\x0B", ""},
{0, "0"},
{true, "1"},
@@ -33,7 +35,13 @@ func TestQuote(t *testing.T) {
{int64(math.MaxInt64), "9223372036854775807"},
{time.Unix(0, 0).UTC(), "'1970-01-01T00:00:00Z'"},
{sqlite3.ZeroBlob(4), "x'00000000'"},
{sqlite3.ZeroBlob(1e9), ""},
{int8(0), "0"},
{uint(0), "0"},
{float32(0), "0"},
{(*string)(nil), "NULL"},
{json.Number("0"), "'0'"},
{&sql.RawBytes{'0'}, "x'30'"},
{t, ""}, // panic
}
for _, tt := range tests {
@@ -62,7 +70,7 @@ func TestQuoteIdentifier(t *testing.T) {
{`a'bc`, `"a'bc"`},
{"\x07bc", "\"\abc\""},
{"\x1c\n", "\"\x1c\n\""},
{"\xB0\x00\x0B", ""},
{"\xB0\x00\x0B", ""}, // panic
}
for _, tt := range tests {