|
1 | 1 | package io.github.composegears.valkyrie.generator.imagevector |
2 | 2 |
|
| 3 | +import assertk.assertFailure |
3 | 4 | import assertk.assertThat |
| 5 | +import assertk.assertions.hasMessage |
4 | 6 | import assertk.assertions.isEqualTo |
| 7 | +import assertk.assertions.isInstanceOf |
5 | 8 | import io.github.composegears.valkyrie.extensions.ResourceUtils.getResourcePath |
6 | 9 | import io.github.composegears.valkyrie.generator.imagevector.common.createConfig |
7 | 10 | import io.github.composegears.valkyrie.generator.imagevector.common.toResourceText |
8 | 11 | import io.github.composegears.valkyrie.parser.svgxml.SvgXmlParser |
9 | 12 | import io.github.composegears.valkyrie.parser.svgxml.util.IconType.XML |
| 13 | +import kotlin.io.path.Path |
| 14 | +import org.junit.jupiter.api.Test |
10 | 15 | import org.junit.jupiter.params.ParameterizedTest |
11 | 16 | import org.junit.jupiter.params.provider.EnumSource |
12 | 17 |
|
13 | 18 | class XmlToImageVectorTest { |
14 | 19 |
|
| 20 | + @Test |
| 21 | + fun `broken icon path should throw exception`() { |
| 22 | + val brokenIconPath = Path("") |
| 23 | + |
| 24 | + assertFailure { |
| 25 | + SvgXmlParser.toIrImageVector(brokenIconPath) |
| 26 | + }.isInstanceOf(IllegalStateException::class) |
| 27 | + .hasMessage(" must be an SVG or XML file.") |
| 28 | + } |
| 29 | + |
15 | 30 | @ParameterizedTest |
16 | 31 | @EnumSource(value = OutputFormat::class) |
17 | 32 | fun `generation without icon pack`(outputFormat: OutputFormat) { |
@@ -186,6 +201,75 @@ class XmlToImageVectorTest { |
186 | 201 | assertThat(output).isEqualTo(expected) |
187 | 202 | } |
188 | 203 |
|
| 204 | + @ParameterizedTest |
| 205 | + @EnumSource(value = OutputFormat::class) |
| 206 | + fun `icon with compose colors enabled`(outputFormat: OutputFormat) { |
| 207 | + val icon = getResourcePath("imagevector/xml/ic_compose_color.xml") |
| 208 | + val parserOutput = SvgXmlParser.toIrImageVector(icon) |
| 209 | + val output = ImageVectorGenerator.convert( |
| 210 | + vector = parserOutput.irImageVector, |
| 211 | + iconName = parserOutput.iconName, |
| 212 | + config = createConfig( |
| 213 | + packName = "ValkyrieIcons", |
| 214 | + outputFormat = outputFormat, |
| 215 | + useComposeColors = true, |
| 216 | + ), |
| 217 | + ).content |
| 218 | + |
| 219 | + val expected = outputFormat.toResourceText( |
| 220 | + pathToBackingProperty = "imagevector/kt/backing/ComposeColor.kt", |
| 221 | + pathToLazyProperty = "imagevector/kt/lazy/ComposeColor.kt", |
| 222 | + ) |
| 223 | + assertThat(parserOutput.iconType).isEqualTo(XML) |
| 224 | + assertThat(output).isEqualTo(expected) |
| 225 | + } |
| 226 | + |
| 227 | + @ParameterizedTest |
| 228 | + @EnumSource(value = OutputFormat::class) |
| 229 | + fun `icon with compose colors and linear gradient`(outputFormat: OutputFormat) { |
| 230 | + val icon = getResourcePath("imagevector/xml/ic_compose_color_linear_gradient.xml") |
| 231 | + val parserOutput = SvgXmlParser.toIrImageVector(icon) |
| 232 | + val output = ImageVectorGenerator.convert( |
| 233 | + vector = parserOutput.irImageVector, |
| 234 | + iconName = parserOutput.iconName, |
| 235 | + config = createConfig( |
| 236 | + packName = "", |
| 237 | + outputFormat = outputFormat, |
| 238 | + useComposeColors = true, |
| 239 | + ), |
| 240 | + ).content |
| 241 | + |
| 242 | + val expected = outputFormat.toResourceText( |
| 243 | + pathToBackingProperty = "imagevector/kt/backing/ComposeColor.linear.gradient.kt", |
| 244 | + pathToLazyProperty = "imagevector/kt/lazy/ComposeColor.linear.gradient.kt", |
| 245 | + ) |
| 246 | + assertThat(parserOutput.iconType).isEqualTo(XML) |
| 247 | + assertThat(output).isEqualTo(expected) |
| 248 | + } |
| 249 | + |
| 250 | + @ParameterizedTest |
| 251 | + @EnumSource(value = OutputFormat::class) |
| 252 | + fun `icon with compose colors and radial gradient`(outputFormat: OutputFormat) { |
| 253 | + val icon = getResourcePath("imagevector/xml/ic_compose_color_radial_gradient.xml") |
| 254 | + val parserOutput = SvgXmlParser.toIrImageVector(icon) |
| 255 | + val output = ImageVectorGenerator.convert( |
| 256 | + vector = parserOutput.irImageVector, |
| 257 | + iconName = parserOutput.iconName, |
| 258 | + config = createConfig( |
| 259 | + packName = "", |
| 260 | + outputFormat = outputFormat, |
| 261 | + useComposeColors = true, |
| 262 | + ), |
| 263 | + ).content |
| 264 | + |
| 265 | + val expected = outputFormat.toResourceText( |
| 266 | + pathToBackingProperty = "imagevector/kt/backing/ComposeColor.radial.gradient.kt", |
| 267 | + pathToLazyProperty = "imagevector/kt/lazy/ComposeColor.radial.gradient.kt", |
| 268 | + ) |
| 269 | + assertThat(parserOutput.iconType).isEqualTo(XML) |
| 270 | + assertThat(output).isEqualTo(expected) |
| 271 | + } |
| 272 | + |
189 | 273 | @ParameterizedTest |
190 | 274 | @EnumSource(value = OutputFormat::class) |
191 | 275 | fun `icon with transparent fill color`(outputFormat: OutputFormat) { |
|
0 commit comments