From 65f93ad6d5f9955b144bdde8eb3022460a3ad8f2 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Sat, 4 Jul 2020 18:46:23 -0400 Subject: [PATCH] builtin fns `red`, `green`, and `blue` round their output --- src/color/mod.rs | 6 +++--- tests/color.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/color/mod.rs b/src/color/mod.rs index e9c422b..b099013 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -151,15 +151,15 @@ impl Color { } pub fn red(&self) -> Number { - self.rgba.red.clone() + self.rgba.red.clone().round() } pub fn blue(&self) -> Number { - self.rgba.blue.clone() + self.rgba.blue.clone().round() } pub fn green(&self) -> Number { - self.rgba.green.clone() + self.rgba.green.clone().round() } /// Mix two colors together with weight diff --git a/tests/color.rs b/tests/color.rs index d5865d1..f29ec23 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -603,3 +603,23 @@ test!( "a {\n color: #00000000f00;\n}\n", "a {\n color: #00000000 f00;\n}\n" ); +test!( + all_three_rgb_channels_have_decimal, + "a {\n color: rgba(1.5, 1.5, 1.5, 1);\n}\n", + "a {\n color: #020202;\n}\n" +); +test!( + builtin_fn_red_rounds_channel, + "a {\n color: red(rgba(1.5, 1.5, 1.5, 1));\n}\n", + "a {\n color: 2;\n}\n" +); +test!( + builtin_fn_green_rounds_channel, + "a {\n color: green(rgba(1.5, 1.5, 1.5, 1));\n}\n", + "a {\n color: 2;\n}\n" +); +test!( + builtin_fn_blue_rounds_channel, + "a {\n color: blue(rgba(1.5, 1.5, 1.5, 1));\n}\n", + "a {\n color: 2;\n}\n" +);