@@ -74,24 +74,30 @@ TEST(Color, ConstructorProperties) {
7474
7575TEST (Color, FromStringValid) {
7676
77- const std::vector<std::tuple<std::string, Color>> valid_strings {
78- { " #FFAA33" , Color{ 0xFF , 0xAA , 0x33 }},
79- { " #FF00FF00" , Color{ 0xFF , 0x00 , 0xFF , 0x00 }},
80- { " rgb(0,0,0)" , Color{ 0 , 0 , 0 }},
81- { " rgba(0,0,0,0)" , Color{ 0 , 0 , 0 , 0 }},
82- { " hsv(0,0,0)" , HSVColor{ 0 , 0 , 0 }},
83- { " hsva(340,0,0.5,0)" , HSVColor{ 340 , 0 , 0.5 , 0 }},
84- { " #ffaa33" , Color{ 0xff , 0xaa , 0x33 }},
85- {" hsv(0, 0.00_000_000_1, 0)" , HSVColor{ 0 , 0.000000001 , 0 }},
86- { " hsva(0, 0, 0, 0xFF)" , HSVColor{ 0 , 0 , 0 , 0xFF }},
87- { " rgba(0, 0xFF, 0, 255)" , Color{ 0 , 0xFF , 0 , 255 }},
88- { " rgba(0, 0xFF, 0, 1_0_0)" , Color{ 0 , 0xFF , 0 , 100 }},
77+ const std::vector<std::tuple<std::string, Color::InfoType >> valid_values {
78+ { " #FFAA33" , { Color{ 0xFF , 0xAA , 0x33 }, color::SerializeMode::Hex, false }},
79+ { " #FF00FF00" , { Color{ 0xFF , 0x00 , 0xFF , 0x00 }, color::SerializeMode::Hex, true }},
80+ { " rgb(0,0,0)" , { Color{ 0 , 0 , 0 }, color::SerializeMode::RGB, false }},
81+ { " rgba(0,0,0,0)" , { Color{ 0 , 0 , 0 , 0 }, color::SerializeMode::RGB, true }},
82+ { " hsv(0,0,0)" , { HSVColor{ 0 , 0 , 0 }, color::SerializeMode::HSV, false }},
83+ { " hsva(340,0,0.5,0)" , { HSVColor{ 340 , 0 , 0.5 , 0 }, color::SerializeMode::HSV, true }},
84+ { " #ffaa33" , { Color{ 0xff , 0xaa , 0x33 }, color::SerializeMode::Hex, false }},
85+ {" hsv(0, 0.00_000_000_1, 0)" , { HSVColor{ 0 , 0.000000001 , 0 }, color::SerializeMode::HSV, false }},
86+ { " hsva(0, 0, 0, 0xFF)" , { HSVColor{ 0 , 0 , 0 , 0xFF }, color::SerializeMode::HSV, true }},
87+ { " rgba(0, 0xFF, 0, 255)" , { Color{ 0 , 0xFF , 0 , 255 }, color::SerializeMode::RGB, true }},
88+ { " rgba(0, 0xFF, 0, 1_0_0)" , { Color{ 0 , 0xFF , 0 , 100 }, color::SerializeMode::RGB, true }},
8989 };
9090
91- for (const auto & [valid_string, expected_color ] : valid_strings ) {
92- const auto result = Color::from_string (valid_string);
91+ for (const auto & [valid_string, expected_result ] : valid_values ) {
92+ const auto result = Color::from_string_with_info (valid_string);
9393 ASSERT_THAT (result, ExpectedHasValue ()) << " Input was: " << valid_string;
94- ASSERT_EQ (result.value (), expected_color) << " Input was: " << valid_string;
94+ ASSERT_EQ (result.value (), expected_result) << " Input was: " << valid_string;
95+
96+ const auto color_string = std::get<0 >(result.value ()).to_string (color::SerializeMode::Hex);
97+
98+ const auto converted_color = Color::from_string_with_info (color_string);
99+ ASSERT_THAT (converted_color, ExpectedHasValue ()) << " Input was: " << color_string;
100+ ASSERT_EQ (result.value (), expected_result) << " Input was: " << color_string;
95101 }
96102}
97103
@@ -103,6 +109,9 @@ TEST(Color, FromStringInvalid) {
103109 { " #Z" , " Unrecognized HEX literal" },
104110 { " #ZZFF" , " Unrecognized HEX literal" },
105111 { " u" , " Unrecognized color literal" },
112+ { " #IIFFFFFF" , " the input must be a valid hex character" },
113+ { " #FFIIFFFF" , " the input must be a valid hex character" },
114+ { " #FFFFIIFF" , " the input must be a valid hex character" },
106115 { " #FFFFFFII" , " the input must be a valid hex character" },
107116 { " #FFFF4T" , " the input must be a valid hex character" },
108117 { " #0000001" , " Unrecognized HEX literal" },
0 commit comments