aboutsummaryrefslogtreecommitdiff
path: root/tests/src/versionTest.cpp
blob: 307496f95d891d47fb707987df822b4a02b244b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <catch2/catch.hpp>
#include "../../include/VersionParser.hpp"

using namespace sibs;

TEST_CASE("parse package version")
{
    VersionParser parser;
    {
        Result<PackageVersionRange> parseResult = parser.parse("17.3.4", 6);
        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 == 17);
        REQUIRE(versionRange.start.minor == 3);
        REQUIRE(versionRange.start.patch == 4);
        REQUIRE(versionRange.endOperation == VersionOperation::LESS);
        REQUIRE(versionRange.end.major == 18);
        REQUIRE(versionRange.end.minor == 0);
        REQUIRE(versionRange.end.patch == 0);
    }
    {
        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);
        REQUIRE(versionRange.endOperation == VersionOperation::LESS);
        REQUIRE(versionRange.end.major == 3);
        REQUIRE(versionRange.end.minor == 0);
        REQUIRE(versionRange.end.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);
        REQUIRE(versionRange.endOperation == VersionOperation::LESS);
        REQUIRE(versionRange.end.major == 3);
        REQUIRE(versionRange.end.minor == 0);
        REQUIRE(versionRange.end.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));
    }
}