-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for XMLScriptBuilder to avoid regression
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/test/java/org/apache/ibatis/scripting/xmltags/XMLScriptBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2009-2025 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ibatis.scripting.xmltags; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.apache.ibatis.mapping.SqlSource; | ||
import org.apache.ibatis.parsing.XPathParser; | ||
import org.apache.ibatis.session.Configuration; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class XMLScriptBuilderTest { | ||
|
||
@Test | ||
void shouldWhereInsertWhitespace() throws Exception { | ||
String xml = """ | ||
<script> | ||
select * from user | ||
<where> | ||
<if test="1==1">and id = 1</if> | ||
<if test="1==1">and id > 0</if> | ||
</where> | ||
</script> | ||
"""; | ||
SqlSource sqlSource = new XMLScriptBuilder(new Configuration(), new XPathParser(xml).evalNode("/script")) | ||
.parseScriptNode(); | ||
assertThat(sqlSource.getBoundSql(1).getSql()) | ||
.containsPattern("(?m)^\\s*select \\* from user\\s+WHERE\\s+id = 1\\s+and id > 0\\s*$"); | ||
} | ||
|
||
} |