Skip to content

Commit 9f867b4

Browse files
committed
dump: add unesacpe test
1 parent b3f5c0f commit 9f867b4

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

dump/dump_test.go

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,52 @@ func (h *testParseHandler) Data(schema string, table string, values []string) er
121121
return nil
122122
}
123123

124+
func (s *parserTestSuite) TestParseFindTable(c *C) {
125+
tbl := []struct {
126+
sql string
127+
table string
128+
}{
129+
{"INSERT INTO `note` VALUES ('title', 'here is sql: INSERT INTO `table` VALUES (\\'some value\\')');", "note"},
130+
{"INSERT INTO `note` VALUES ('1', '2', '3');", "note"},
131+
{"INSERT INTO `a.b` VALUES ('1');", "a.b"},
132+
}
133+
134+
for _, t := range tbl {
135+
res := valuesExp.FindAllStringSubmatch(t.sql, -1)[0][1]
136+
c.Assert(res, Equals, t.table)
137+
}
138+
}
139+
140+
type parserTestSuite struct {
141+
}
142+
143+
var _ = Suite(&parserTestSuite{})
144+
145+
func (s *parserTestSuite) TestUnescape(c *C) {
146+
tbl := []struct {
147+
escaped string
148+
expected string
149+
}{
150+
{`\\n`, `\n`},
151+
{`\\t`, `\t`},
152+
{`\\"`, `\"`},
153+
{`\\'`, `\'`},
154+
{`\\0`, `\0`},
155+
{`\\b`, `\b`},
156+
{`\\Z`, `\Z`},
157+
{`\\r`, `\r`},
158+
{`abc`, `abc`},
159+
{`abc\`, `abc`},
160+
{`ab\c`, `abc`},
161+
{`\abc`, `abc`},
162+
}
163+
164+
for _, t := range tbl {
165+
unesacped := unescapeString(t.escaped)
166+
c.Assert(unesacped, Equals, t.expected)
167+
}
168+
}
169+
124170
func (s *schemaTestSuite) TestParse(c *C) {
125171
var buf bytes.Buffer
126172

@@ -135,7 +181,7 @@ func (s *schemaTestSuite) TestParse(c *C) {
135181
c.Assert(err, IsNil)
136182
}
137183

138-
func (s *schemaTestSuite) TestParseValue(c *C) {
184+
func (s *parserTestSuite) TestParseValue(c *C) {
139185
str := `'abc\\',''`
140186
values, err := parseValues(str)
141187
c.Assert(err, IsNil)
@@ -150,19 +196,3 @@ func (s *schemaTestSuite) TestParseValue(c *C) {
150196
values, err = parseValues(str)
151197
c.Assert(err, NotNil)
152198
}
153-
154-
func (s *schemaTestSuite) TestParseFindTable(c *C) {
155-
tbl := []struct {
156-
sql string
157-
table string
158-
}{
159-
{"INSERT INTO `note` VALUES ('title', 'here is sql: INSERT INTO `table` VALUES (\\'some value\\')');", "note"},
160-
{"INSERT INTO `note` VALUES ('1', '2', '3');", "note"},
161-
{"INSERT INTO `a.b` VALUES ('1');", "a.b"},
162-
}
163-
164-
for _, t := range tbl {
165-
res := valuesExp.FindAllStringSubmatch(t.sql, -1)[0][1]
166-
c.Assert(res, Equals, t.table)
167-
}
168-
}

0 commit comments

Comments
 (0)