Browse Source

Support negation for CSSNumeric values

This resolves #921
pull/927/head
Shagen Ogandzhanian 3 years ago
parent
commit
b9a87578fc
  1. 2
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSOperations.kt
  2. 72
      web/core/src/jsTest/kotlin/CSSUnitApiTests.kt

2
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSOperations.kt

@ -12,6 +12,8 @@ operator fun <T: CSSUnit> CSSSizeValue<T>.div(num: Number): CSSSizeValue<T> = CS
operator fun <T: CSSUnit> CSSSizeValue<T>.plus(b: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(value + b.value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.minus(b: CSSSizeValue<T>): CSSSizeValue<T> = CSSUnitValueTyped(value - b.value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.unaryMinus(): CSSSizeValue<T> = CSSUnitValueTyped(-value, unit)
operator fun <T: CSSUnit> CSSSizeValue<T>.unaryPlus(): CSSSizeValue<T> = CSSUnitValueTyped(value, unit)
external interface CSSCalcOperation<T : CSSUnit>: CSSNumericValue<T>

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

@ -273,6 +273,78 @@ class CSSUnitApiTests {
assertEquals(1.fr, 7.fr - 4.fr - 2.fr)
}
@Test
fun unaryMinus() {
assertEquals((-3).percent, -3.percent)
assertEquals((-3).em, -3.em)
assertEquals((-3).ch, -3.ch)
assertEquals((-3).cssRem, -3.cssRem)
assertEquals((-3).vw, -3.vw)
assertEquals((-3).vh, -3.vh)
assertEquals((-3).vmin, -3.vmin)
assertEquals((-3).vmax, -3.vmax)
assertEquals((-3).cm, -3.cm)
assertEquals((-3).mm, -3.mm)
assertEquals((-3).pt, -3.pt)
assertEquals((-3).pc, -3.pc)
assertEquals((-3).px, -3.px)
assertEquals((-3).deg, -3.deg)
assertEquals((-3).grad, -3.grad)
assertEquals((-3).rad, -3.rad)
assertEquals((-3).turn, -3.turn)
assertEquals((-3).s, -3.s)
assertEquals((-3).ms, -3.ms)
assertEquals((-3).dpi, -3.dpi)
assertEquals((-3).dpcm, -3.dpcm)
assertEquals((-3).dppx, -3.dppx)
assertEquals((-3).fr, -3.fr)
}
@Test
fun unaryPlus() {
assertEquals(3.percent, +3.percent)
assertEquals(3.em, +3.em)
assertEquals(3.ch, +3.ch)
assertEquals(3.cssRem, +3.cssRem)
assertEquals(3.vw, +3.vw)
assertEquals(3.vh, +3.vh)
assertEquals(3.vmin, +3.vmin)
assertEquals(3.vmax, +3.vmax)
assertEquals(3.cm, +3.cm)
assertEquals(3.mm, +3.mm)
assertEquals(3.pt, +3.pt)
assertEquals(3.pc, +3.pc)
assertEquals(3.px, +3.px)
assertEquals(3.deg, +3.deg)
assertEquals(3.grad, +3.grad)
assertEquals(3.rad, +3.rad)
assertEquals(3.turn, +3.turn)
assertEquals(3.s, +3.s)
assertEquals(3.ms, +3.ms)
assertEquals(3.dpi, +3.dpi)
assertEquals(3.dpcm, +3.dpcm)
assertEquals(3.dppx, +3.dppx)
assertEquals(3.fr, +3.fr)
}
@Test
fun calcMultiplicationLeft() {
val typedResultAbs: CSSNumericValue<CSSUnitAbs> = ((4.pt + 4.px) * 4)

Loading…
Cancel
Save