From 4e7b10de922d5dd01311291cde2fad64afaae35e Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Fri, 14 Jun 2024 16:15:48 -0500 Subject: [PATCH] Add Tests for Parsing Versions with Whitespace --- src/AppInstallerCLITests/Versions.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/AppInstallerCLITests/Versions.cpp b/src/AppInstallerCLITests/Versions.cpp index 740788b7bf..0e214f6864 100644 --- a/src/AppInstallerCLITests/Versions.cpp +++ b/src/AppInstallerCLITests/Versions.cpp @@ -43,6 +43,19 @@ TEST_CASE("VersionParsePlusDash", "[versions]") REQUIRE(parts[4].Other == "alpha"); } +TEST_CASE("VersionParseWithWhitespace", "[versions]") +{ + Version version("1. 2.3 . 4 "); + const auto& parts = version.GetParts(); + REQUIRE(parts.size() == 4); + for (size_t i = 0; i < parts.size(); ++i) + { + INFO(i); + REQUIRE(parts[i].Integer == static_cast(i + 1)); + REQUIRE(parts[i].Other == ""); + } +} + TEST_CASE("VersionParseCorner", "[versions]") { Version version1(""); @@ -70,6 +83,14 @@ TEST_CASE("VersionParseCorner", "[versions]") REQUIRE(parts.size() == 1); REQUIRE(parts[0].Integer == 0); REQUIRE(parts[0].Other == "version"); + + Version version6(". 1 "); + parts = version6.GetParts(); + REQUIRE(parts.size() == 2); + REQUIRE(parts[0].Integer == 0); + REQUIRE(parts[0].Other == ""); + REQUIRE(parts[1].Integer == 1); + REQUIRE(parts[1].Other == ""); } void RequireLessThan(std::string_view a, std::string_view b) @@ -113,6 +134,9 @@ TEST_CASE("VersionCompare", "[versions]") RequireLessThan("13.9.8", "14.1"); RequireEqual("1.0", "1.0.0"); + // Ensure whitespace doesn't affect equality + RequireEqual("1.0", "1.0 "); + RequireEqual("1.0", "1. 0"); } TEST_CASE("VersionAndChannelSort", "[versions]")