From 8a70adbde03ee9931dc4e1b6f31bd8635eb3633b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 20 Mar 2023 13:36:06 +0100 Subject: fix(vim.version): prerelease compare Problem: semver specifies that digit sequences in a prerelease string should be compared as numbers, not lexically: https://semver.org/#spec-item-11 > Precedence for two pre-release versions with the same major, minor, > and patch version MUST be determined by comparing each dot separated > identifier from left to right until a difference is found as follows: > 1. Identifiers consisting of only digits are compared numerically. > 2. Identifiers with letters or hyphens are compared lexically in ASCII sort order. > 3. Numeric identifiers always have lower precedence than non-numeric identifiers. > 4. A larger set of pre-release fields has a higher precedence than a smaller set, if all of the preceding identifiers are equal. Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0. Solution: cmp_prerel() treats all digit sequences in a prerelease string as numbers. This doesn't _exactly_ match the spec, which specifies that only dot-delimited digit sequences should be treated as numbers... --- test/functional/lua/version_spec.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test/functional/lua/version_spec.lua') diff --git a/test/functional/lua/version_spec.lua b/test/functional/lua/version_spec.lua index 014fea5272..75b62e8318 100644 --- a/test/functional/lua/version_spec.lua +++ b/test/functional/lua/version_spec.lua @@ -101,6 +101,9 @@ describe('version', function() { v1 = 'v9.0.0', v2 = 'v0.9.0', want = 1, }, { v1 = 'v0.9.0', v2 = 'v0.0.0', want = 1, }, { v1 = 'v0.0.9', v2 = 'v0.0.0', want = 1, }, + { v1 = 'v0.0.9+aaa', v2 = 'v0.0.9+bbb', want = 0, }, + + -- prerelease 💩 https://semver.org/#spec-item-11 { v1 = 'v1.0.0-alpha', v2 = 'v1.0.0', want = -1, }, { v1 = '1.0.0', v2 = '1.0.0-alpha', want = 1, }, { v1 = '1.0.0-2', v2 = '1.0.0-1', want = 1, }, @@ -116,11 +119,11 @@ describe('version', function() { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-alpha', want = 1, }, { v1 = '1.0.0-alpha', v2 = '1.0.0-alpha.beta', want = -1, }, { v1 = '1.0.0-alpha.beta', v2 = '1.0.0-beta', want = -1, }, - { v1 = '1.0.0-beta', v2 = '1.0.0-alpha.beta', want = 1, }, - { v1 = '1.0.0-beta', v2 = '1.0.0-beta.2', want = -1, }, - -- TODO - -- { v1 = '1.0.0-beta.2', v2 = '1.0.0-beta.11', want = -1, }, - { v1 = '1.0.0-beta.11', v2 = '1.0.0-rc.1', want = -1, }, + { v1 = '1.0.0-beta.2', v2 = '1.0.0-beta.11', want = -1, }, + { v1 = '1.0.0-beta.20', v2 = '1.0.0-beta.11', want = 1, }, + { v1 = '1.0.0-alpha.20', v2 = '1.0.0-beta.11', want = -1, }, + { v1 = '1.0.0-a.01.x.3', v2 = '1.0.0-a.1.x.003', want = 0, }, + { v1 = 'v0.9.0-dev-92+9', v2 = 'v0.9.0-dev-120+3', want = -1, }, } for _, tc in ipairs(testcases) do local msg = function(s) return ('v1 %s v2'):format(s == 0 and '==' or (s == 1 and '>' or '<')) end -- cgit