add "version<=>"

db4
Maximilian Lupke 2010-02-22 21:23:43 +01:00
parent b969f35e01
commit 79e6738a07
2 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,10 @@
USING: semantic-versioning tools.test ;
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

@ -1,6 +1,7 @@
! Copyright (C) 2010 Maximilian Lupke.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays ascii kernel math.parser sequences splitting ;
USING: arrays ascii combinators kernel math.order math.parser
sequences splitting ;
IN: semantic-versioning
: split-version ( string -- array )
@ -8,3 +9,14 @@ IN: semantic-versioning
[ cut [ [ string>number ] tri@ ] dip 4array ]
[ drop [ string>number ] tri@ 3array ]
if ;
! okay, not beautiful
: version<=> ( version1 version2 -- <=> )
[ split-version ] bi@
{
{ [ [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
{ [ drop [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
{ [ drop [ unclip ] bi@ swapd <=> dup +eq+ = not ] [ 2nip ] }
{ [ drop 2dup [ length ] bi@ >=< dup +eq+ = not ] [ 2nip ] }
[ drop [ first ] bi@ <=> ]
} cond ;