[wpilib] Make Color::HexString() constexpr (#5985)

Related improvements to wpi::ct_string:
* Implicitly convert to std::string
* Add operator== for std::string, std::string_view, and const Char*
This commit is contained in:
Tyler Veness
2023-12-04 21:20:49 -08:00
committed by GitHub
parent 2676b77873
commit 90757b9e90
7 changed files with 105 additions and 36 deletions

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <string>
#include <gtest/gtest.h>
#include "frc/util/Color8Bit.h"
@@ -56,7 +58,12 @@ TEST(Color8BitTest, ImplicitConversionToColor) {
}
TEST(Color8BitTest, ToHexString) {
constexpr frc::Color8Bit color{255, 128, 64};
constexpr frc::Color8Bit color1{255, 128, 64};
EXPECT_EQ("#FF8040", color1.HexString());
EXPECT_EQ("#FF8040", color.HexString());
// Ensure conversion to std::string works
[[maybe_unused]] std::string str = color1.HexString();
frc::Color8Bit color2{255, 128, 64};
EXPECT_EQ("#FF8040", color2.HexString());
}

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <string>
#include <gtest/gtest.h>
#include "frc/util/Color.h"
@@ -56,7 +58,12 @@ TEST(ColorTest, FromHSV) {
}
TEST(ColorTest, ToHexString) {
constexpr frc::Color color{255, 128, 64};
constexpr frc::Color color1{255, 128, 64};
EXPECT_EQ("#FF8040", color1.HexString());
EXPECT_EQ("#FF8040", color.HexString());
// Ensure conversion to std::string works
[[maybe_unused]] std::string str = color1.HexString();
frc::Color color2{255, 128, 64};
EXPECT_EQ("#FF8040", color2.HexString());
}