Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix(lsp): invalid inferred file extensions in FileProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed May 29, 2024
1 parent e15454e commit c698d9a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.junit.Ignore

/** @author Akash Yadav */
@Ignore("Base singleton class")
object JavaLSPTest : LSPTest() {
object JavaLSPTest : LSPTest("java") {

val server by lazy {
ILanguageServerRegistry.getDefault().getServer(JavaLanguageServer.SERVER_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ import java.nio.file.Path
*/
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.DEFAULT_VALUE_STRING)
abstract class LSPTest {
abstract class LSPTest(
private val sourceFileExt: String,
) {

protected lateinit var toolingServer: IToolingApiServer
protected lateinit var toolingProject: IProject
Expand Down Expand Up @@ -162,7 +164,7 @@ abstract class LSPTest {
}

open fun openFile(fileName: String) {
file = FileProvider.sourceFile(fileName).normalize()
file = FileProvider.sourceFile(fileName, sourceFileExt).normalize()
contents = FileProvider.contents(file!!)

dispatchEvent(DocumentOpenEvent(file!!, contents.toString(), 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FileProvider {
* @return The path to the file.
*/
@JvmStatic
fun sourceFile(name: String): Path {
fun sourceFile(name: String, extension: String = ""): Path {
return resources().resolve("${name}_template.$extension").normalize()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,15 @@ class FileProviderTest {

@Test
fun testPath() {
val path = FileProvider.sourceFile("SourceFileTest")
val path = FileProvider.sourceFile("SourceFileTest", "java")
assertThat(Files.exists(path)).isTrue()
assertThat(path.fileName.toString()).isEqualTo("SourceFileTest_template.java")
}

@Test
fun testNested() {
val path = FileProvider.sourceFile("package/SourceFileTest")
val path = FileProvider.sourceFile("package/SourceFileTest", "java")
assertThat(Files.exists(path)).isTrue()
assertThat(path.fileName.toString()).isEqualTo("SourceFileTest_template.java")
}

@Test
fun testExtension() {
val folder = File(".").canonicalFile

assertThat(FileProvider.extension).isNotEmpty()
assertThat(FileProvider.extension)
.isEqualTo(
when (folder.name) {
"xml" -> "xml"
else -> "java"
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.junit.Ignore

/** @author Akash Yadav */
@Ignore("Base class for XML tests")
object XMLLSPTest : LSPTest() {
object XMLLSPTest : LSPTest("xml") {

@Before
override fun initProjectIfNeeded() {
Expand Down

0 comments on commit c698d9a

Please sign in to comment.