generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix Svelte imports being prepended by \ for utils - Add tests for this - Move previous tests to their correct package - Update Gradle
- Loading branch information
1 parent
458c570
commit 34fede3
Showing
22 changed files
with
396 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ithub/warningimhack3r/intellijshadcnplugin/backend/sources/impl/ReactReplacementsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.sources.impl | ||
|
||
import com.github.warningimhack3r.intellijshadcnplugin.backend.sources.config.ReactConfig | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
|
||
class ReactReplacementsTests : ReplacementsTests() { | ||
private var useNotNullUI = false | ||
|
||
inner class ReactSourceStub(project: Project) : ReactSource(project) { | ||
override fun getLocalConfig() = ReactConfig( | ||
style = "default", | ||
rsc = true, | ||
tsx = true, | ||
tailwind = ReactConfig.Tailwind( | ||
config = "tailwind.config.js", | ||
css = "app/globals.css", | ||
baseColor = "slate", | ||
cssVariables = true, | ||
prefix = "" | ||
), | ||
aliases = ReactConfig.Aliases( | ||
components = "@/components", | ||
utils = "@/lib/utilsReplaced", | ||
ui = if (useNotNullUI) "@/ui" else null | ||
) | ||
) | ||
|
||
public override fun adaptFileToConfig(file: PsiFile) { | ||
super.adaptFileToConfig(file) | ||
} | ||
} | ||
|
||
private val compareImports by lazy { | ||
compareImportsBuilder( | ||
ReactSourceStub(project)::adaptFileToConfig, | ||
"tsx", | ||
""" | ||
import { foo } from "{{import}}"; | ||
""".trimIndent() | ||
) | ||
} | ||
|
||
fun testImportMatchingRegistry() { | ||
compareImports("@/components/bar", "@/registry/foo/bar") | ||
} | ||
|
||
fun testImportMatchingRegistry2() { | ||
compareImports("@/components", "@/registry/foo") | ||
} | ||
|
||
fun testImportNotMatchingRegistry() { | ||
compareImports("@/lib/notregistry/foo", "@/lib/notregistry/foo") | ||
} | ||
|
||
fun testImportMatchingRegistryWithUI() { | ||
useNotNullUI = true | ||
compareImports("@/ui", "@/registry/foo/ui") | ||
} | ||
|
||
fun testImportNotMatchingRegistryWithUI() { | ||
useNotNullUI = true | ||
compareImports("@/registry/foo", "@/registry/foo") | ||
} | ||
|
||
fun testImportMatchingUI() { | ||
compareImports("@/lib/utilsReplaced", "@/lib/utils") | ||
} | ||
|
||
fun testImportNotMatchingAny() { | ||
compareImports("./lib/foo", "./lib/foo") | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...com/github/warningimhack3r/intellijshadcnplugin/backend/sources/impl/ReplacementsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.sources.impl | ||
|
||
import com.intellij.psi.PsiFile | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
|
||
open class ReplacementsTests : BasePlatformTestCase() { | ||
|
||
/** | ||
* Creates a function that compares two imports in a file. | ||
* | ||
* @param transformer A function that modifies the file before comparison. | ||
* @param extension The file extension. | ||
* @param fileShape The file shape with a placeholder for the import. The placeholder is `{{import}}`. | ||
* | ||
* @return A function that compares two imports in a file, given the expected then actual imports. | ||
*/ | ||
fun compareImportsBuilder( | ||
transformer: (PsiFile) -> Unit, | ||
extension: String, | ||
fileShape: String | ||
): (String, String) -> Unit { | ||
return { expected, actual -> | ||
val psiFile = myFixture.configureByText( | ||
"App.$extension", fileShape.replace("{{import}}", actual) | ||
) | ||
transformer(psiFile) | ||
assertEquals( | ||
fileShape.replace("{{import}}", expected), | ||
psiFile.text | ||
) | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ithub/warningimhack3r/intellijshadcnplugin/backend/sources/impl/SolidReplacementsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.warningimhack3r.intellijshadcnplugin.backend.sources.impl | ||
|
||
import com.github.warningimhack3r.intellijshadcnplugin.backend.sources.config.SolidConfig | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
|
||
class SolidReplacementsTests : ReplacementsTests() { | ||
|
||
class SolidSourceStub(project: Project) : SolidSource(project) { | ||
override fun getLocalConfig() = SolidConfig( | ||
tailwind = SolidConfig.Tailwind( | ||
config = "tailwind.config.cjs", | ||
css = "src/root.css", | ||
baseColor = "slate", | ||
cssVariables = true | ||
), | ||
aliases = SolidConfig.Aliases( | ||
components = "@/components", | ||
utils = "@/lib/utils" | ||
) | ||
) | ||
|
||
public override fun adaptFileToConfig(file: PsiFile) { | ||
super.adaptFileToConfig(file) | ||
} | ||
} | ||
|
||
private val compareImports by lazy { | ||
compareImportsBuilder( | ||
SolidSourceStub(project)::adaptFileToConfig, | ||
"tsx", | ||
""" | ||
import { foo } from "{{import}}"; | ||
""".trimIndent() | ||
) | ||
} | ||
|
||
fun testImportMatchingLibsCn() { | ||
compareImports("@/lib/utils", "@/libs/cn") | ||
} | ||
|
||
fun testImportNotMatchingLibsCn() { | ||
compareImports("@/libs/cn/foo", "@/libs/cn/foo") | ||
} | ||
|
||
fun testImportNotMatchingLibsCn2() { | ||
compareImports("@/lib/cn", "@/lib/cn") | ||
} | ||
} |
Oops, something went wrong.