-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
\ No newline at end of file
! 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 )
[ 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 ;