generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MethodDocumentationIntentionTest.kt
78 lines (63 loc) · 3.35 KB
/
MethodDocumentationIntentionTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.methoddoc.intention
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import org.junit.Assert
class MethodDocumentationIntentionTest : BasePlatformTestCase() {
override fun getTestDataPath() = "src/test/testData"
fun testMethodWithoutAnyDoc() {
val testName = "WithoutAnyDoc"
val nextDocSuggestion = "/** Some generated documentation */"
checkIntentionForKotlinAndJava(testName, nextDocSuggestion)
}
fun testComplicatedMethodIntention() {
val testName = "ComplicatedMethod"
val nextDocSuggestion = "/** Some generated documentation for the complicated method */"
checkIntentionForKotlinAndJava(testName, nextDocSuggestion)
}
fun testMethodWithPreviousDoc() {
val testName = "WithPreviousDoc"
val nextDocSuggestion = "/** Some new documentation that replaced the old one */"
checkIntentionForKotlinAndJava(testName, nextDocSuggestion)
}
fun testMethodWithDocAndComment() {
val testName = "WithDocAndComment"
val nextDocSuggestion = "/** Some new one documentation. The comment below remained untouched. */"
checkIntentionForKotlinAndJava(testName, nextDocSuggestion)
}
fun testMethodWithManyCommentsWithSpaces() {
val testName = "ManyCommentsWithSpaces"
val nextDocSuggestion =
"/** Some new one documentation. The comments below remained untouched with all their white spaces. */"
checkIntentionForKotlinAndJava(testName, nextDocSuggestion)
}
fun testWrongCaretPosition() {
checkWrongCaretPosForKotlinAndJava("WrongCaretPosition1")
checkWrongCaretPosForKotlinAndJava("WrongCaretPosition2")
checkWrongCaretPosForKotlinAndJava("WrongCaretPosition3")
}
private fun checkIntentionForKotlinAndJava(testName: String, nextDocSuggestion: String) {
checkMethodDocumentationIntention(testName, "kotlin", "kt", nextDocSuggestion)
checkMethodDocumentationIntention(testName, "java", "java", nextDocSuggestion)
}
private fun checkWrongCaretPosForKotlinAndJava(testName: String) {
checkWrongCaretPosition(testName, "kotlin", "kt")
checkWrongCaretPosition(testName, "java", "java")
}
private fun checkMethodDocumentationIntention(testName: String, codeLanguage: String, fileExtension: String, nextDocSuggestion: String) {
val beforeTestFileName = "/$codeLanguage.code.examples/$testName.before.$fileExtension"
val afterTestFileName = "/$codeLanguage.code.examples/$testName.after.$fileExtension"
myFixture.configureByFile(beforeTestFileName).putUserData(mockedDocKey, nextDocSuggestion)
val intentionHint = MyBundle.message("intentionHint")
val intentionAction = myFixture.findSingleIntention(intentionHint)
Assert.assertNotNull(intentionAction)
myFixture.apply {
launchAction(intentionAction)
checkResultByFile(afterTestFileName)
}
}
private fun checkWrongCaretPosition(testName: String, codeLanguage: String, fileExtension: String) {
val beforeTestFileName = "/$codeLanguage.code.examples/$testName.before.$fileExtension"
myFixture.configureByFile(beforeTestFileName)
val intentionHint = MyBundle.message("intentionHint")
Assert.assertEquals(myFixture.filterAvailableIntentions(intentionHint).size, 0)
}
}