Skip to content

Commit

Permalink
Minor docstring fixes and testcase additions.
Browse files Browse the repository at this point in the history
Signed-off-by: Nashwan Azhari <[email protected]>
  • Loading branch information
aznashwan committed Jul 8, 2024
1 parent 4c30e1f commit cfab297
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
16 changes: 10 additions & 6 deletions src/gleamsver.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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
/// ```
Expand Down
67 changes: 63 additions & 4 deletions test/gleamsver_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -694,6 +735,7 @@ const compare_pre_release_strings_testcases = [
"alpha.8.123",
order.Gt,
),

// String parts should be compared lexicographically:
#(
"alpha.abc",
Expand Down Expand Up @@ -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", ""),
Expand Down

0 comments on commit cfab297

Please sign in to comment.