MCPcopy
hub / github.com/go-sql-driver/mysql / TestFormatBinaryTime

Function TestFormatBinaryTime

utils_test.go:86–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestFormatBinaryTime(t *testing.T) {
87 expect := func(expected string, src []byte, outlen uint8) {
88 actual, _ := formatBinaryTime(src, outlen)
89 bytes, ok := actual.([]byte)
90 if !ok {
91 t.Errorf("formatBinaryDateTime must return []byte, was %T", actual)
92 }
93 if string(bytes) != expected {
94 t.Errorf(
95 "expected %q, got %q for src=%q and outlen=%d",
96 expected, actual, src, outlen)
97 }
98 }
99
100 // binary format:
101 // sign (0: positive, 1: negative), days(4), hours, minutes, seconds, micro(4)
102
103 // Zeros
104 expect("00:00:00", []byte{}, 8)
105 expect("00:00:00.0", []byte{}, 10)
106 expect("00:00:00.000000", []byte{}, 15)
107
108 // Without micro(4)
109 expect("12:34:56", []byte{0, 0, 0, 0, 0, 12, 34, 56}, 8)
110 expect("-12:34:56", []byte{1, 0, 0, 0, 0, 12, 34, 56}, 8)
111 expect("12:34:56.00", []byte{0, 0, 0, 0, 0, 12, 34, 56}, 11)
112 expect("24:34:56", []byte{0, 1, 0, 0, 0, 0, 34, 56}, 8)
113 expect("-99:34:56", []byte{1, 4, 0, 0, 0, 3, 34, 56}, 8)
114 expect("103079215103:34:56", []byte{0, 255, 255, 255, 255, 23, 34, 56}, 8)
115
116 // With micro(4)
117 expect("12:34:56.00", []byte{0, 0, 0, 0, 0, 12, 34, 56, 99, 0, 0, 0}, 11)
118 expect("12:34:56.000099", []byte{0, 0, 0, 0, 0, 12, 34, 56, 99, 0, 0, 0}, 15)
119}
120
121func TestEscapeBackslash(t *testing.T) {
122 expect := func(expected, value string) {

Callers

nothing calls this directly

Calls 1

formatBinaryTimeFunction · 0.85

Tested by

no test coverage detected