PackageVersion: Implement other ordering ops; test them all

parent bc24a8c5
......@@ -39,18 +39,27 @@ public:
return this->_revision;
}
friend bool operator<(const PackageVersion &left, const PackageVersion &right) {
friend inline bool operator< (const PackageVersion &left, const PackageVersion &right) {
assert(false); // NYI
return false;
}
friend bool operator>(const PackageVersion &left, const PackageVersion &right) { return right < left; }
friend inline bool operator> (const PackageVersion &left, const PackageVersion &right) { return right < left; }
friend inline bool operator<=(const PackageVersion &left, const PackageVersion &right) { return !(left > right); }
friend inline bool operator>=(const PackageVersion &left, const PackageVersion &right) { return !(left < right); }
bool compare(const PackageVersion &other, bool fuzzy = false) {
bool compare(const PackageVersion &other, bool fuzzy = false) const {
if(!fuzzy) return (this->_version == other._version && this->_revision == other._revision);
assert(false); // NYI
return false;
}
friend inline bool operator==(const PackageVersion &left, const PackageVersion& right) {
return left.compare(right);
}
friend inline bool operator!=(const PackageVersion& left, const PackageVersion& right) {
return !(left == right);
}
bool operator==(const PackageVersion& other) { return this->compare(other); }
private:
string _version;
......
......@@ -26,8 +26,56 @@ void test_packageversions()
assert(multirev.revision() == 4);
}
void test_equality() {
PackageVersion onepoint0("1.0");
PackageVersion onepoint0r0("1.0-r0");
assert(onepoint0 == onepoint0r0);
PackageVersion onepoint0r1("1.0-r1");
PackageVersion onepoint1r0("1.1-r0");
assert(onepoint0 != onepoint0r1);
assert(onepoint0r0 != onepoint0r1);
assert(onepoint0r0 != onepoint1r0);
}
void test_ordering() {
// Taken from APKBUILD.5 manpage
PackageVersion first("1.0-r0");
PackageVersion second("1.1_alpha2-r1");
PackageVersion third("1.1.3_pre-r2");
PackageVersion fourth("1.1.3-r0");
PackageVersion fifth("1.1.3_hg-r0");
PackageVersion sixth("1.2-r0");
PackageVersion seventh("1.2a-r0");
PackageVersion eighth("1.2b-r0");
PackageVersion ninth("1.2c_alpha2-r0");
PackageVersion tenth("1.3-r0");
assert(first < second);
assert(second < third);
assert(third < fourth);
assert(fourth < fifth);
assert(fifth < sixth);
assert(sixth < seventh);
assert(seventh < eighth);
assert(eighth < ninth);
assert(ninth < tenth);
/* since other ops are based on <, just ensure basics work as sanity test */
assert(eighth <= ninth);
assert(ninth <= ninth);
assert(tenth > ninth);
assert(ninth >= eighth);
assert(eighth > seventh);
}
int main(void)
{
test_packageversions();
test_equality();
test_ordering();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment