@@ -1519,7 +1519,7 @@ fn generic_parser() {
1519
1519
enum OutputType {
1520
1520
CurrentColor ,
1521
1521
Rgba ( u8 , u8 , u8 , f32 ) ,
1522
- Hsl ( f32 , f32 , f32 , f32 ) ,
1522
+ Hsl ( Option < f32 > , Option < f32 > , Option < f32 > , Option < f32 > ) ,
1523
1523
Hwb ( Option < f32 > , Option < f32 > , Option < f32 > , Option < f32 > ) ,
1524
1524
Lab ( Option < f32 > , Option < f32 > , Option < f32 > , Option < f32 > ) ,
1525
1525
Lch ( Option < f32 > , Option < f32 > , Option < f32 > , Option < f32 > ) ,
@@ -1543,7 +1543,12 @@ fn generic_parser() {
1543
1543
OutputType :: Rgba ( red, green, blue, alpha)
1544
1544
}
1545
1545
1546
- fn from_hsl ( hue : f32 , saturation : f32 , lightness : f32 , alpha : f32 ) -> Self {
1546
+ fn from_hsl (
1547
+ hue : Option < f32 > ,
1548
+ saturation : Option < f32 > ,
1549
+ lightness : Option < f32 > ,
1550
+ alpha : Option < f32 > ,
1551
+ ) -> Self {
1547
1552
OutputType :: Hsl ( hue, saturation, lightness, alpha)
1548
1553
}
1549
1554
@@ -1609,133 +1614,37 @@ fn generic_parser() {
1609
1614
type Error = ( ) ;
1610
1615
}
1611
1616
1617
+ #[ rustfmt:: skip]
1612
1618
const TESTS : & [ ( & str , OutputType ) ] = & [
1613
- ( "currentColor" , OutputType :: CurrentColor ) ,
1614
- ( "rgb(1, 2, 3)" , OutputType :: Rgba ( 1 , 2 , 3 , 1.0 ) ) ,
1615
- ( "rgba(1, 2, 3, 0.4)" , OutputType :: Rgba ( 1 , 2 , 3 , 0.4 ) ) ,
1616
- ( "rgb(none none none / none)" , OutputType :: Rgba ( 0 , 0 , 0 , 0.0 ) ) ,
1617
- ( "rgb(1 none 3 / none)" , OutputType :: Rgba ( 1 , 0 , 3 , 0.0 ) ) ,
1618
- (
1619
- "hsla(45deg, 20%, 30%, 0.4)" ,
1620
- OutputType :: Hsl ( 45.0 , 0.2 , 0.3 , 0.4 ) ,
1621
- ) ,
1622
- ( "hsl(45deg none none)" , OutputType :: Hsl ( 45.0 , 0.0 , 0.0 , 1.0 ) ) ,
1623
- (
1624
- "hsl(none 10% none / none)" ,
1625
- OutputType :: Hsl ( 0.0 , 0.1 , 0.0 , 0.0 ) ,
1626
- ) ,
1627
- (
1628
- "hsl(120 100.0% 50.0%)" ,
1629
- OutputType :: Hsl ( 120.0 , 1.0 , 0.5 , 1.0 ) ,
1630
- ) ,
1631
- (
1632
- "hwb(45deg 20% 30% / 0.4)" ,
1633
- OutputType :: Hwb ( Some ( 45.0 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ,
1634
- ) ,
1635
- (
1636
- "lab(100 20 30 / 0.4)" ,
1637
- OutputType :: Lab ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ,
1638
- ) ,
1639
- (
1640
- "lch(100 20 30 / 0.4)" ,
1641
- OutputType :: Lch ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ,
1642
- ) ,
1643
- (
1644
- "oklab(100 20 30 / 0.4)" ,
1645
- OutputType :: Oklab ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ,
1646
- ) ,
1647
- (
1648
- "oklch(100 20 30 / 0.4)" ,
1649
- OutputType :: Oklch ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ,
1650
- ) ,
1651
- (
1652
- "color(srgb 0.1 0.2 0.3 / 0.4)" ,
1653
- OutputType :: ColorFunction (
1654
- PredefinedColorSpace :: Srgb ,
1655
- Some ( 0.1 ) ,
1656
- Some ( 0.2 ) ,
1657
- Some ( 0.3 ) ,
1658
- Some ( 0.4 ) ,
1659
- ) ,
1660
- ) ,
1661
- (
1662
- "color(srgb-linear 0.1 0.2 0.3 / 0.4)" ,
1663
- OutputType :: ColorFunction (
1664
- PredefinedColorSpace :: SrgbLinear ,
1665
- Some ( 0.1 ) ,
1666
- Some ( 0.2 ) ,
1667
- Some ( 0.3 ) ,
1668
- Some ( 0.4 ) ,
1669
- ) ,
1670
- ) ,
1671
- (
1672
- "color(display-p3 0.1 0.2 0.3 / 0.4)" ,
1673
- OutputType :: ColorFunction (
1674
- PredefinedColorSpace :: DisplayP3 ,
1675
- Some ( 0.1 ) ,
1676
- Some ( 0.2 ) ,
1677
- Some ( 0.3 ) ,
1678
- Some ( 0.4 ) ,
1679
- ) ,
1680
- ) ,
1681
- (
1682
- "color(a98-rgb 0.1 0.2 0.3 / 0.4)" ,
1683
- OutputType :: ColorFunction (
1684
- PredefinedColorSpace :: A98Rgb ,
1685
- Some ( 0.1 ) ,
1686
- Some ( 0.2 ) ,
1687
- Some ( 0.3 ) ,
1688
- Some ( 0.4 ) ,
1689
- ) ,
1690
- ) ,
1691
- (
1692
- "color(prophoto-rgb 0.1 0.2 0.3 / 0.4)" ,
1693
- OutputType :: ColorFunction (
1694
- PredefinedColorSpace :: ProphotoRgb ,
1695
- Some ( 0.1 ) ,
1696
- Some ( 0.2 ) ,
1697
- Some ( 0.3 ) ,
1698
- Some ( 0.4 ) ,
1699
- ) ,
1700
- ) ,
1701
- (
1702
- "color(rec2020 0.1 0.2 0.3 / 0.4)" ,
1703
- OutputType :: ColorFunction (
1704
- PredefinedColorSpace :: Rec2020 ,
1705
- Some ( 0.1 ) ,
1706
- Some ( 0.2 ) ,
1707
- Some ( 0.3 ) ,
1708
- Some ( 0.4 ) ,
1709
- ) ,
1710
- ) ,
1711
- (
1712
- "color(xyz-d50 0.1 0.2 0.3 / 0.4)" ,
1713
- OutputType :: ColorFunction (
1714
- PredefinedColorSpace :: XyzD50 ,
1715
- Some ( 0.1 ) ,
1716
- Some ( 0.2 ) ,
1717
- Some ( 0.3 ) ,
1718
- Some ( 0.4 ) ,
1719
- ) ,
1720
- ) ,
1721
- (
1722
- "color(xyz-d65 0.1 0.2 0.3 / 0.4)" ,
1723
- OutputType :: ColorFunction (
1724
- PredefinedColorSpace :: XyzD65 ,
1725
- Some ( 0.1 ) ,
1726
- Some ( 0.2 ) ,
1727
- Some ( 0.3 ) ,
1728
- Some ( 0.4 ) ,
1729
- ) ,
1730
- ) ,
1731
- (
1732
- "color(srgb none none none)" ,
1733
- OutputType :: ColorFunction ( PredefinedColorSpace :: Srgb , None , None , None , Some ( 1.0 ) ) ,
1734
- ) ,
1735
- (
1736
- "color(srgb none none none / none)" ,
1737
- OutputType :: ColorFunction ( PredefinedColorSpace :: Srgb , None , None , None , None ) ,
1738
- ) ,
1619
+ ( "currentColor" , OutputType :: CurrentColor ) ,
1620
+ ( "rgb(1, 2, 3)" , OutputType :: Rgba ( 1 , 2 , 3 , 1.0 ) ) ,
1621
+ ( "rgba(1, 2, 3, 0.4)" , OutputType :: Rgba ( 1 , 2 , 3 , 0.4 ) ) ,
1622
+ ( "rgb(none none none / none)" , OutputType :: Rgba ( 0 , 0 , 0 , 0.0 ) ) ,
1623
+ ( "rgb(1 none 3 / none)" , OutputType :: Rgba ( 1 , 0 , 3 , 0.0 ) ) ,
1624
+
1625
+ ( "hsla(45deg, 20%, 30%, 0.4)" , OutputType :: Hsl ( Some ( 45.0 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1626
+ ( "hsl(45deg none none)" , OutputType :: Hsl ( Some ( 45.0 ) , None , None , Some ( 1.0 ) ) ) ,
1627
+ ( "hsl(none 10% none / none)" , OutputType :: Hsl ( None , Some ( 0.1 ) , None , None ) ) ,
1628
+ ( "hsl(120 100.0% 50.0%)" , OutputType :: Hsl ( Some ( 120.0 ) , Some ( 1.0 ) , Some ( 0.5 ) , Some ( 1.0 ) ) ) ,
1629
+
1630
+ ( "hwb(45deg 20% 30% / 0.4)" , OutputType :: Hwb ( Some ( 45.0 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1631
+
1632
+ ( "lab(100 20 30 / 0.4)" , OutputType :: Lab ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ) ,
1633
+ ( "lch(100 20 30 / 0.4)" , OutputType :: Lch ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ) ,
1634
+
1635
+ ( "oklab(100 20 30 / 0.4)" , OutputType :: Oklab ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ) ,
1636
+ ( "oklch(100 20 30 / 0.4)" , OutputType :: Oklch ( Some ( 100.0 ) , Some ( 20.0 ) , Some ( 30.0 ) , Some ( 0.4 ) ) ) ,
1637
+
1638
+ ( "color(srgb 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: Srgb , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1639
+ ( "color(srgb none none none)" , OutputType :: ColorFunction ( PredefinedColorSpace :: Srgb , None , None , None , Some ( 1.0 ) ) ) ,
1640
+ ( "color(srgb none none none / none)" , OutputType :: ColorFunction ( PredefinedColorSpace :: Srgb , None , None , None , None ) ) ,
1641
+ ( "color(srgb-linear 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: SrgbLinear , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1642
+ ( "color(display-p3 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: DisplayP3 , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1643
+ ( "color(a98-rgb 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: A98Rgb , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1644
+ ( "color(prophoto-rgb 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: ProphotoRgb , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1645
+ ( "color(rec2020 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: Rec2020 , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1646
+ ( "color(xyz-d50 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: XyzD50 , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1647
+ ( "color(xyz-d65 0.1 0.2 0.3 / 0.4)" , OutputType :: ColorFunction ( PredefinedColorSpace :: XyzD65 , Some ( 0.1 ) , Some ( 0.2 ) , Some ( 0.3 ) , Some ( 0.4 ) ) ) ,
1739
1648
] ;
1740
1649
1741
1650
for ( input, expected) in TESTS {
0 commit comments