mirror of
https://github.com/neovim/neovim.git
synced 2026-04-20 22:35:33 +00:00
feat(vim.version): add __eq to vim.VersionRange #38881
Problem: vim.VersionRange had no __eq metamethod, so comparing 2 distinct but same value instances always returned false. In vim.pack.add this caused redundant lockfile rewrites, even when the resulting lockfile content was unchanged. Solution: Add __eq metamethod on vim.VersionRange
This commit is contained in:
@@ -65,6 +65,7 @@ LSP
|
||||
LUA
|
||||
|
||||
• Renamed `vim.diff` to `vim.text.diff`.
|
||||
• Added `__eq` metamethod to |vim.VersionRange|.
|
||||
|
||||
OPTIONS
|
||||
|
||||
@@ -301,6 +302,9 @@ LUA
|
||||
• EXPERIMENTAL: |vim.pos|, |vim.range| provide Position/Range abstraction.
|
||||
• |vim.filetype.inspect()| returns a copy of the internal tables used for
|
||||
filetype detection.
|
||||
• Added `__eq` metamethod to |vim.VersionRange|. 2 distinct but representing
|
||||
the same range instances now compare equal.
|
||||
|
||||
|
||||
OPTIONS
|
||||
|
||||
|
||||
@@ -273,6 +273,9 @@ end
|
||||
|
||||
local range_mt = {
|
||||
__index = VersionRange,
|
||||
__eq = function(self, other)
|
||||
return self.to == other.to and self.from == other.from
|
||||
end,
|
||||
__tostring = function(self)
|
||||
if not self.to then
|
||||
return '>=' .. tostring(self.from)
|
||||
|
||||
@@ -118,6 +118,18 @@ describe('version', function()
|
||||
end)
|
||||
end
|
||||
|
||||
it('__eq', function()
|
||||
local range1 = vim.version.range('1.2.3 - 2.3.4')
|
||||
local range2 = vim.version.range('1.2.3 - 2.3.4')
|
||||
local range3 = vim.version.range('<=1.2.3')
|
||||
local range4 = vim.version.range('1.2.3')
|
||||
assert(range1 == range1)
|
||||
assert(range1 == range2)
|
||||
assert(range1 ~= range3)
|
||||
assert(range1 ~= range4)
|
||||
assert(range3 ~= range4)
|
||||
end)
|
||||
|
||||
it('handles prerelease', function()
|
||||
assert(not vim.version.range('1.2.3'):has('1.2.3-alpha'))
|
||||
assert(vim.version.range('1.2.3-alpha'):has('1.2.3-alpha'))
|
||||
|
||||
Reference in New Issue
Block a user