aboutsummaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/confTest/confTest.cpp4
-rw-r--r--tests/src/versionTest.cpp112
2 files changed, 114 insertions, 2 deletions
diff --git a/tests/src/confTest/confTest.cpp b/tests/src/confTest/confTest.cpp
index 8dab691..a86dbb3 100644
--- a/tests/src/confTest/confTest.cpp
+++ b/tests/src/confTest/confTest.cpp
@@ -26,11 +26,11 @@ TEST_CASE("parse config")
}
auto *xxhashDependency = sibsConfig.getPackageListDependencies()[0]->asPackageListDependency();
REQUIRE(xxhashDependency->name == "xxhash");
- REQUIRE(xxhashDependency->version == "0.1.0");
+ REQUIRE(xxhashDependency->version.toString() == ">=0.1.0");
const auto &catch2Dependency = sibsConfig.getPackageListDependencies()[1]->asPackageListDependency();
REQUIRE(catch2Dependency->name == "catch2");
- REQUIRE(catch2Dependency->version == "1.0.0");
+ REQUIRE(catch2Dependency->version.toString() == ">=1.0.0");
REQUIRE(sibsConfig.getGitDependencies().size() == 1);
for(auto *dep : sibsConfig.getGitDependencies())
diff --git a/tests/src/versionTest.cpp b/tests/src/versionTest.cpp
new file mode 100644
index 0000000..d5a492c
--- /dev/null
+++ b/tests/src/versionTest.cpp
@@ -0,0 +1,112 @@
+#include <catch.hpp>
+#include "../../include/VersionParser.hpp"
+
+using namespace sibs;
+
+TEST_CASE("parse package version")
+{
+ VersionParser parser;
+ {
+ Result<PackageVersionRange> parseResult = parser.parse("2.3.4", 5);
+ if(!parseResult)
+ FAIL(parseResult.getErrMsg());
+ PackageVersionRange versionRange = parseResult.unwrap();
+ REQUIRE(versionRange.startDefined);
+ REQUIRE(!versionRange.endDefined);
+ REQUIRE(versionRange.startOperation == VersionOperation::GREATER_EQUAL);
+ REQUIRE(versionRange.start.major == 2);
+ REQUIRE(versionRange.start.minor == 3);
+ REQUIRE(versionRange.start.patch == 4);
+ }
+ {
+ Result<PackageVersionRange> parseResult = parser.parse("2.3", 3);
+ if(!parseResult)
+ FAIL(parseResult.getErrMsg());
+ PackageVersionRange versionRange = parseResult.unwrap();
+ REQUIRE(versionRange.startDefined);
+ REQUIRE(!versionRange.endDefined);
+ REQUIRE(versionRange.startOperation == VersionOperation::GREATER_EQUAL);
+ REQUIRE(versionRange.start.major == 2);
+ REQUIRE(versionRange.start.minor == 3);
+ REQUIRE(versionRange.start.patch == 0);
+ }
+ {
+ Result<PackageVersionRange> parseResult = parser.parse("2", 1);
+ if(!parseResult)
+ FAIL(parseResult.getErrMsg());
+ PackageVersionRange versionRange = parseResult.unwrap();
+ REQUIRE(versionRange.startDefined);
+ REQUIRE(!versionRange.endDefined);
+ REQUIRE(versionRange.startOperation == VersionOperation::GREATER_EQUAL);
+ REQUIRE(versionRange.start.major == 2);
+ REQUIRE(versionRange.start.minor == 0);
+ REQUIRE(versionRange.start.patch == 0);
+ }
+ {
+ Result<PackageVersionRange> parseResult = parser.parse(">=2.3.4 and <5.6.7", 18);
+ if(!parseResult)
+ FAIL(parseResult.getErrMsg());
+ PackageVersionRange versionRange = parseResult.unwrap();
+ REQUIRE(versionRange.startDefined);
+ REQUIRE(versionRange.endDefined);
+ REQUIRE(versionRange.startOperation == VersionOperation::GREATER_EQUAL);
+ REQUIRE(versionRange.start.major == 2);
+ REQUIRE(versionRange.start.minor == 3);
+ REQUIRE(versionRange.start.patch == 4);
+ REQUIRE(versionRange.endOperation == VersionOperation::LESS);
+ REQUIRE(versionRange.end.major == 5);
+ REQUIRE(versionRange.end.minor == 6);
+ REQUIRE(versionRange.end.patch == 7);
+ }
+ {
+ Result<PackageVersionRange> parseResult = parser.parse(">2.3.4 and <=5.6.7", 18);
+ if(!parseResult)
+ FAIL(parseResult.getErrMsg());
+ PackageVersionRange versionRange = parseResult.unwrap();
+ REQUIRE(versionRange.startDefined);
+ REQUIRE(versionRange.endDefined);
+ REQUIRE(versionRange.startOperation == VersionOperation::GREATER);
+ REQUIRE(versionRange.start.major == 2);
+ REQUIRE(versionRange.start.minor == 3);
+ REQUIRE(versionRange.start.patch == 4);
+ REQUIRE(versionRange.endOperation == VersionOperation::LESS_EQUAL);
+ REQUIRE(versionRange.end.major == 5);
+ REQUIRE(versionRange.end.minor == 6);
+ REQUIRE(versionRange.end.patch == 7);
+ }
+ {
+ Result<PackageVersionRange> parseResult = parser.parse(">2.3.4 and <=5", 14);
+ if(!parseResult)
+ FAIL(parseResult.getErrMsg());
+ PackageVersionRange versionRange = parseResult.unwrap();
+ REQUIRE(versionRange.startDefined);
+ REQUIRE(versionRange.endDefined);
+ REQUIRE(versionRange.startOperation == VersionOperation::GREATER);
+ REQUIRE(versionRange.start.major == 2);
+ REQUIRE(versionRange.start.minor == 3);
+ REQUIRE(versionRange.start.patch == 4);
+ REQUIRE(versionRange.endOperation == VersionOperation::LESS_EQUAL);
+ REQUIRE(versionRange.end.major == 5);
+ REQUIRE(versionRange.end.minor == 0);
+ REQUIRE(versionRange.end.patch == 0);
+ }
+ {
+ REQUIRE(!parser.parse("", 0));
+ REQUIRE(!parser.parse(" ", 1));
+ REQUIRE(!parser.parse("2", 2));
+ REQUIRE(!parser.parse(".", 1));
+ REQUIRE(!parser.parse(".2", 2));
+ REQUIRE(!parser.parse("<", 1));
+ REQUIRE(!parser.parse("and", 3));
+ REQUIRE(!parser.parse("2 and", 5));
+ REQUIRE(!parser.parse("2 and 3", 7));
+ REQUIRE(!parser.parse("2 and =3", 8));
+ REQUIRE(!parser.parse("2 and >3", 8));
+ REQUIRE(!parser.parse(">=1.0.0 and 2.0.0", 17));
+ REQUIRE(!parser.parse("1.0.0 < 2.0.0", 13));
+ REQUIRE(!parser.parse("1.0.0 and <0.9.3", 16));
+ REQUIRE(!parser.parse("=1.0.0 and <2.0.0", 17));
+ REQUIRE(!parser.parse("1.0.0 and <2.0.0", 16));
+ REQUIRE(!parser.parse(">=1.0.0 and =2.0.0", 18));
+ }
+}