Skip to content

Commit a9a7fab

Browse files
committed
Add test cases that handle "_has_next" and "_index" with specified types.
1 parent 763fb99 commit a9a7fab

File tree

11 files changed

+128
-0
lines changed

11 files changed

+128
-0
lines changed

src/test/kotlin/org/domaframework/doma/intellij/complate/sql/SqlCompleteTest.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class SqlCompleteTest : DomaSqlTest() {
5151
"$testDapName/completeParameterSecondProperty.sql",
5252
"$testDapName/completeCallStaticPropertyClassPackage.sql",
5353
"$testDapName/completeCallStaticPropertyClass.sql",
54+
"$testDapName/completeForItemHasNext.sql",
55+
"$testDapName/completeForItemIndex.sql",
5456
)
5557
myFixture.enableInspections(SqlBindVariableValidInspector())
5658
}
@@ -107,6 +109,35 @@ class SqlCompleteTest : DomaSqlTest() {
107109
)
108110
}
109111

112+
fun testCompleteForItemHasNext() {
113+
innerDirectiveCompleteTest(
114+
"$testDapName/completeForItemHasNext.sql",
115+
listOf(
116+
"FALSE",
117+
"TRUE",
118+
"TYPE",
119+
"toString()",
120+
"booleanValue()",
121+
),
122+
listOf("get()", "startsWith()", "permissions", "MAX_VALUE", "MIN_VALUE"),
123+
)
124+
}
125+
126+
fun testCompleteForItemIndex() {
127+
innerDirectiveCompleteTest(
128+
"$testDapName/completeForItemIndex.sql",
129+
listOf(
130+
"BYTES",
131+
"MAX_VALUE",
132+
"MIN_VALUE",
133+
"SIZE",
134+
"TYPE",
135+
"Integer()",
136+
),
137+
listOf("get()", "startsWith()", "permissions", "FALSE", "TRUE"),
138+
)
139+
}
140+
110141
fun testCompleteDirective() {
111142
innerDirectiveCompleteTest(
112143
"$testDapName/completeDirective.sql",

src/test/kotlin/org/domaframework/doma/intellij/document/SqlSymbolDocumentTestCase.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
3535
addSqlFile("$testPackage/$testDaoName/documentForItemElementByFieldAccess.sql")
3636
addSqlFile("$testPackage/$testDaoName/documentForItemFirstElement.sql")
3737
addSqlFile("$testPackage/$testDaoName/documentForItemStaticProperty.sql")
38+
addSqlFile("$testPackage/$testDaoName/documentForItemHasNext.sql")
39+
addSqlFile("$testPackage/$testDaoName/documentForItemIndex.sql")
3840
}
3941

4042
fun testDocumentForItemDaoParam() {
@@ -96,6 +98,22 @@ class SqlSymbolDocumentTestCase : DomaSqlTest() {
9698
documentationFindTextTest(sqlName, "item", result)
9799
}
98100

101+
fun testDocumentForItemHasNext() {
102+
val sqlName = "documentForItemHasNext"
103+
val result =
104+
"<a href=\"psi_element://java.lang.Boolean\">Boolean</a> item_has_next"
105+
106+
documentationFindTextTest(sqlName, "item_has_next", result)
107+
}
108+
109+
fun testDocumentForItemIndex() {
110+
val sqlName = "documentForItemIndex"
111+
val result =
112+
"<a href=\"psi_element://java.lang.Integer\">Integer</a> item_index"
113+
114+
documentationFindTextTest(sqlName, "item_index", result)
115+
}
116+
99117
fun testDocumentForItemStaticProperty() {
100118
val sqlName = "documentForItemStaticProperty"
101119
val result =

src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ParameterDefinedTest : DomaSqlTest() {
3737
"$testDaoName/resolveDaoArgumentOfListType.sql",
3838
"$testDaoName/bindVariableInFunctionParameters.sql",
3939
"$testDaoName/callStaticPropertyPackageName.sql",
40+
"$testDaoName/bindVariableForItemHasNextAndIndex.sql",
4041
)
4142
myFixture.enableInspections(SqlBindVariableValidInspector())
4243
}
@@ -61,6 +62,14 @@ class ParameterDefinedTest : DomaSqlTest() {
6162
myFixture.testHighlighting(false, false, false, sqlFile)
6263
}
6364

65+
fun testBindVariableForItemHasNextAndIndex() {
66+
val sqlFile = findSqlFile("$testDaoName/bindVariableForItemHasNextAndIndex.sql")
67+
assertNotNull("Not Found SQL File", sqlFile)
68+
if (sqlFile == null) return
69+
70+
myFixture.testHighlighting(false, false, false, sqlFile)
71+
}
72+
6473
fun testAccessStaticProperty() {
6574
val sqlFile = findSqlFile("$testDaoName/accessStaticProperty.sql")
6675
assertNotNull("Not Found SQL File", sqlFile)

src/test/testData/src/main/java/doma/example/dao/EmployeeSummaryDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ interface EmployeeSummaryDao {
3232

3333
@Insert(sqlFile=true)
3434
EmployeeSummary bindVariableInFunctionParameters(Employee employee, User user);
35+
36+
@Select
37+
List<Employee> bindVariableForItemHasNextAndIndex(List<Employee> employees);
3538
}

src/test/testData/src/main/java/doma/example/dao/SqlCompleteTestDao.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ interface SqlCompleteTestDao {
7575
@Select
7676
Employee completeCallStaticPropertyClass();
7777

78+
@Select
79+
Principal completeForItemHasNext(Principal principal);
80+
81+
@Select
82+
Principal completeForItemIndex(Principal principal);
83+
7884
}

src/test/testData/src/main/java/doma/example/dao/document/DocumentTestDao.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ public interface DocumentTestDao {
3232
@Select
3333
int documentForItemStaticProperty();
3434

35+
@Select
36+
int documentForItemHasNext(Principal principal);
37+
3538
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
select p.project_id
2+
, pd.project_detail_id
3+
, pd.project_number
4+
, p.project_name
5+
, e.employee_id
6+
, e.employee_name
7+
from project_detail pd
8+
inner join project p
9+
on p.project_id = pd.project_id
10+
inner join employee e
11+
on pd.employee_id = e.employee_id
12+
-- Use as List-type
13+
/*%if employees.size() > 0 */
14+
where
15+
/*%for member : employees */
16+
/*%if member_has_next */
17+
/*# "or" */
18+
/*%end */
19+
p.employee_id = /* member.employeeId */0
20+
and p.not_next = /* member_has_next.<error descr="The field or method [NotTRUE] does not exist in the class [Boolean]">NotTRUE</error> */false
21+
and p.next = /* member_has_next.TRUE */false
22+
and p.not_index = /* member_index.<error descr="The field or method [nextValue] does not exist in the class [Integer]">nextValue</error>() */999
23+
and p.index = /* member_index.MIN_VALUE */0
24+
/*%end */
25+
p.employee_id = /* employees.get(0).employeeId */0
26+
/*%end */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
select * from principal
2+
where
3+
/*%for item : principal.permissions */
4+
index = /* item_index */0
5+
/*%if item_has_next */
6+
OR flag = /* item_has_next.<caret> */false
7+
/*%end */
8+
/*%end */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
select * from principal
2+
where
3+
/*%for item : principal.permissions */
4+
index = /* item_index.<caret> */0
5+
/*%if item_has_next */
6+
OR flag = /* item_has_next.FALSE */false
7+
/*%end */
8+
/*%end */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
select count(*) from principal
2+
where
3+
/*%for item : principal.permissions */
4+
name = /* item.name */'name'
5+
/*%if item_has_<caret>next */
6+
/*# "or" */
7+
/*%end */
8+
/*%end */

0 commit comments

Comments
 (0)