semver: fix semver-inc-patch, add some unit tests
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 25 Aug 2022 02:12:35 +0000 (22:12 -0400)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 25 Aug 2022 02:13:27 +0000 (22:13 -0400)
extra/semver/semver-tests.factor
extra/semver/semver.factor

index ce459ccb157695f2bc4c1bf8079a46cc561811e6..0e7effe575f8140579d75a31253a9e98f65501c7 100644 (file)
@@ -141,3 +141,14 @@ CONSTANT: semver-gt-comparisons {
     values [ +lt+ = ] all?
 ] unit-test
 
+{ "1.2.4-dev.0" } [ "1.2.3" <semver> semver-inc-prepatch semver>string ] unit-test
+{ "1.2.4" } [ "1.2.3" <semver> semver-inc-patch semver>string ] unit-test
+
+{ "1.3.0-dev.0" } [ "1.2.3" <semver> semver-inc-preminor semver>string ] unit-test
+{ "1.3.0" } [ "1.2.3" <semver> semver-inc-minor semver>string ] unit-test
+
+{ "2.0.0-dev.0" } [ "1.2.3" <semver> semver-inc-premajor semver>string ] unit-test
+{ "2.0.0-dev.1" } [ "1.2.3" <semver> semver-inc-premajor semver-inc-prerelease semver>string ] unit-test
+{ "2.0.0" } [ "1.2.3" <semver> semver-inc-major semver>string ] unit-test
+
+{ "1.2.3-erg.0" } [ "1.2.3" <semver> "erg" semver-inc-prerelease-id semver>string ] unit-test
index 6826136065a387bd9a90dca5c95d46aac0622d8b..92f3f998dd9d11926a80096eec689c79adaad392 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2020 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs combinators combinators.smart
+USING: accessors arrays assocs combinators combinators.smart io
 kernel math math.order math.parser multiline peg.ebnf sequences
 sequences.deep sequences.extras splitting strings ;
 IN: semver
@@ -32,6 +32,8 @@ TUPLE: semver
     [ "." split [ string>number ] map first3 ] 2dip
     semver boa ;
 
+: <semver> ( str -- semver ) parse-semver ; inline
+
 : first-semver-slot ( semver -- class )
     {
         { [ dup major>> 0 > ] [ drop major ] }
@@ -63,6 +65,9 @@ TUPLE: semver
         } cleave
     ] "" append-outputs-as ;
 
+: semver. ( semver -- )
+    semver>string print ;
+
 : semver-inc-major ( semver -- semver )
     dup prerelease>> [
         [ 1 + ] change-major
@@ -91,7 +96,6 @@ TUPLE: semver
 : semver-inc-patch ( semver -- semver )
     dup prerelease>> [
         [ 1 + ] change-patch
-        0 >>patch
         "" >>prerelease
         "" >>build
     ] [