semantic-versioning: upgrade to Semantic Versioning 2.0.0.
Note: the parser is purposefully forgiving to handle more cases than the specification allows.db4
parent
7ed9365c00
commit
896d3fc460
|
@ -3,13 +3,6 @@
|
|||
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 }
|
||||
|
|
|
@ -1,10 +1,48 @@
|
|||
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
|
||||
{
|
||||
{
|
||||
T{ version f 0 1 0 "" "" }
|
||||
T{ version f 0 97 0 "" "" }
|
||||
T{ version f 1 1 0 "" "" }
|
||||
T{ version f 1 2 3 "" "" }
|
||||
T{ version f 1 0 0 "dev1" "" }
|
||||
T{ version f 1 0 0 "rc1" "build" }
|
||||
T{ version f 1 0 0 "rc2" "" }
|
||||
T{ version f 1 0 0 "rc2" "123456" }
|
||||
}
|
||||
} [
|
||||
{
|
||||
".1"
|
||||
"0.97"
|
||||
"1.1"
|
||||
"1.2.3"
|
||||
"1.0.0dev1"
|
||||
"1.0.0rc1+build"
|
||||
"1.0.0-rc2"
|
||||
"1.0.0-rc2+123456"
|
||||
} [ string>version ] map
|
||||
] 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
|
||||
{ +gt+ } [ "1.2.0dev1" "0.12.1dev2" version<=> ] unit-test
|
||||
{ +lt+ } [ "1.9.0" "1.10.0" 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
|
||||
{ +lt+ } [ "1.0.0-rc.1" "1.0.0-rc.11" version<=> ] unit-test
|
||||
{ +lt+ } [ "1.0.0-rc.2" "1.0.0-rc.11" version<=> ] unit-test
|
||||
{ +eq+ } [ "1.0.0+foo" "1.0.0+bar" version<=> ] unit-test
|
||||
|
||||
{ t } [
|
||||
{
|
||||
"1.0.0-alpha"
|
||||
"1.0.0-alpha.1"
|
||||
"1.0.0-alpha.beta"
|
||||
"1.0.0-beta"
|
||||
"1.0.0-beta.2"
|
||||
"1.0.0-beta.11"
|
||||
"1.0.0-rc.1"
|
||||
"1.0.0"
|
||||
} dup clone randomize [ version<=> ] sort =
|
||||
] unit-test
|
||||
|
|
|
@ -1,19 +1,38 @@
|
|||
! Copyright (C) 2010 Maximilian Lupke.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays ascii kernel math.order math.parser sequences splitting
|
||||
;
|
||||
USING: accessors arrays ascii kernel math.order math.parser
|
||||
sequences sorting.human sorting.slots 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 ;
|
||||
<PRIVATE
|
||||
|
||||
: pre-release<=> ( obj1 obj2 -- <=> )
|
||||
2dup [ empty? ] either?
|
||||
[ [ length ] bi@ >=< ] [ human<=> ] if ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
TUPLE: version major minor patch pre-release build ;
|
||||
|
||||
C: <version> version
|
||||
|
||||
M: version <=>
|
||||
{
|
||||
{ major>> <=> }
|
||||
{ minor>> <=> }
|
||||
{ patch>> <=> }
|
||||
{ pre-release>> pre-release<=> }
|
||||
} compare-slots ;
|
||||
|
||||
: string>version ( string -- version )
|
||||
"." split1 "." split1 dup [ digit? not ] find
|
||||
[ [ cut ] [ CHAR: - = [ rest ] when ] bi* ] [ drop "" ] if*
|
||||
[ [ string>number 0 or ] tri@ ] dip
|
||||
CHAR: + over index [ cut rest ] [ "" ] if*
|
||||
<version> ;
|
||||
|
||||
: version<=> ( version1 version2 -- <=> )
|
||||
[ split-version ] bi@ drop-prefix
|
||||
2dup [ length 0 = ] either?
|
||||
[ [ length ] bi@ >=< ] [ [ first ] compare ] if ;
|
||||
[ string>version ] bi@ <=> ;
|
||||
|
||||
: version< ( version1 version2 -- ? )
|
||||
version<=> +lt+ = ;
|
||||
|
|
Loading…
Reference in New Issue