Skip to content

Commit 807df3d

Browse files
committed
test module
1 parent 27090a5 commit 807df3d

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

src/test/kotlin/com/tang/intellij/test/FileTree.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class TestProject(
132132
val root: VirtualFile,
133133
val filesWithCaret: List<String>
134134
) {
135+
val fileWithCaret: String get() = filesWithCaret.singleOrNull()!!
136+
135137
fun doFindElementInFile(path: String): PsiElement {
136138
val vFile = root.findFileByRelativePath(path)
137139
?: error("No `$path` file in test project")
@@ -180,5 +182,5 @@ private fun findElementInFile(file: PsiFile, marker: String): PsiElement {
180182
error { "No element found, offset = $elementOffset" }
181183
}
182184

183-
fun replaceCaretMarker(text: String): String = text.replace("/*caret*/", "<caret>")
184-
fun hasCaretMarker(text: String): Boolean = text.contains("/*caret*/")
185+
fun replaceCaretMarker(text: String): String = text.replace("--[[caret]]", "<caret>")
186+
fun hasCaretMarker(text: String): Boolean = text.contains("--[[caret]]")

src/test/kotlin/com/tang/intellij/test/LuaTestBase.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ abstract class LuaTestBase : LightPlatformCodeInsightFixtureTestCase() {
4646

4747
protected fun FileTree.create(): TestProject =
4848
create(myFixture.project, myFixture.findFileInTempDir(""))
49+
50+
protected fun FileTree.createAndOpenFileWithCaretMarker(): TestProject {
51+
val testProject = create()
52+
myFixture.configureFromTempProjectFile(testProject.fileWithCaret)
53+
return testProject
54+
}
4955
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2017. tangzx([email protected])
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+
* http://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+
17+
package com.tang.intellij.test.completion
18+
19+
import com.intellij.openapi.fileEditor.FileDocumentManager
20+
import com.tang.intellij.test.LuaTestBase
21+
import com.tang.intellij.test.fileTreeFromText
22+
23+
class TestModule : LuaTestBase() {
24+
25+
fun `test module type`() {
26+
fileTreeFromText("""
27+
--- moduleA.lua
28+
---@module TypeA
29+
module("TypeA")
30+
31+
name = "a"
32+
33+
--- B.lua
34+
local a ---@type TypeA
35+
a.--[[caret]]
36+
""").createAndOpenFileWithCaretMarker()
37+
38+
FileDocumentManager.getInstance().saveAllDocuments()
39+
myFixture.completeBasic()
40+
val elementStrings = myFixture.lookupElementStrings
41+
assertTrue(elementStrings!!.contains("name"))
42+
}
43+
44+
45+
fun `test module members visibility`() {
46+
fileTreeFromText("""
47+
--- moduleA.lua
48+
---@module TypeA
49+
module("TypeA")
50+
51+
myFieldName = "a"
52+
53+
function myFunction() end
54+
55+
--- B.lua
56+
--[[caret]]
57+
""").createAndOpenFileWithCaretMarker()
58+
59+
FileDocumentManager.getInstance().saveAllDocuments()
60+
myFixture.completeBasic()
61+
val elementStrings = myFixture.lookupElementStrings
62+
assertFalse(elementStrings!!.containsAll(listOf("myFieldName", "myFunction")))
63+
}
64+
}

0 commit comments

Comments
 (0)