From e6887932539315e02621edb77d5e77c7c2a0b033 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 12 Jun 2023 01:14:33 +0200 Subject: [PATCH] feat: tostring(vim.version()) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: tostring(vim.version()) returns "table: 0x…". Solution: Modify vim.version() to return a string prerelease instead of a boolean. Fix #23863 --- runtime/lua/vim/version.lua | 2 +- test/functional/lua/version_spec.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/version.lua b/runtime/lua/vim/version.lua index 5578423453..92250ff1f8 100644 --- a/runtime/lua/vim/version.lua +++ b/runtime/lua/vim/version.lua @@ -425,7 +425,7 @@ setmetatable(M, { __call = function() local version = vim.fn.api_info().version -- Workaround: vim.fn.api_info().version reports "prerelease" as a boolean. - version.prerelease = version.prerelease or nil + version.prerelease = version.prerelease and 'dev' or nil return setmetatable(version, Version) end, }) diff --git a/test/functional/lua/version_spec.lua b/test/functional/lua/version_spec.lua index 64dcbec983..d1c981c388 100644 --- a/test/functional/lua/version_spec.lua +++ b/test/functional/lua/version_spec.lua @@ -17,6 +17,18 @@ describe('version', function() eq({ major = 42, minor = 3, patch = 99 }, exec_lua("return vim.version.parse('v42.3.99')")) end) + it('version() returns Nvim version', function() + local expected = exec_lua('return vim.fn.api_info().version') + local actual = exec_lua('return vim.version()') + eq(expected.major, actual.major) + eq(expected.minor, actual.minor) + eq(expected.patch, actual.patch) + eq(expected.prerelease and 'dev' or nil, actual.prerelease) + + -- tostring() #23863 + matches([[%d+%.%d+%.%d+]], exec_lua('return tostring(vim.version())')) + end) + describe('_version()', function() local tests = { ['v1.2.3'] = { major = 1, minor = 2, patch = 3 },