From cfab297bd4890d1014f4c8629ce9f364fa35a24f Mon Sep 17 00:00:00 2001 From: Nashwan Azhari Date: Mon, 8 Jul 2024 12:48:26 +0300 Subject: [PATCH] Minor docstring fixes and testcase additions. Signed-off-by: Nashwan Azhari --- gleam.toml | 2 +- src/gleamsver.gleam | 16 ++++++---- test/gleamsver_test.gleam | 67 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/gleam.toml b/gleam.toml index 6665f49..f17eb66 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "gleamsver" -version = "1.0.0" +version = "1.0.1" description = "Comprehensive set of native Gleam utilities for handling SemVer 2.0.0 version strings." licences = ["MIT"] diff --git a/src/gleamsver.gleam b/src/gleamsver.gleam index 3b20313..ad53ed9 100644 --- a/src/gleamsver.gleam +++ b/src/gleamsver.gleam @@ -89,7 +89,7 @@ pub const empty_semver = SemVer(0, 0, 0, "", "") /// // -> Ok(SemVer(major: 1, minor; 2, patch: 3, pre: "rc0", build: "20240505")) /// ``` /// -/// Both the Pre-release ("-rc0") and Build ("+20240505") parts are optional: +/// Both the Pre-release (`-rc0`) and Build (`+20240505`) parts are optional: /// /// ```gleam /// parse("4.5.6-rc0") @@ -117,7 +117,7 @@ pub const empty_semver = SemVer(0, 0, 0, "", "") /// /// ```gleam /// parse("abc") -/// -> MissingMajor("Leading Major SemVer Integer part is missing.") +/// // -> MissingMajor("Leading Major SemVer Integer part is missing.") /// // To get the error String directly, simply: /// parse("abc") |> result.map_error(string_from_parsing_error) /// // -> Error("Leading Major SemVer Integer part is missing.") @@ -390,7 +390,7 @@ pub fn are_compatible(v1: SemVer, with v2: SemVer) -> Bool { /// /// ## Examples /// -/// ```gleams +/// ```gleam /// are_equal_core(SemVer(1, 2, 3, "", ""), with: SemVer(1, 2, 3, "", "")) /// // -> True /// @@ -742,11 +742,15 @@ fn process_split( /// compare_pre_release_strings("12.thing.A", "12.thing.B") /// // -> Lt /// -/// // NOTE: 'A' comes before 'b' in the ASCII table: -/// compare_pre_release_strings("12.thing.A", "12.thing.b") +/// // NOTE: integer parts always have lower precedence over non-integer ones: +/// compare_pre_release_strings("12.thing.1", "12.thing.rc0") +/// // -> Lt +/// +/// // NOTE: 'B' comes before 'a' in the ASCII table: +/// compare_pre_release_strings("12.thing.B", "12.thing.a") /// // -> Lt /// -/// // NOTE: '0' comes before '6': +/// // NOTE: '0' comes before '6' in the ASCII table: /// compare_pre_release_strings("rc07", "rc6") /// // -> Lt /// ``` diff --git a/test/gleamsver_test.gleam b/test/gleamsver_test.gleam index 37e7d31..25b6297 100644 --- a/test/gleamsver_test.gleam +++ b/test/gleamsver_test.gleam @@ -652,6 +652,13 @@ const compare_pre_release_strings_testcases = [ "", order.Eq, ), + #( + "rc0.123.7", + "rc0.123.7", + order.Eq, + ), + + // Empty tags should have higher precendence: #( "", "anything", @@ -663,10 +670,38 @@ const compare_pre_release_strings_testcases = [ order.Lt, ), #( - "rc0.123.7", - "rc0.123.7", - order.Eq, + "", + "7", + order.Gt, + ), + #( + "7", + "", + order.Lt, + ), + + // Integer tags should have lower precedence to non-Int ones: + #( + "123", + "rc0", + order.Lt, + ), + #( + "rc0", + "123", + order.Gt, ), + #( + "abc.123", + "abc.rc0", + order.Lt, + ), + #( + "abc.rc0", + "abc.123", + order.Gt, + ), + // Pre-release strings with more parts => higher. #( "alpha", @@ -678,6 +713,12 @@ const compare_pre_release_strings_testcases = [ "alpha.1", order.Gt, ), + #( + "alpha.1.1", + "alpha.2", + order.Lt, + ), + // Integer parts should be compared as Integers: #( "alpha.7", @@ -694,6 +735,7 @@ const compare_pre_release_strings_testcases = [ "alpha.8.123", order.Gt, ), + // String parts should be compared lexicographically: #( "alpha.abc", @@ -892,17 +934,34 @@ const compare_testcases = [ SemVer(1, 2, 3, "rc0.123", ""), order.Gt, ), - #( SemVer(1, 2, 3, "rc0.124", ""), SemVer(1, 2, 3, "rc1.123", ""), order.Lt, ), + #( SemVer(1, 2, 3, "rc07", ""), SemVer(1, 2, 3, "rc6", ""), order.Lt, ), + + #( + SemVer(1, 2, 3, "12.thing.1", ""), + SemVer(1, 2, 3, "12.thing.rc0", ""), + order.Lt, + ), + #( + SemVer(1, 2, 3, "12.thing.rc0", ""), + SemVer(1, 2, 3, "12.thing.1", ""), + order.Gt, + ), + + #( + SemVer(1, 2, 3, "12.thing.B", ""), + SemVer(1, 2, 3, "12.thing.a", ""), + order.Lt, + ), #( SemVer(1, 2, 3, "0.3.7", ""), SemVer(1, 2, 3, "0.3.7", ""),