Skip to content

Commit

Permalink
added simple completion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghik committed Oct 21, 2019
1 parent 6ee1132 commit b98c362
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ class HoconPropertyLookupElement(resField: ResolvedField) extends LookupElement
override def getObject: ResolvedField = resField

override def getPsiElement: PsiElement = resField.hkey

def repr: String = {
val resValue = resField.resolveValue
s"$getLookupString (${resValue.typeHint})${resValue.valueHint}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jetbrains.plugins.hocon
package completion

import com.intellij.codeInsight.completion.CompletionType
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import org.jetbrains.plugins.hocon.ref.HoconPropertyLookupElement
import org.junit.Assert.assertEquals

class HoconCompletionTest extends BasePlatformTestCase {

override def getTestDataPath: String = "testdata/completion"

def testToplevel(): Unit = testCompletion(
"moar (number) = 5",
"top (object) = {...}",
)

def testInner(): Unit = testCompletion(
"arr (array) = [...]",
"boo (boolean) = true",
"nul (null) = null",
"num (number) = 2",
"obj (object) = {...}",
"str (string) = kek",
)

def testInner2(): Unit = testInner()

def testToplevelSub(): Unit = testCompletion(
"value ()",
"moar (number) = 5",
"top (object) = {...}",
)

def testInnerSub(): Unit = testInner()

private def testCompletion(expected: String*): Unit = {
myFixture.configureByFiles(s"${getTestName(true)}.conf", "included.conf")
val lookups = myFixture.complete(CompletionType.BASIC) map {
case hple: HoconPropertyLookupElement => hple.repr
}
assertEquals(lookups.toSeq, expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class HoconHighlightUsagesTest extends BasePlatformTestCase {

override def getTestDataPath: String = "testdata/highlightUsages"

override def isWriteActionRequired: Boolean = false

def testSimple(): Unit = testUsages(
(0, 0, 3),
(1, 0, 3),
Expand Down
11 changes: 11 additions & 0 deletions testdata/completion/included.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
top {
str = kek
num = 2
boo = true
nul = null
arr = [1, 2, 3]
obj {
sub = foo
}
}
moar = 5
2 changes: 2 additions & 0 deletions testdata/completion/inner.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include "included"
top.<caret>
4 changes: 4 additions & 0 deletions testdata/completion/inner2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include "included"
top {
<caret>
}
2 changes: 2 additions & 0 deletions testdata/completion/innerSub.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include "included"
value = ${top.<caret>}
2 changes: 2 additions & 0 deletions testdata/completion/toplevel.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include "included"
<caret>
2 changes: 2 additions & 0 deletions testdata/completion/toplevelSub.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include "included"
value = ${<caret>}

0 comments on commit b98c362

Please sign in to comment.