Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Semantic Version Parsing: ~version #1160

Merged
merged 1 commit into from

3 participants

@simensen

Implemented according to #643 and used the following versions as a test case as defined by @Seldaek:

  • "~1.2.3.4" = ">=1.2.3.4 <1.2.4.0-dev"
  • "~1.2.3" = ">=1.2.3 <1.3.0-dev"
  • "~1.2" = ">=1.2.0 <2.0.0-dev"
  • "~1" = ">=1.0.0 <2.0.0-dev"

This was by no means done simply because I want to ask Composer to update to depend on Symfony ~2.1 components. Honest. :)

@simensen

Hm, maybe it doesn't close #643 entirely? :) I might have been too excited about that. :) But I added the ~ part. I am going to amend my commit to take the closes part out.

@stof

~1.2.3.4 should also be supported as Composer supports 4 level in the version number

src/Composer/Package/Version/VersionParser.php
@@ -238,6 +238,25 @@ private function parseConstraint($constraint)
return array();
}
+ if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?$}', $constraint, $matches)) {
+ if (isset($matches[3])) {
+ $highVersion = $matches[1] . '.' . ($matches[2] + 1) . '.0000000.0000000';
+ $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.0000000';
+ } else {
+ $highVersion = ($matches[1] + 1) . '.0000000.0000000.0000000';
+ if (isset($matches[2])) {
+ $lowVersion = $matches[1] . '.' . $matches[2] . '.0000000.0000000';
+ } else {
+ $lowVersion = $matches[1] . '.0000000.0000000.0000000';
@stof
stof added a note

use .0, not .000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@simensen

What would the constraints look like for ~1.2.3.4?

@simensen

I took a guess on what I figured ~1.2.3.4 would mean.

  • "~1.2.3.4" = ">=1.2.3.4 <1.2.4.0"

I also fixed the 0000000 bit. :-/

Thanks for catching these @stof!

...s/Composer/Test/Package/Version/VersionParserTest.php
((10 lines not shown))
+ if ($min) {
+ $expected = new MultiConstraint(array($min, $max));
+ } else {
+ $expected = $max;
+ }
+
+ $this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
+ }
+
+ public function tildeConstraints()
+ {
+ return array(
+ array('~1', new VersionConstraint('>=', '1.0.0.0'), new VersionConstraint('<', '2.0.0.0')),
+ array('~1.2', new VersionConstraint('>=', '1.2.0.0'), new VersionConstraint('<', '2.0.0.0')),
+ array('~1.2.3', new VersionConstraint('>=', '1.2.3.0'), new VersionConstraint('<', '1.3.0.0')),
+ array('~1.2.3.4', new VersionConstraint('>=', '1.2.3.4'), new VersionConstraint('<', '1.2.4.0')),
@Seldaek Owner
Seldaek added a note

Actually the < should be <anything-dev because 2.0.0.0-dev is smaller than 2.0.0.0 for example.

@simensen
simensen added a note

So how would the version constraint look?

@stof
stof added a note

new VersionConstraint('<', '1.2.4.0-dev'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@simensen

Updated to have the high number to include -dev.

@simensen simensen Semantic Version Parsing: ~version
Implemented `~` according to #643 and used the following versions
as a test case as defined by @Seldaek:

 * "~1.2.3.4" = ">=1.2.3.4 <1.2.4.0-dev"
 * "~1.2.3" = ">=1.2.3 <1.3.0-dev"
 * "~1.2" = ">=1.2.0 <2.0.0-dev"
 * "~1" = ">=1.0.0 <2.0.0-dev"

Refs #643
96a76ee
@simensen

Is this good to go now or does it still need some tweaking? I rebased a few days ago because I saw some other version parsing stuff going on and it looked like it was still clean at the time.

@Seldaek
Owner

It looks good yes thank you, but I'm putting it on hold for now because I need to do some work in packagist so that this stuff doesn't blow up every composer.phar out there at the first package that's using it.

@Seldaek Seldaek merged commit 96a76ee into composer:master
@Seldaek
Owner

Merged, thanks!

@simensen simensen deleted the simensen:sem-version-support branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 6, 2012
  1. @simensen

    Semantic Version Parsing: ~version

    simensen authored
    Implemented `~` according to #643 and used the following versions
    as a test case as defined by @Seldaek:
    
     * "~1.2.3.4" = ">=1.2.3.4 <1.2.4.0-dev"
     * "~1.2.3" = ">=1.2.3 <1.3.0-dev"
     * "~1.2" = ">=1.2.0 <2.0.0-dev"
     * "~1" = ">=1.0.0 <2.0.0-dev"
    
    Refs #643
This page is out of date. Refresh to see the latest.
View
22 src/Composer/Package/Version/VersionParser.php
@@ -245,6 +245,28 @@ private function parseConstraint($constraint)
return array();
}
+ if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?$}', $constraint, $matches)) {
+ if (isset($matches[4])) {
+ $highVersion = $matches[1] . '.' . $matches[2] . '.' . ($matches[3] + 1) . '.0-dev';
+ $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.' . $matches[4];
+ } elseif (isset($matches[3])) {
+ $highVersion = $matches[1] . '.' . ($matches[2] + 1) . '.0.0-dev';
+ $lowVersion = $matches[1] . '.' . $matches[2] . '.' . $matches[3]. '.0';
+ } else {
+ $highVersion = ($matches[1] + 1) . '.0.0.0-dev';
+ if (isset($matches[2])) {
+ $lowVersion = $matches[1] . '.' . $matches[2] . '.0.0';
+ } else {
+ $lowVersion = $matches[1] . '.0.0.0';
+ }
+ }
+
+ return array(
+ new VersionConstraint('>=', $lowVersion),
+ new VersionConstraint('<', $highVersion),
+ );
+ }
+
// match wildcard constraints
if (preg_match('{^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.[x*]$}', $constraint, $matches)) {
if (isset($matches[3])) {
View
25 tests/Composer/Test/Package/Version/VersionParserTest.php
@@ -240,6 +240,31 @@ public function wildcardConstraints()
);
}
+ /**
+ * @dataProvider tildeConstraints
+ */
+ public function testParseTildeWildcard($input, $min, $max)
+ {
+ $parser = new VersionParser;
+ if ($min) {
+ $expected = new MultiConstraint(array($min, $max));
+ } else {
+ $expected = $max;
+ }
+
+ $this->assertSame((string) $expected, (string) $parser->parseConstraints($input));
+ }
+
+ public function tildeConstraints()
+ {
+ return array(
+ array('~1', new VersionConstraint('>=', '1.0.0.0'), new VersionConstraint('<', '2.0.0.0-dev')),
+ array('~1.2', new VersionConstraint('>=', '1.2.0.0'), new VersionConstraint('<', '2.0.0.0-dev')),
+ array('~1.2.3', new VersionConstraint('>=', '1.2.3.0'), new VersionConstraint('<', '1.3.0.0-dev')),
+ array('~1.2.3.4', new VersionConstraint('>=', '1.2.3.4'), new VersionConstraint('<', '1.2.4.0-dev')),
+ );
+ }
+
public function testParseConstraintsMulti()
{
$parser = new VersionParser;
Something went wrong with that request. Please try again.