Skip to content

Commit c06626c

Browse files
committed
Test for XMLScriptBuilder to avoid regression
mybatis#3349 mybatis#3375 mybatis#3349 (comment)
1 parent 21f9459 commit c06626c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2009-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.apache.ibatis.scripting.xmltags;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import org.apache.ibatis.mapping.SqlSource;
22+
import org.apache.ibatis.parsing.XPathParser;
23+
import org.apache.ibatis.session.Configuration;
24+
import org.junit.jupiter.api.Test;
25+
26+
class XMLScriptBuilderTest {
27+
28+
@Test
29+
void shouldWhereInsertWhitespace() throws Exception {
30+
String xml = """
31+
<script>
32+
select * from user
33+
<where>
34+
<if test="1==1">and id = 1</if>
35+
<if test="1==1">and id > 0</if>
36+
</where>
37+
</script>
38+
""";
39+
SqlSource sqlSource = new XMLScriptBuilder(new Configuration(), new XPathParser(xml).evalNode("/script"))
40+
.parseScriptNode();
41+
assertThat(sqlSource.getBoundSql(1).getSql())
42+
.containsPattern("(?m)^\\s*select \\* from user\\s+WHERE\\s+id = 1\\s+and id > 0\\s*$");
43+
}
44+
45+
}

0 commit comments

Comments
 (0)