MCPcopy Index your code
hub / github.com/cube2222/octosql / TestEncode

Function TestEncode

parser/sqlparser/dependency/sqltypes/value_test.go:616–650  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

614}
615
616func TestEncode(t *testing.T) {
617 testcases := []struct {
618 in Value
619 outSQL string
620 outASCII string
621 }{{
622 in: NULL,
623 outSQL: "null",
624 outASCII: "null",
625 }, {
626 in: testVal(Int64, "1"),
627 outSQL: "1",
628 outASCII: "1",
629 }, {
630 in: testVal(VarChar, "foo"),
631 outSQL: "'foo'",
632 outASCII: "'Zm9v'",
633 }, {
634 in: testVal(VarChar, "\x00'\"\b\n\r\t\x1A\\"),
635 outSQL: "'\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\'",
636 outASCII: "'ACciCAoNCRpc'",
637 }}
638 for _, tcase := range testcases {
639 buf := &bytes.Buffer{}
640 tcase.in.EncodeSQL(buf)
641 if tcase.outSQL != buf.String() {
642 t.Errorf("%v.EncodeSQL = %q, want %q", makePretty(tcase.in), buf.String(), tcase.outSQL)
643 }
644 buf = &bytes.Buffer{}
645 tcase.in.EncodeASCII(buf)
646 if tcase.outASCII != buf.String() {
647 t.Errorf("%v.EncodeASCII = %q, want %q", makePretty(tcase.in), buf.String(), tcase.outASCII)
648 }
649 }
650}
651
652// TestEncodeMap ensures DontEscape is not escaped
653func TestEncodeMap(t *testing.T) {

Callers

nothing calls this directly

Calls 5

StringMethod · 0.95
testValFunction · 0.85
makePrettyFunction · 0.85
EncodeSQLMethod · 0.80
EncodeASCIIMethod · 0.80

Tested by

no test coverage detected