Merge remote-tracking branch 'malu/semantic-versioning'

db4
John Benediktsson 2011-08-26 20:48:18 -07:00
commit 6a085abd7d
4 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1 @@
Maximilian Lupke

View File

@ -0,0 +1,55 @@
! Copyright (C) 2010 Maximilian Lupke.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays help.markup help.syntax kernel strings ;
IN: semantic-versioning
HELP: split-version
{ $values
{ "string" string }
{ "array" array }
}
{ $description "Splits the version string into a sequnece of major version, minor version, patch level and an alphanumeric identifier if given. See " { $url "http://semver.org/" } " for a detailed description." } ;
HELP: version<
{ $values
{ "version1" string } { "version2" string }
{ "?" boolean }
} ;
HELP: version<=
{ $values
{ "version1" string } { "version2" string }
{ "?" boolean }
} ;
HELP: version<=>
{ $values
{ "version1" string } { "version2" string }
{ "<=>" string }
} ;
HELP: version=
{ $values
{ "version1" string } { "version2" string }
{ "?" boolean }
} ;
HELP: version>
{ $values
{ "version1" string } { "version2" string }
{ "?" boolean }
} ;
HELP: version>=
{ $values
{ "version1" string } { "version2" string }
{ "?" boolean }
} ;
ARTICLE: { "Versioning" "Semantic Versioning" } "Semantic Versioning"
{ $vocab-link "semantic-versioning" }
$nl
{ "See " { $url "http://semver.org/" } " for a detailed description of semantic versioning." }
;
ABOUT: { "Versioning" "Semantic Versioning" }

View File

@ -0,0 +1,10 @@
USING: math.order semantic-versioning tools.test ;
IN: semantic-versioning.tests
[ { 1 0 0 "dev1" } ] [ "1.0.0dev1" split-version ] unit-test
[ { 1 2 3 } ] [ "1.2.3" split-version ] unit-test
[ +gt+ ] [ "1.2.0dev1" "0.12.1dev2" version<=> ] unit-test
[ +eq+ ] [ "2.0.0rc1" "2.0.0rc1" version<=> ] unit-test
[ +lt+ ] [ "1.0.0rc1" "1.0.0" version<=> ] unit-test
[ +lt+ ] [ "1.0.0rc1" "1.0.0rc2" version<=> ] unit-test

View File

@ -0,0 +1,31 @@
! Copyright (C) 2010 Maximilian Lupke.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays ascii kernel math.order math.parser sequences splitting
;
IN: semantic-versioning
: split-version ( string -- array )
"." split first3 dup [ digit? not ] find
[ cut [ [ string>number ] tri@ ] dip 4array ]
[ drop [ string>number ] tri@ 3array ]
if ;
: version<=> ( version1 version2 -- <=> )
[ split-version ] bi@ drop-prefix
2dup [ length 0 = ] either?
[ [ length ] bi@ >=< ] [ [ first ] bi@ <=> ] if ;
: version< ( version1 version2 -- ? )
version<=> +lt+ = ;
: version<= ( version1 version2 -- ? )
version<=> [ +lt+ = ] [ +eq+ = ] either? ;
: version= ( version1 version2 -- ? )
version<=> +eq+ = ;
: version>= ( version1 version2 -- ? )
version<=> [ +gt+ = ] [ +eq+ = ] either? ;
: version> ( version1 version2 -- ? )
version<=> +gt+ = ;