Browse Source

addHomogenous

CSS_UNIT_WITH_ARITHMETIC_OPERATIONS
Shagen Ogandzhanian 4 years ago
parent
commit
8e7e2cf831
  1. 2
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt
  2. 37
      web/core/src/jsTest/kotlin/CSSUnitApiTests.kt

2
web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSUnits.kt

@ -19,6 +19,8 @@ operator fun <T : CSSUnit> Number.times(unit: CSSSizeValue<T>): CSSSizeValue<T>
operator fun <T : CSSUnit> CSSSizeValue<T>.div(num: Number): CSSSizeValue<T> = newUnit(value / num.toFloat()) operator fun <T : CSSUnit> CSSSizeValue<T>.div(num: Number): CSSSizeValue<T> = newUnit(value / num.toFloat())
operator fun <T: CSSUnit> CSSSizeValue<T>.plus(b: CSSSizeValue<T>): CSSSizeValue<T> = newUnit(value + b.value)
typealias CSSUnitValue = CSSSizeValue<CSSUnit> typealias CSSUnitValue = CSSSizeValue<CSSUnit>
typealias CSSpxValue = CSSSizeValue<CSSUnit.px> typealias CSSpxValue = CSSSizeValue<CSSUnit.px>

37
web/core/src/jsTest/kotlin/CSSUnitApiTests.kt

@ -21,6 +21,7 @@ import org.jetbrains.compose.web.css.ms
import org.jetbrains.compose.web.css.number import org.jetbrains.compose.web.css.number
import org.jetbrains.compose.web.css.pc import org.jetbrains.compose.web.css.pc
import org.jetbrains.compose.web.css.percent import org.jetbrains.compose.web.css.percent
import org.jetbrains.compose.web.css.plus
import org.jetbrains.compose.web.css.pt import org.jetbrains.compose.web.css.pt
import org.jetbrains.compose.web.css.px import org.jetbrains.compose.web.css.px
import org.jetbrains.compose.web.css.rad import org.jetbrains.compose.web.css.rad
@ -222,4 +223,40 @@ class CSSUnitApiTests {
assertEquals(12.fr, 3 * 4.fr) assertEquals(12.fr, 3 * 4.fr)
} }
@Test
fun addHomogenous() {
assertEquals(13.percent, 7.percent + 4.percent + 2.percent)
assertEquals(13.em, 7.em + 4.em + 2.em)
assertEquals(13.ch, 7.ch + 4.ch + 2.ch)
assertEquals(13.cssRem, 7.cssRem + 4.cssRem + 2.cssRem)
assertEquals(13.vw, 7.vw + 4.vw + 2.vw)
assertEquals(13.vh, 7.vh + 4.vh + 2.vh)
assertEquals(13.vmin, 7.vmin + 4.vmin + 2.vmin)
assertEquals(13.vmax, 7.vmax + 4.vmax + 2.vmax)
assertEquals(13.cm, 7.cm + 4.cm + 2.cm)
assertEquals(13.mm, 7.mm + 4.mm + 2.mm)
assertEquals(13.pt, 7.pt + 4.pt + 2.pt)
assertEquals(13.pc, 7.pc + 4.pc + 2.pc)
assertEquals(13.px, 7.px + 4.px + 2.px)
assertEquals(13.deg, 7.deg + 4.deg + 2.deg)
assertEquals(13.grad, 7.grad + 4.grad + 2.grad)
assertEquals(13.rad, 7.rad + 4.rad + 2.rad)
assertEquals(13.turn, 7.turn + 4.turn + 2.turn)
assertEquals(13.s, 7.s + 4.s + 2.s)
assertEquals(13.ms, 7.ms + 4.ms + 2.ms)
assertEquals(13.dpi, 7.dpi + 4.dpi + 2.dpi)
assertEquals(13.dpcm, 7.dpcm + 4.dpcm + 2.dpcm)
assertEquals(13.dppx, 7.dppx + 4.dppx + 2.dppx)
assertEquals(13.fr, 7.fr + 4.fr + 2.fr)
}
} }
Loading…
Cancel
Save