diff options
author | Treeston <treeston.mmoc@gmail.com> | 2020-09-02 22:04:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 22:04:45 +0200 |
commit | f45aa5cac1579e87cbc599ffb58e10e662066792 (patch) | |
tree | 250812f5a1608c21f3e04cbc460e8be0cece147c /tests/common/StringConvert.cpp | |
parent | eaf8fa75a1c76131ecbf2585db6d6236b7334b8e (diff) |
Common/Util: Trinity::StringTo<double> support (PR #25364)
Diffstat (limited to 'tests/common/StringConvert.cpp')
-rw-r--r-- | tests/common/StringConvert.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/common/StringConvert.cpp b/tests/common/StringConvert.cpp index d25e28f3d19..c1a6f5da7f8 100644 --- a/tests/common/StringConvert.cpp +++ b/tests/common/StringConvert.cpp @@ -119,7 +119,7 @@ TEST_CASE("String to smaller integer types", "[StringConvert]") REQUIRE(Trinity::StringTo<int16>("-1", 0) == -1); } -TEST_CASE("Test.String to boolean", "[StringConvert]") +TEST_CASE("String to boolean", "[StringConvert]") { REQUIRE(Trinity::StringTo<bool>("true") == true); REQUIRE(Trinity::StringTo<bool>("false") == false); @@ -129,3 +129,26 @@ TEST_CASE("Test.String to boolean", "[StringConvert]") REQUIRE(Trinity::StringTo<bool>("1", 10) == true); REQUIRE(Trinity::StringTo<bool>("0", 10) == false); } + +TEST_CASE("String to double", "[StringConvert]") +{ + using namespace Catch::literals; + REQUIRE(Trinity::StringTo<double>("0.5") == 0.5); + REQUIRE(Trinity::StringTo<double>("0.1") == 0.1_a); + REQUIRE(Trinity::StringTo<double>("1.2.3") == std::nullopt); + REQUIRE(Trinity::StringTo<double>("1e+5") == 100000.0); + REQUIRE(Trinity::StringTo<double>("1e+3+5") == std::nullopt); + REQUIRE(Trinity::StringTo<double>("a1.5") == std::nullopt); + REQUIRE(Trinity::StringTo<double>("1.5tail") == std::nullopt); + REQUIRE(Trinity::StringTo<double>("0x0") == 0.0); + REQUIRE(Trinity::StringTo<double>("0x0", 16) == std::nullopt); + REQUIRE(Trinity::StringTo<double>("0", 16) == 0.0); + REQUIRE(Trinity::StringTo<double>("0x1.BC70A3D70A3D7p+6") == 0x1.BC70A3D70A3D7p+6); + REQUIRE(Trinity::StringTo<double>("0x1.BC70A3D70A3D7p+6", 10) == std::nullopt); + REQUIRE(Trinity::StringTo<double>("0x1.BC70A3D70A3D7p+6", 16) == std::nullopt); + REQUIRE(Trinity::StringTo<double>("1.BC70A3D70A3D7p+6", 16) == 0x1.BC70A3D70A3D7p+6); + REQUIRE(Trinity::StringTo<double>("0x1.2.3") == std::nullopt); + REQUIRE(Trinity::StringTo<double>("0x1.AAAp+1-3") == std::nullopt); + REQUIRE(Trinity::StringTo<double>("1.2.3", 16) == std::nullopt); + REQUIRE(Trinity::StringTo<double>("1.AAAp+1-3", 16) == std::nullopt); +} |