From 5e18fc55e82405b4af622391c99fa449c15e8fc8 Mon Sep 17 00:00:00 2001 From: Martin Bodin Date: Thu, 30 Nov 2023 15:15:49 +0100 Subject: [PATCH] Adding tests for fill-opacity. --- syntax/attribute_value.ml | 3 ++- test/test_jsx.re | 10 ++++++++++ test/test_ppx.ml | 10 +++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/syntax/attribute_value.ml b/syntax/attribute_value.ml index 52b6554cb..84d4c2d6c 100644 --- a/syntax/attribute_value.ml +++ b/syntax/attribute_value.ml @@ -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 diff --git a/test/test_jsx.re b/test/test_jsx.re index 18a5d4a7c..37283c243 100644 --- a/test/test_jsx.re +++ b/test/test_jsx.re @@ -331,6 +331,16 @@ let svg = ( ), ], ), + ( + "fill_opacity float, circle", + [], + [circle(~a=[a_cx (1., None); a_cy (2., None); a_r (3., None); a_fill_opacity 0.5], [])], + ), + ( + "fill_opacity percentage, rect", + [], + [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", [], diff --git a/test/test_ppx.ml b/test/test_ppx.ml index 23401b064..58251b95c 100644 --- a/test/test_ppx.ml +++ b/test/test_ppx.ml @@ -416,9 +416,13 @@ let svg = "svg", SvgTests.make Svg.[ [[%svg ""]], [animate ~a:[a_animation_fill `Freeze; a_animation_values ["1"; "2"]] []] ; - "fill_opacity, circle", - [[%svg ""]], - [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 ~a:[a_cx (1., None); a_cy (2., None); a_r (3., None); a_fill_opacity 0.5] []] ; + + "fill_opacity percentage, rect", + [[%svg ""]], + [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 ""]],