@@ -2,40 +2,27 @@ package io.github.composegears.valkyrie.parser.ktfile
22
33import androidx.compose.material.icons.materialIcon
44import androidx.compose.material.icons.materialPath
5- import androidx.compose.ui.geometry.Offset
6- import androidx.compose.ui.graphics.Brush
75import androidx.compose.ui.graphics.Color
86import androidx.compose.ui.graphics.PathFillType
97import androidx.compose.ui.graphics.SolidColor
108import androidx.compose.ui.graphics.StrokeCap
119import androidx.compose.ui.graphics.StrokeJoin
1210import androidx.compose.ui.graphics.vector.ImageVector
13- import androidx.compose.ui.graphics.vector.PathData
1411import androidx.compose.ui.graphics.vector.group
1512import androidx.compose.ui.graphics.vector.path
1613import androidx.compose.ui.unit.dp
1714import assertk.assertThat
1815import assertk.assertions.isEqualTo
19- import com.intellij.openapi.project.Project
20- import com.intellij.testFramework.ProjectExtension
2116import com.intellij.testFramework.runInEdtAndGet
17+ import io.github.composegears.valkyrie.parser.ktfile.common.BaseKtParserTest
2218import io.github.composegears.valkyrie.parser.ktfile.common.ParseType
2319import io.github.composegears.valkyrie.parser.ktfile.common.createKtFile
2420import io.github.composegears.valkyrie.parser.ktfile.common.toKtFile
2521import org.junit.jupiter.api.Test
26- import org.junit.jupiter.api.extension.RegisterExtension
2722import org.junit.jupiter.params.ParameterizedTest
2823import org.junit.jupiter.params.provider.EnumSource
2924
30- class KtFileToImageVectorParserTest {
31-
32- companion object {
33- @RegisterExtension
34- val projectExtension = ProjectExtension ()
35- }
36-
37- private val project: Project
38- get() = projectExtension.project
25+ class KtFileToImageVectorParserTest : BaseKtParserTest () {
3926
4027 @ParameterizedTest
4128 @EnumSource(value = ParseType ::class )
@@ -203,77 +190,6 @@ class KtFileToImageVectorParserTest {
203190 assertThat(imageVector).isEqualTo(expected)
204191 }
205192
206- @ParameterizedTest
207- @EnumSource(value = ParseType ::class )
208- fun `parse icon with linear and radial gradient` (parseType : ParseType ) = runInEdtAndGet {
209- val ktFile = parseType.toKtFile(
210- project = project,
211- pathToLazy = " lazy/IconWithGradient.kt" ,
212- pathToBacking = " backing/IconWithGradient.kt" ,
213- )
214- val imageVector = KtFileToImageVectorParser .parse(ktFile)
215-
216- val expected = ImageVector .Builder (
217- name = " IconWithGradient" ,
218- defaultWidth = 51 .dp,
219- defaultHeight = 63 .dp,
220- viewportWidth = 51f ,
221- viewportHeight = 63f ,
222- ).apply {
223- path(
224- fill = Brush .radialGradient(
225- colorStops = arrayOf(
226- 0.19f to Color (0xFFD53A42 ),
227- 0.39f to Color (0xFFDF7A40 ),
228- 0.59f to Color (0xFFF0A941 ),
229- 1f to Color (0xFFFFFFF0 ),
230- ),
231- center = Offset (0f , 10f ),
232- radius = 100f ,
233- ),
234- stroke = SolidColor (Color (0x00000000 )),
235- ) {
236- moveTo(0f , 0f )
237- horizontalLineToRelative(100f )
238- verticalLineToRelative(20f )
239- horizontalLineToRelative(- 100f )
240- close()
241- }
242- path(
243- fill = Brush .linearGradient(
244- colorStops = arrayOf(
245- 0.126f to Color (0xFFE7BD76 ),
246- 0.13f to Color (0xFFE6BB74 ),
247- 0.247f to Color (0xFFD48E4E ),
248- 0.334f to Color (0xFFCC753B ),
249- 0.38f to Color (0xFFC96C35 ),
250- 0.891f to Color (0xFFC96D34 ),
251- 0.908f to Color (0xFFCC7439 ),
252- 0.937f to Color (0xFFD28647 ),
253- 0.973f to Color (0xFFDEA763 ),
254- 0.989f to Color (0xFFE5B972 ),
255- ),
256- start = Offset (46.778f , 40.493f ),
257- end = Offset (24.105f , 63.166f ),
258- ),
259- ) {
260- moveTo(51f , 44.716f )
261- reflectiveCurveToRelative(- 6.586f , 6.584f , - 9.823f , 6.805f )
262- curveToRelative(- 3.235f , 0.224f , - 7.032f , 0f , - 7.032f , 0f )
263- reflectiveCurveToRelative(- 7.024f , 1.732f , - 7.024f , 7.368f )
264- verticalLineTo(63f )
265- lineToRelative(- 3.195f , - 0.014f )
266- verticalLineToRelative(- 5.571f )
267- curveToRelative(0f , - 6.857f , 10.052f , - 7.567f , 10.052f , - 7.567f )
268- reflectiveCurveTo(39.057f , 41.979f , 51f , 44.716f )
269- }
270- }.build()
271-
272- // assertKt error due usage arrayList inside ImageVector:
273- // "did not compare equal to the same type with the same string representation"
274- assertThat(imageVector.toString()).isEqualTo(expected.toString())
275- }
276-
277193 @ParameterizedTest
278194 @EnumSource(value = ParseType ::class )
279195 fun `parse single path property` (parseType : ParseType ) = runInEdtAndGet {
@@ -382,149 +298,6 @@ class KtFileToImageVectorParserTest {
382298 assertThat(imageVector).isEqualTo(expected)
383299 }
384300
385- @ParameterizedTest
386- @EnumSource(value = ParseType ::class )
387- fun `parse gradient with clip path` (parseType : ParseType ) = runInEdtAndGet {
388- val ktFile = parseType.toKtFile(
389- project = project,
390- pathToLazy = " imagevector/kt//lazy/ClipPathGradient.kt" ,
391- pathToBacking = " imagevector/kt/backing/ClipPathGradient.kt" ,
392- )
393- val imageVector = KtFileToImageVectorParser .parse(ktFile)
394-
395- val expected = ImageVector .Builder (
396- name = " ClipPathGradient" ,
397- defaultWidth = 5000 .dp,
398- defaultHeight = 2916 .dp,
399- viewportWidth = 5000f ,
400- viewportHeight = 2916f ,
401- ).apply {
402- group(
403- clipPathData = PathData {
404- moveTo(1026f , 918f )
405- curveTo(1877f , 1321.7f , 2427f , 602.7f , 2721.6f , 0f )
406- horizontalLineTo(0f )
407- verticalLineToRelative(698.6f )
408- curveToRelative(264.3f , - 29.7f , 602.1f , 18.2f , 1026f , 219.3f )
409- },
410- ) {
411- path(
412- fill = Brush .linearGradient(
413- colorStops = arrayOf(
414- 0f to Color (0xFF00CCFF ),
415- 1f to Color (0xFF000066 ),
416- ),
417- start = Offset (413f , 1501.2f ),
418- end = Offset (2500.6f , - 349.7f ),
419- ),
420- ) {
421- moveTo(0f , 0f )
422- horizontalLineToRelative(2721.6f )
423- verticalLineToRelative(1321.7f )
424- horizontalLineToRelative(- 2721.6f )
425- close()
426- }
427- }
428- group(
429- clipPathData = PathData {
430- moveTo(2721.6f , 0f )
431- curveToRelative(- 294.6f , 602.7f , - 844.7f , 1321.7f , - 1695.6f , 918f )
432- curveTo(602.1f , 716.9f , 264.3f , 668.9f , 0f , 698.6f )
433- verticalLineToRelative(573.2f )
434- curveToRelative(331f , - 133.9f , 782.3f , - 132.4f , 1266f , 406.1f )
435- curveToRelative(1219.8f , 1358.1f , 2464f , - 1169f , 3734f , - 1120.8f )
436- verticalLineTo(0f )
437- horizontalLineToRelative(- 2278.4f )
438- close()
439- },
440- ) {
441- path(
442- fill = Brush .linearGradient(
443- colorStops = arrayOf(
444- 0f to Color (0xFF00CCFF ),
445- 1f to Color (0xFF000066 ),
446- ),
447- start = Offset (717.4f , 2963.9f ),
448- end = Offset (4849.2f , - 387.4f ),
449- ),
450- ) {
451- moveTo(0f , 0f )
452- horizontalLineToRelative(5000f )
453- verticalLineToRelative(3036.1f )
454- horizontalLineToRelative(- 5000f )
455- close()
456- }
457- }
458- group(
459- clipPathData = PathData {
460- moveTo(5000f , 557.2f )
461- curveToRelative(- 1270f , - 48.2f , - 2514.2f , 2478.9f , - 3734f , 1120.8f )
462- curveTo(782.3f , 1139.5f , 331f , 1138f , 0f , 1271.9f )
463- verticalLineToRelative(566.4f )
464- curveToRelative(354f , - 194.6f , 925.2f , - 246.3f , 1626f , 629.7f )
465- curveToRelative(157.9f , 197.4f , 309.2f , 344f , 455f , 448f )
466- horizontalLineToRelative(1220.8f )
467- curveToRelative(566.6f , - 357.5f , 1094.3f , - 1069.6f , 1698.3f , - 1323.7f )
468- verticalLineTo(557.2f )
469- close()
470- },
471- ) {
472- path(
473- fill = Brush .linearGradient(
474- colorStops = arrayOf(
475- 0f to Color (0xFF00CCFF ),
476- 1f to Color (0xFF000066 ),
477- ),
478- start = Offset (304.5f , 3342f ),
479- end = Offset (4838.1f , 101.2f ),
480- ),
481- ) {
482- moveTo(0f , 509f )
483- horizontalLineToRelative(5000f )
484- verticalLineToRelative(2527.1f )
485- horizontalLineToRelative(- 5000f )
486- close()
487- }
488- }
489- group(
490- clipPathData = PathData {
491- moveTo(5000f , 1592.3f )
492- curveToRelative(- 604f , 254.1f , - 1131.7f , 966.3f , - 1698.3f , 1323.7f )
493- horizontalLineToRelative(1698.3f )
494- verticalLineToRelative(- 1323.7f )
495- close()
496- moveTo(1626f , 2468f )
497- curveTo(925.2f , 1592f , 354f , 1643.7f , 0f , 1838.3f )
498- verticalLineToRelative(1077.7f )
499- horizontalLineToRelative(2081f )
500- curveToRelative(- 145.8f , - 104.1f , - 297f , - 250.6f , - 455f , - 448f )
501- close()
502- },
503- ) {
504- path(
505- fill = Brush .linearGradient(
506- colorStops = arrayOf(
507- 0f to Color (0xFF00CCFF ),
508- 1f to Color (0xFF000066 ),
509- ),
510- start = Offset (1225.5f , 3877.8f ),
511- end = Offset (3836.7f , 550.9f ),
512- ),
513- ) {
514- moveTo(0f , 1592f )
515- horizontalLineToRelative(5000f )
516- verticalLineToRelative(1324f )
517- horizontalLineToRelative(- 5000f )
518- close()
519- }
520- }
521- }.build()
522-
523- // assertKt error due usage arrayList inside ImageVector:
524- // "did not compare equal to the same type with the same string representation"
525- assertThat(imageVector.toString()).isEqualTo(expected.toString())
526- }
527-
528301 @ParameterizedTest
529302 @EnumSource(value = ParseType ::class )
530303 fun `parse compose color` (parseType : ParseType ) = runInEdtAndGet {
0 commit comments