Repository: neovim/neovim
File: test/functional/lua/version_spec.lua (Lua)

Code before:
      ['v1.2.3'] = { major = 1, minor = 2, patch = 3 },
      ['v1.2'] = { major = 1, minor = 2, patch = 0 },
      ['v1.2.3-prerelease'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease' },
      ['v1.2-prerelease'] = { major = 1, minor = 2, patch = 0, prerelease = 'prerelease' },
      ['v1.2.3-prerelease+build'] = {
        major = 1,
        minor = 2,
        patch = 3,
        prerelease = 'prerelease',
        build = 'build',
      },
      ['1.2.3+build'] = { major = 1, minor = 2, patch = 3, build = 'build' },
    }
    for input, output in pairs(tests) do
      it('parses ' .. input, function()
        eq(output, v(input))
      end)
    end
  end)

  describe('range', function()
    local tests = {
      ['1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 2, 3 } },
      ['1.2'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['=1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 2, 3 } },
      ['>1.2.3'] = { from = '1.2.4-alpha' },
      ['>=1.2.3'] = { from = { 1, 2, 3 } },
      ['<1.2.3'] = { from = { 0, 0, 0 }, to = { 1, 2, 3 } },
      ['<=1.2.3'] = { from = { 0, 0, 0 }, to = '1.2.4-alpha' },
      ['~1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 3, 0 } },
      ['^1.2.3'] = { from = { 1, 2, 3 }, to = { 2, 0, 0 } },
      ['^0.2.3'] = { from = { 0, 2, 3 }, to = { 0, 3, 0 } },
      ['^0.0.1'] = { from = { 0, 0, 1 }, to = { 0, 0, 2 } },
      ['^1.2'] = { from = { 1, 2, 0 }, to = { 2, 0, 0 } },
      ['~1.2'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['~1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['^1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1.*'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1.x'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1.2.x'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['1.2.*'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['*'] = { from = { 0, 0, 0 } },
      ['1.2 - 2.3.0'] = { from = { 1, 2, 0 }, to = { 2, 3, 0 } },
      ['1.2.3 - 2.3.4'] = { from = { 1, 2, 3 }, to = { 2, 3, 4 } },
      ['1.2.3 - 2'] = { from = { 1, 2, 3 }, to = { 3, 0, 0 } },
    }
    for input, output in pairs(tests) do
      output.from = v(output.from)
      output.to = output.to and v(output.to)
      local range = vim.version.range(input)

Review comment (suggestion):
```suggestion
      ['>1.2.3'] = { from = '1.2.4-0' },
```

Code after:
      ['v1.2.3'] = { major = 1, minor = 2, patch = 3 },
      ['v1.2'] = { major = 1, minor = 2, patch = 0 },
      ['v1.2.3-prerelease'] = { major = 1, minor = 2, patch = 3, prerelease = 'prerelease' },
      ['v1.2-prerelease'] = { major = 1, minor = 2, patch = 0, prerelease = 'prerelease' },
      ['v1.2.3-prerelease+build'] = {
        major = 1,
        minor = 2,
        patch = 3,
        prerelease = 'prerelease',
        build = 'build',
      },
      ['1.2.3+build'] = { major = 1, minor = 2, patch = 3, build = 'build' },
    }
    for input, output in pairs(tests) do
      it('parses ' .. input, function()
        eq(output, v(input))
      end)
    end
  end)

  describe('range', function()
    local tests = {
      ['1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 2, 3 } },
      ['1.2'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['=1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 2, 3 } },
      ['>1.2.3'] = { from = '1.2.4-0' },
      ['>=1.2.3'] = { from = { 1, 2, 3 } },
      ['<1.2.3'] = { from = { 0, 0, 0 }, to = { 1, 2, 3 } },
      ['<=1.2.3'] = { from = { 0, 0, 0 }, to = '1.2.4-0' },
      ['~1.2.3'] = { from = { 1, 2, 3 }, to = { 1, 3, 0 } },
      ['^1.2.3'] = { from = { 1, 2, 3 }, to = { 2, 0, 0 } },
      ['^0.2.3'] = { from = { 0, 2, 3 }, to = { 0, 3, 0 } },
      ['^0.0.1'] = { from = { 0, 0, 1 }, to = { 0, 0, 2 } },
      ['^1.2'] = { from = { 1, 2, 0 }, to = { 2, 0, 0 } },
      ['~1.2'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['~1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['^1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1.*'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1.x'] = { from = { 1, 0, 0 }, to = { 2, 0, 0 } },
      ['1.2.x'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['1.2.*'] = { from = { 1, 2, 0 }, to = { 1, 3, 0 } },
      ['*'] = { from = { 0, 0, 0 } },
      ['1.2 - 2.3.0'] = { from = { 1, 2, 0 }, to = { 2, 3, 0 } },
      ['1.2.3 - 2.3.4'] = { from = { 1, 2, 3 }, to = { 2, 3, 4 } },
      ['1.2.3 - 2'] = { from = { 1, 2, 3 }, to = { 3, 0, 0 } },
    }
    for input, output in pairs(tests) do
      output.from = v(output.from)
      output.to = output.to and v(output.to)
      local range = vim.version.range(input)