Skip to content

Commit 610c75e

Browse files
committed
Added failing tests involving repeat directive
#14 and #15
1 parent 2c1ca02 commit 610c75e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/test/java/org/mybatis/scripting/velocity/use/VelocityLanguageTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.sql.Connection;
2222
import java.sql.DriverManager;
2323
import java.util.ArrayList;
24+
import java.util.Arrays;
2425
import java.util.HashMap;
2526
import java.util.List;
2627
import java.util.Map;
@@ -273,6 +274,31 @@ void testDynamicSelectWithIterationBoundary() {
273274
}
274275
}
275276

277+
@Test
278+
void testSetInsideRepeat() {
279+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
280+
Name[] names = { new Name(2), new Name(5) };
281+
Map<String, Object> param = new HashMap<>();
282+
param.put("names", names);
283+
param.put("nid", 4);
284+
List<Name> answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectWithSetInsideRepeat", param);
285+
assertEquals(2, answer.size());
286+
assertEquals(2, answer.get(0).getId());
287+
assertEquals(5, answer.get(1).getId());
288+
}
289+
}
290+
291+
@Test
292+
void testNestedRepeat() {
293+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
294+
List<List<Integer>> ids = Arrays.asList(Arrays.asList(1, 10), Arrays.asList(100, 1000));
295+
Map<String, Object> param = new HashMap<>();
296+
param.put("ids", ids);
297+
Integer answer = sqlSession.selectOne("org.mybatis.scripting.velocity.use.selectNestedRepeat", param);
298+
assertEquals(202, answer);
299+
}
300+
}
301+
276302
@Test
277303
void testSelectKey() {
278304
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {

src/test/resources/org/mybatis/scripting/velocity/use/mapper.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2012-2022 the original author or authors.
4+
Copyright 2012-2025 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -92,6 +92,29 @@
9292
#end
9393
</select>
9494

95+
<select id="selectWithSetInsideRepeat" resultType="org.mybatis.scripting.velocity.use.Name">
96+
SELECT *
97+
FROM names
98+
#where()
99+
#repeat($_parameter.names $name ',' 'id IN (' ')')
100+
#set( $nid = $name.id)
101+
@{nid}
102+
#end
103+
or id = @{nid}
104+
#end
105+
order by id
106+
</select>
107+
108+
<select id="selectNestedRepeat" resultType="int">
109+
SELECT
110+
#repeat($_parameter.ids $level1 '+' '' '')
111+
#repeat($level1 $level2 '+' '' '')
112+
@{level1[0]}
113+
#end
114+
#end
115+
FROM (VALUES(0))
116+
</select>
117+
95118
<select id="selectWithCustomUserDirective" resultType="org.mybatis.scripting.velocity.use.Name">
96119
#genSql()
97120
#end

0 commit comments

Comments
 (0)