aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-11 09:38:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-11 09:38:46 +0000
commiteb899af3049fb5df96dc2305f892a4854d2bd099 (patch)
tree5c9931c887333c83d83d47a54c21376a2a7f409d
parent7c7bdc34e2867447ba0188f2597890a1f93ff892 (diff)
downloadpaludis-eb899af3049fb5df96dc2305f892a4854d2bd099.tar.gz
paludis-eb899af3049fb5df96dc2305f892a4854d2bd099.tar.xz
Add ~> operator support.
-rw-r--r--paludis/version_operator.cc26
-rw-r--r--paludis/version_operator.hh1
-rw-r--r--paludis/version_operator_TEST.cc2
-rw-r--r--paludis/version_spec.cc37
-rw-r--r--paludis/version_spec.hh21
-rw-r--r--paludis/version_spec_TEST.cc35
6 files changed, 111 insertions, 11 deletions
diff --git a/paludis/version_operator.cc b/paludis/version_operator.cc
index 199c903..74cd58d 100644
--- a/paludis/version_operator.cc
+++ b/paludis/version_operator.cc
@@ -60,6 +60,12 @@ VersionOperator::_decode(const std::string & v)
case '<':
return vo_less_equal;
}
+ else if ('>' == v[1])
+ switch (v[0])
+ {
+ case '~':
+ return vo_tilde_greater;
+ }
}
throw BadVersionOperatorError(v);
@@ -100,6 +106,10 @@ paludis::operator<< (std::ostream & s, const VersionOperator & v)
s << "=*";
continue;
+ case vo_tilde_greater:
+ s << "~>";
+ continue;
+
case last_vo:
break;
}
@@ -116,19 +126,21 @@ bool (VersionSpec::* VersionOperator::as_version_spec_operator() const)(const Ve
switch (_v)
{
case vo_less:
- return &VersionSpec::operator< ;
+ return &VersionSpec::operator<;
case vo_less_equal:
- return &VersionSpec::operator<= ;
+ return &VersionSpec::operator<=;
case vo_equal:
- return &VersionSpec::operator== ;
+ return &VersionSpec::operator==;
case vo_tilde:
- return &VersionSpec::tilde_compare ;
+ return &VersionSpec::tilde_compare;
case vo_greater:
- return &VersionSpec::operator> ;
+ return &VersionSpec::operator>;
case vo_greater_equal:
- return &VersionSpec::operator>= ;
+ return &VersionSpec::operator>=;
case vo_equal_star:
- return &VersionSpec::equal_star_compare ;
+ return &VersionSpec::equal_star_compare;
+ case vo_tilde_greater:
+ return &VersionSpec::tilde_greater_compare;
case last_vo:
break;
}
diff --git a/paludis/version_operator.hh b/paludis/version_operator.hh
index ca668b7..49588e0 100644
--- a/paludis/version_operator.hh
+++ b/paludis/version_operator.hh
@@ -50,6 +50,7 @@ namespace paludis
vo_greater, ///< > dependency
vo_greater_equal, ///< >= dependency
vo_equal_star, ///< =* dependency
+ vo_tilde_greater, ///< ~> dependency (gems)
last_vo ///< number of items
};
diff --git a/paludis/version_operator_TEST.cc b/paludis/version_operator_TEST.cc
index dfbe27a..991d919 100644
--- a/paludis/version_operator_TEST.cc
+++ b/paludis/version_operator_TEST.cc
@@ -88,6 +88,7 @@ namespace test_cases
TEST_CHECK_EQUAL(VersionOperator("~"), VersionOperator(vo_tilde));
TEST_CHECK_EQUAL(VersionOperator(">"), VersionOperator(vo_greater));
TEST_CHECK_EQUAL(VersionOperator(">="), VersionOperator(vo_greater_equal));
+ TEST_CHECK_EQUAL(VersionOperator("~>"), VersionOperator(vo_tilde_greater));
}
} test_version_operator_from_string;
@@ -104,6 +105,7 @@ namespace test_cases
TEST_CHECK_EQUAL(stringify(VersionOperator(vo_greater)), ">");
TEST_CHECK_EQUAL(stringify(VersionOperator(vo_equal)), "=");
TEST_CHECK_EQUAL(stringify(VersionOperator(vo_tilde)), "~");
+ TEST_CHECK_EQUAL(stringify(VersionOperator(vo_tilde_greater)), "~>");
}
} test_version_operator_to_string;
}
diff --git a/paludis/version_spec.cc b/paludis/version_spec.cc
index 2cf307f..ba4caa3 100644
--- a/paludis/version_spec.cc
+++ b/paludis/version_spec.cc
@@ -388,7 +388,8 @@ namespace
* \ingroup grpversions
*/
template <PartKind p_>
- struct IsPart
+ struct IsPart :
+ std::unary_function<Part, bool>
{
bool operator() (const Part & p) const
{
@@ -479,3 +480,37 @@ VersionSpec::is_scm() const
return result;
}
+VersionSpec
+VersionSpec::bump() const
+{
+ std::vector<Part> number_parts;
+ std::copy(_imp->parts.begin(),
+ std::find_if(_imp->parts.begin(), _imp->parts.end(), std::not1(IsPart<number>())),
+ std::back_inserter(number_parts));
+
+ if (number_parts.empty())
+ return *this;
+ if (number_parts.size() > 1)
+ number_parts.pop_back();
+ if (! number_parts.empty())
+ ++number_parts.back().value;
+
+ bool need_dot(false);
+ std::string str;
+ for (std::vector<Part>::const_iterator r(number_parts.begin()), r_end(number_parts.end()) ;
+ r != r_end ; ++r)
+ {
+ if (need_dot)
+ str.append(".");
+ str.append(stringify(r->value));
+ need_dot = true;
+ }
+ return VersionSpec(str);
+}
+
+bool
+VersionSpec::tilde_greater_compare(const VersionSpec & v) const
+{
+ return operator>= (v) && operator< (v.bump());
+}
+
diff --git a/paludis/version_spec.hh b/paludis/version_spec.hh
index 91e673f..1aab313 100644
--- a/paludis/version_spec.hh
+++ b/paludis/version_spec.hh
@@ -56,9 +56,10 @@ namespace paludis
*
* \ingroup grpversions
*/
- class VersionSpec : private PrivateImplementationPattern<VersionSpec>,
- public ComparisonPolicy<VersionSpec, comparison_mode::FullComparisonTag,
- comparison_method::CompareByMemberComparisonFunctionTag>
+ class VersionSpec :
+ private PrivateImplementationPattern<VersionSpec>,
+ public ComparisonPolicy<VersionSpec, comparison_mode::FullComparisonTag,
+ comparison_method::CompareByMemberComparisonFunctionTag>
{
friend std::ostream & operator<< (std::ostream &, const VersionSpec &);
@@ -95,6 +96,11 @@ namespace paludis
bool tilde_compare(const VersionSpec & other) const;
/**
+ * Comparison function for ~> depend operator (gems).
+ */
+ bool tilde_greater_compare(const VersionSpec & other) const;
+
+ /**
* Comparison function for =* depend operator.
*/
bool equal_star_compare(const VersionSpec & other) const;
@@ -116,6 +122,15 @@ namespace paludis
std::string revision_only() const;
/**
+ * Bump ourself.
+ *
+ * This is used by the ~> operator. It returns a version where the
+ * next to last number is one greater (e.g. 5.3.1 => 5.4). Any non
+ * number parts are stripped (e.g. 1.2.3_alpha4-r5 => 1.3).
+ */
+ VersionSpec bump() const;
+
+ /**
* Are we an -scm package, or something pretending to be one?
*/
bool is_scm() const;
diff --git a/paludis/version_spec_TEST.cc b/paludis/version_spec_TEST.cc
index 3b5ff22..d49c4ff 100644
--- a/paludis/version_spec_TEST.cc
+++ b/paludis/version_spec_TEST.cc
@@ -153,6 +153,23 @@ namespace test_cases
} test_version_spec_tilde_compare;
/**
+ * \test VersionSpec tilde greater comparisons
+ *
+ */
+ struct VersionSpecTildeGreaterCompareTest : TestCase
+ {
+ VersionSpecTildeGreaterCompareTest() : TestCase("version spec tilde greater compare") {}
+
+ void run()
+ {
+ TEST_CHECK(VersionSpec("1.2").tilde_greater_compare(VersionSpec("1.2")));
+ TEST_CHECK(VersionSpec("1.2.1").tilde_greater_compare(VersionSpec("1.2")));
+ TEST_CHECK(! VersionSpec("1.1").tilde_greater_compare(VersionSpec("1.2")));
+ TEST_CHECK(! VersionSpec("2.0").tilde_greater_compare(VersionSpec("1.2")));
+ }
+ } test_version_spec_tilde_greater_compare;
+
+ /**
* \test VersionSpec remove revision
*
*/
@@ -169,6 +186,24 @@ namespace test_cases
} test_version_remove_revision;
/**
+ * \test VersionSpec bump
+ *
+ */
+ struct VersionBumpTest : TestCase
+ {
+ VersionBumpTest() : TestCase("version spec bump") {}
+
+ void run()
+ {
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("1.2").bump(), "2");
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("1.2-r99").bump(), "2");
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("1.2.3").bump(), "1.3");
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("1").bump(), "2");
+ TEST_CHECK_STRINGIFY_EQUAL(VersionSpec("scm").bump(), "scm");
+ }
+ } test_version_bump;
+
+ /**
* \test VersionSpec revision only
*
*/