Skip to content

Commit

Permalink
Add a test for avoiding clip groups
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Jun 2, 2021
1 parent f7c18c4 commit d72cb42
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jzbrooks.vgo.core.optimization

import assertk.assertThat
import assertk.assertions.containsExactly
import com.jzbrooks.vgo.core.graphic.ClipPath
import com.jzbrooks.vgo.core.graphic.ContainerElement
import com.jzbrooks.vgo.core.graphic.Element
import com.jzbrooks.vgo.core.graphic.Graphic
Expand Down Expand Up @@ -73,4 +74,30 @@ class CollapseGroupsTests {

assertThat(graphic::elements).containsExactly(innerGroupWithAttributes)
}

@Test
fun testAvoidCollapsingGroupsWithClipPaths() {
val clip = createPath(listOf(MoveTo(CommandVariant.ABSOLUTE, listOf(Point(10f, 15f)))))
val group = Group(
listOf(
ClipPath(listOf(clip), null, mutableMapOf()),
Group(
listOf(ClipPath(listOf(clip), null, mutableMapOf()))
)
)
)

val graphic = object : Graphic {
override var elements: List<Element> = listOf(group)
override val id: String? = null
override val foreign: MutableMap<String, String> = mutableMapOf()
}

val groupCollapser = CollapseGroups()
traverseBottomUp(graphic) {
if (it is ContainerElement) groupCollapser.visit(it)
}

assertThat(graphic::elements).containsExactly(group)
}
}

0 comments on commit d72cb42

Please sign in to comment.