@@ -2,12 +2,10 @@ package io.github.composegears.valkyrie.sdk.intellij.psi.imagevector
22
33import assertk.assertThat
44import assertk.assertions.isEqualTo
5- import com.intellij.openapi.project.Project
6- import com.intellij.testFramework.ProjectExtension
5+ import com.intellij.testFramework.junit5.TestApplication
76import com.intellij.testFramework.runInEdtAndGet
7+ import io.github.composegears.valkyrie.psi.TEST_DATA_PATH
88import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.common.ParseType
9- import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.common.createKtFile
10- import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.common.toKtFile
119import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedAllGroupParams
1210import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedAllPathParams
1311import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedClipPathGradient
@@ -24,31 +22,21 @@ import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.Exp
2422import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedMaterialIconWithoutParam2
2523import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedRadialGradient
2624import io.github.composegears.valkyrie.sdk.intellij.psi.imagevector.expected.ExpectedSinglePath
25+ import io.github.composegears.valkyrie.sdk.intellij.testfixtures.KotlinCodeInsightTest
2726import io.github.composegears.valkyrie.sdk.ir.compose.toComposeImageVector
27+ import org.jetbrains.kotlin.psi.KtFile
2828import org.junit.jupiter.api.Test
29- import org.junit.jupiter.api.extension.RegisterExtension
3029import org.junit.jupiter.params.ParameterizedClass
3130import org.junit.jupiter.params.provider.EnumSource
3231
32+ @TestApplication
3333@ParameterizedClass
3434@EnumSource(value = ParseType ::class )
35- class KtFileToImageVectorParserTest (
36- private val parseType : ParseType ,
37- ) {
38-
39- companion object {
40- @JvmField
41- @RegisterExtension
42- val projectExtension = ProjectExtension ()
43- }
44-
45- private val project: Project
46- get() = projectExtension.project
35+ class KtFileToImageVectorParserTest (private val parseType : ParseType ) : KotlinCodeInsightTest() {
4736
4837 @Test
4938 fun `empty image vector` () = runInEdtAndGet {
5039 val ktFile = parseType.toKtFile(
51- project = project,
5240 pathToLazy = " lazy/EmptyImageVector.kt" ,
5341 pathToBacking = " backing/EmptyImageVector.kt" ,
5442 )
@@ -60,7 +48,6 @@ class KtFileToImageVectorParserTest(
6048 @Test
6149 fun `empty paths` () = runInEdtAndGet {
6250 val ktFile = parseType.toKtFile(
63- project = project,
6451 pathToLazy = " lazy/EmptyPaths.kt" ,
6552 pathToBacking = " backing/EmptyPaths.kt" ,
6653 )
@@ -72,7 +59,6 @@ class KtFileToImageVectorParserTest(
7259 @Test
7360 fun `parse all path params` () = runInEdtAndGet {
7461 val ktFile = parseType.toKtFile(
75- project = project,
7662 pathToLazy = " lazy/AllPathParams.kt" ,
7763 pathToBacking = " backing/AllPathParams.kt" ,
7864 )
@@ -83,39 +69,39 @@ class KtFileToImageVectorParserTest(
8369
8470 @Test
8571 fun `parse material icon` () = runInEdtAndGet {
86- val ktFile = project.createKtFile(from = " backing/MaterialIcon.all.kt" )
72+ val ktFile = loadKtFile( " backing/MaterialIcon.all.kt" )
8773 val imageVector = ImageVectorPsiParser .parseToIrImageVector(ktFile)?.toComposeImageVector()
8874
8975 assertThat(imageVector).isEqualTo(ExpectedMaterialIcon )
9076 }
9177
9278 @Test
9379 fun `parse material icon without param` () = runInEdtAndGet {
94- val ktFile = project.createKtFile(from = " backing/MaterialIcon.all.without.param.kt" )
80+ val ktFile = loadKtFile( " backing/MaterialIcon.all.without.param.kt" )
9581 val imageVector = ImageVectorPsiParser .parseToIrImageVector(ktFile)?.toComposeImageVector()
9682
9783 assertThat(imageVector).isEqualTo(ExpectedMaterialIconWithoutParam )
9884 }
9985
10086 @Test
10187 fun `parse material icon with several materialPath` () = runInEdtAndGet {
102- val ktFile = project.createKtFile(from = " backing/MaterialIcon.several.materialpath.kt" )
88+ val ktFile = loadKtFile( " backing/MaterialIcon.several.materialpath.kt" )
10389 val imageVector = ImageVectorPsiParser .parseToIrImageVector(ktFile)?.toComposeImageVector()
10490
10591 assertThat(imageVector).isEqualTo(ExpectedMaterialIconWithoutParam2 )
10692 }
10793
10894 @Test
10995 fun `parse material icon only with materialPath` () = runInEdtAndGet {
110- val ktFile = project.createKtFile(from = " backing/MaterialIcon.material.path.kt" )
96+ val ktFile = loadKtFile( " backing/MaterialIcon.material.path.kt" )
11197 val imageVector = ImageVectorPsiParser .parseToIrImageVector(ktFile)?.toComposeImageVector()
11298
11399 assertThat(imageVector).isEqualTo(ExpectedMaterialIconOnlyWithPath )
114100 }
115101
116102 @Test
117103 fun `parse icon with import member` () = runInEdtAndGet {
118- val ktFile = project.createKtFile(from = " backing/IconWithImportMember.kt" )
104+ val ktFile = loadKtFile( " backing/IconWithImportMember.kt" )
119105 val imageVector = ImageVectorPsiParser .parseToIrImageVector(ktFile)?.toComposeImageVector()
120106
121107 assertThat(imageVector).isEqualTo(ExpectedIconWithImportMember )
@@ -124,7 +110,6 @@ class KtFileToImageVectorParserTest(
124110 @Test
125111 fun `parse icon with group` () = runInEdtAndGet {
126112 val ktFile = parseType.toKtFile(
127- project = project,
128113 pathToLazy = " lazy/IconWithGroup.kt" ,
129114 pathToBacking = " backing/IconWithGroup.kt" ,
130115 )
@@ -136,7 +121,6 @@ class KtFileToImageVectorParserTest(
136121 @Test
137122 fun `parse single path property` () = runInEdtAndGet {
138123 val ktFile = parseType.toKtFile(
139- project = project,
140124 pathToLazy = " lazy/SinglePath.kt" ,
141125 pathToBacking = " backing/SinglePath.kt" ,
142126 )
@@ -148,7 +132,6 @@ class KtFileToImageVectorParserTest(
148132 @Test
149133 fun `parse all group params` () = runInEdtAndGet {
150134 val ktFile = parseType.toKtFile(
151- project = project,
152135 pathToLazy = " imagevector/kt/lazy/AllGroupParams.kt" ,
153136 pathToBacking = " imagevector/kt/backing/AllGroupParams.kt" ,
154137 )
@@ -160,7 +143,6 @@ class KtFileToImageVectorParserTest(
160143 @Test
161144 fun `parse compose color` () = runInEdtAndGet {
162145 val ktFile = parseType.toKtFile(
163- project = project,
164146 pathToLazy = " imagevector/kt/lazy/ComposeColor.kt" ,
165147 pathToBacking = " imagevector/kt/backing/ComposeColor.kt" ,
166148 )
@@ -172,7 +154,6 @@ class KtFileToImageVectorParserTest(
172154 @Test
173155 fun `parse icon with linear gradient` () = runInEdtAndGet {
174156 val ktFile = parseType.toKtFile(
175- project = project,
176157 pathToLazy = " imagevector/kt/backing/LinearGradient.kt" ,
177158 pathToBacking = " imagevector/kt/lazy/LinearGradient.kt" ,
178159 )
@@ -184,7 +165,6 @@ class KtFileToImageVectorParserTest(
184165 @Test
185166 fun `parse icon with linear gradient and stroke` () = runInEdtAndGet {
186167 val ktFile = parseType.toKtFile(
187- project = project,
188168 pathToLazy = " imagevector/kt/backing/LinearGradientWithStroke.kt" ,
189169 pathToBacking = " imagevector/kt/lazy/LinearGradientWithStroke.kt" ,
190170 )
@@ -196,7 +176,6 @@ class KtFileToImageVectorParserTest(
196176 @Test
197177 fun `parse linear gradient with clip path` () = runInEdtAndGet {
198178 val ktFile = parseType.toKtFile(
199- project = project,
200179 pathToLazy = " imagevector/kt/lazy/ClipPathGradient.kt" ,
201180 pathToBacking = " imagevector/kt/backing/ClipPathGradient.kt" ,
202181 )
@@ -208,12 +187,22 @@ class KtFileToImageVectorParserTest(
208187 @Test
209188 fun `parse icon with radial gradient` () = runInEdtAndGet {
210189 val ktFile = parseType.toKtFile(
211- project = project,
212190 pathToLazy = " imagevector/kt/backing/RadialGradient.kt" ,
213191 pathToBacking = " imagevector/kt/lazy/RadialGradient.kt" ,
214192 )
215193 val imageVector = ImageVectorPsiParser .parseToIrImageVector(ktFile)?.toComposeImageVector()
216194
217195 assertThat(imageVector).isEqualTo(ExpectedRadialGradient )
218196 }
197+
198+ // Use path for build folder with all generated test resources
199+ override val testDataPath: String = TEST_DATA_PATH
200+
201+ fun ParseType.toKtFile (
202+ pathToLazy : String ,
203+ pathToBacking : String ,
204+ ): KtFile = when (this ) {
205+ ParseType .Lazy -> loadKtFile(pathToLazy)
206+ ParseType .Backing -> loadKtFile(pathToBacking)
207+ }
219208}
0 commit comments