Skip to content

Commit 865273c

Browse files
committed
Move SQL completion test datas
1 parent 88d2f09 commit 865273c

File tree

11 files changed

+109
-3
lines changed

11 files changed

+109
-3
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import org.domaframework.doma.intellij.DomaSqlTest
2222
*/
2323
class SqlCompleteTest : DomaSqlTest() {
2424
private val testDaoName = "SqlCompleteTestDao"
25-
private val testSpecificDaoName = "SpecificParamTypeCompletionDao"
2625

2726
override fun setUp() {
2827
super.setUp()
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright Doma Tools 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+
package org.domaframework.doma.intellij.complate.sql
17+
18+
import org.domaframework.doma.intellij.DomaSqlTest
19+
20+
/**
21+
* Code completion testing in SQL(Specific Param Type)
22+
*/
23+
class SqlSpecificParamTypeCompleteTest : DomaSqlTest() {
24+
private val testDaoName = "completion/SpecificParamTypeCompletionTestDao"
25+
26+
override fun setUp() {
27+
super.setUp()
28+
addDaoJavaFile("$testDaoName.java")
29+
addOtherJavaFile("collector", "HogeCollector.java")
30+
addOtherJavaFile("option", "HogeSelectOptions.java")
31+
addOtherJavaFile("function", "HogeFunction.java")
32+
addOtherJavaFile("function", "HogeBiFunction.java")
33+
}
34+
35+
fun testSelectOptionArgument() {
36+
val sqlFileName = "selectSelectOption"
37+
val expectedSuggestions = listOf("id", "searchName")
38+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
39+
}
40+
41+
fun testSubTypeSelectOptionArgument() {
42+
val sqlFileName = "selectSubTypeSelectOption"
43+
val expectedSuggestions = listOf("employee", "searchName", "hogeSelectOptions")
44+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
45+
}
46+
47+
fun testCollectorArgument() {
48+
val sqlFileName = "selectCollector"
49+
val expectedSuggestions = listOf("salary")
50+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
51+
}
52+
53+
fun testSubTypeCollectorArgument() {
54+
val sqlFileName = "selectSubTypeCollector"
55+
val expectedSuggestions = listOf("employee", "id")
56+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
57+
}
58+
59+
fun testFunctionArgument() {
60+
val sqlFileName = "selectFunction"
61+
val expectedSuggestions = listOf("employee", "id")
62+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
63+
}
64+
65+
fun testSubTypeFunctionArgument() {
66+
val sqlFileName = "selectSubTypeFunction"
67+
val expectedSuggestions = listOf("employee", "id")
68+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
69+
}
70+
71+
fun testBiFunctionArgument() {
72+
val sqlFileName = "executeBiFunction"
73+
val expectedSuggestions = listOf("tableName")
74+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
75+
}
76+
77+
fun testSubTypeBiFunctionArgument() {
78+
val sqlFileName = "executeSubTypeBiFunction"
79+
val expectedSuggestions = listOf("tableName")
80+
innerDirectiveCompleteTest(sqlFileName, expectedSuggestions)
81+
}
82+
83+
private fun innerDirectiveCompleteTest(
84+
sqlFileName: String,
85+
expectedSuggestions: List<String>,
86+
) {
87+
addSqlFile("$testDaoName/$sqlFileName.sql")
88+
val sqlFile = findSqlFile("$testDaoName/$sqlFileName.sql")
89+
assertNotNull("Not Found SQL File", sqlFile)
90+
if (sqlFile == null) return
91+
92+
myFixture.configureFromExistingVirtualFile(sqlFile)
93+
val lookupElements = myFixture.completeBasic()
94+
val suggestions = lookupElements.map { it.lookupString }
95+
println(suggestions.map { it })
96+
expectedSuggestions.forEach { expected ->
97+
assertTrue(
98+
"Expected '$expected' in completion suggestions: $suggestions",
99+
suggestions.contains(expected),
100+
)
101+
}
102+
assertTrue(
103+
"List sizes of [suggestions(${suggestions.size})] and [expectedSuggestions(${expectedSuggestions.size})] do not match",
104+
suggestions.size == expectedSuggestions.size,
105+
)
106+
}
107+
}

src/test/testData/src/main/java/doma/example/dao/SpecificParamTypeCompletionDao.java renamed to src/test/testData/src/main/java/doma/example/dao/completion/SpecificParamTypeCompletionTestDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package doma.example.dao;
1+
package doma.example.dao.completion;
22

33
import doma.example.collector.HogeCollector;
44
import doma.example.entity.*;
@@ -16,7 +16,7 @@
1616
import java.util.stream.Stream;
1717

1818
@Dao
19-
public interface SpecificParamTypeCompletionDao {
19+
public interface SpecificParamTypeCompletionTestDao {
2020

2121
/**
2222
* SelectOptions do not cause errors even when unused

0 commit comments

Comments
 (0)