feat(vim.version): make tostring() return human-readable version range

Problem: `tostring()` applied to version range doesn't return
human-readable text with information about the range.

Solution: Add `__tostring()` method.
This commit is contained in:
Evgeni Chasnovski
2025-06-30 16:08:35 +03:00
parent 561021bacd
commit aeb8bca12d
3 changed files with 22 additions and 3 deletions

View File

@@ -89,6 +89,11 @@ describe('version', function()
eq(output, range)
end)
it('tostring() ' .. input, function()
eq(type(tostring(range)), 'string')
eq(vim.version.range(tostring(range)), range)
end)
it('[from] in range ' .. input, function()
assert(range:has(output.from))
end)
@@ -119,6 +124,9 @@ describe('version', function()
assert(not vim.version.range('1.2.3-alpha'):has('1.2.3-beta'))
assert(vim.version.range('>0.10'):has('0.12.0-dev'))
assert(not vim.version.range('>=0.12'):has('0.12.0-dev'))
local range_alpha = vim.version.range('1.2.3-alpha')
eq(vim.version.range(tostring(range_alpha)), range_alpha)
end)
it('returns nil with empty version', function()