Skip to content

Commit d7804d9

Browse files
committed
add unit test
1 parent 07500d1 commit d7804d9

24 files changed

+6101
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ go 1.14
55
require (
66
github.com/pingcap/parser v3.0.12+incompatible
77
github.com/pingcap/tidb v0.0.0-20200312110807-8c4696b3f340 // v3.0.12
8+
github.com/stretchr/testify v1.3.0
89
)

parser_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package parser
22

33
import (
44
"testing"
5+
6+
"github.com/stretchr/testify/assert"
57
)
68

79
func testParser(t *testing.T, xmlData, expect string) {
@@ -1046,3 +1048,62 @@ func TestOtherwise_issue1193(t *testing.T) {
10461048
`, "SELECT * FROM `fruits` WHERE `name`=? AND `price`=? AND `category`=?;",
10471049
)
10481050
}
1051+
1052+
func TestParseXMLs(t *testing.T) {
1053+
xmlCommonData := `
1054+
<?xml version="1.0" encoding="UTF-8"?><!--Converted at: Mon Jun 07 09:48:24 CST 2021-->
1055+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
1056+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
1057+
<mapper namespace="test.common">
1058+
<sql id="prefix">
1059+
SELECT * FROM (
1060+
</sql>
1061+
1062+
<sql id="suffix">
1063+
WHERE a=1 )
1064+
</sql>
1065+
1066+
<select id="sql1" parameterType="customer" resultMap="custResultMap">
1067+
<include refid="prefix"/>
1068+
SELECT a,b FROM tb1
1069+
<include refid="suffix"/>
1070+
</select>
1071+
</mapper>
1072+
`
1073+
xmlData := `
1074+
<?xml version="1.0" encoding="UTF-8"?><!--Converted at: Tue May 10 15:50:21 CST 2022-->
1075+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
1076+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
1077+
<mapper namespace="employee">
1078+
<select id="queryEmpHireSepList" parameterType="employee" resultType="employeeResult">
1079+
<include refid="test.common.prefix"/>
1080+
SELECT a,b FROM tb1
1081+
<include refid="test.common.suffix"/>
1082+
</select>
1083+
</mapper>
1084+
`
1085+
1086+
sqls, err := ParseXMLs([]string{xmlCommonData, xmlData}, false)
1087+
if err != nil {
1088+
if !assert.NoError(t, err) {
1089+
t.Fatal(err)
1090+
}
1091+
}
1092+
assert.Equal(t, 2, len(sqls))
1093+
assert.Equal(t, `
1094+
SELECT * FROM (
1095+
1096+
SELECT a,b FROM tb1
1097+
1098+
WHERE a=1 )
1099+
`, sqls[0])
1100+
1101+
assert.Equal(t, `
1102+
SELECT * FROM (
1103+
1104+
SELECT a,b FROM tb1
1105+
1106+
WHERE a=1 )
1107+
`, sqls[1])
1108+
1109+
}

vendor/github.com/davecgh/go-spew/LICENSE

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypass.go

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)