Skip to content

Commit

Permalink
Adding tests for fill-opacity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mbodin committed Nov 30, 2023
1 parent 925474c commit 5e18fc5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion syntax/attribute_value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ let fill_opacity =
if group_matched 2 s then (n /. 100.)
else n in

if v >= 0. && v <= 1. then Some [%expr [%e v]]
if v >= 0. && v <= 1. then
Some [%expr [%e (Common.float loc @@ v)]]
else
Common.error loc "Value of %s must be between 0 and 1." name

Expand Down
10 changes: 10 additions & 0 deletions test/test_jsx.re
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ let svg = (
),
],
),
(
"fill_opacity float, circle",
[<circle cx=1 cy=2 r=3 fill-opacity=0.5 />],
[circle(~a=[a_cx (1., None); a_cy (2., None); a_r (3., None); a_fill_opacity 0.5], [])],
),
(
"fill_opacity percentage, rect",
[<rect x=1 y='2' width=3 height='4' fill-opacity='50%' />],
[rect(~a=[a_cx (1., None); a_cy (2., None); a_width (3., None); a_height (4., None); a_fill_opacity 0.5], [])],
),
(
"fill_rule nonzero",
[<path fill_rule="nonzero" />],
Expand Down
10 changes: 7 additions & 3 deletions test/test_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,13 @@ let svg = "svg", SvgTests.make Svg.[
[[%svg "<animate fill='freeze' values='1 2'/>"]],
[animate ~a:[a_animation_fill `Freeze; a_animation_values ["1"; "2"]] []] ;

"fill_opacity, circle",
[[%svg "<circle cx=50 cy=50 r=50 fill-opacity=0.5 />"]],
[rect ~a:[a_cx (50., None); a_cy (50., None); a_r (50., None); a_fill_opacity 0.5] []] ;
"fill_opacity float, circle",
[[%svg "<circle cx=1 cy=2 r=3 fill-opacity=0.5 />"]],
[circle ~a:[a_cx (1., None); a_cy (2., None); a_r (3., None); a_fill_opacity 0.5] []] ;

"fill_opacity percentage, rect",
[[%svg "<rect x=1 y='2' width=3 height='4' fill-opacity='50%' />"]],
[rect ~a:[a_cx (1., None); a_cy (2., None); a_width (3., None); a_height (4., None); a_fill_opacity 0.5] []] ;

"fill_rule type nonzero",
[[%svg "<path fill-rule='nonzero'/>"]],
Expand Down

0 comments on commit 5e18fc5

Please sign in to comment.