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

Code before:
      it('[from] in range ' .. input, function()
        assert(range:has(output.from))
      end)

      it('[from-1] not in range ' .. input, function()
        local lower = vim.deepcopy(range.from)
        lower.major = lower.major - 1
        assert(not range:has(lower))
      end)

      it('[to] not in range ' .. input .. ' to:' .. tostring(range.to), function()
        if range.to and range.to ~= range.from then
          assert(not (range.to < range.to))
          assert(not range:has(range.to))
        end
      end)

      it('[to] in range ' .. input .. ' to:' .. tostring(range.to), function()
        if range.to and range.to == range.from then
          assert(range:has(range.to))
        end
      end)
    end

    it('handles prerelease', function()
      assert(not vim.version.range('1.2.3'):has('1.2.3-alpha'), '1.2.3 should not have 1.2.3-alpha')
      assert(
        vim.version.range('1.2.3-alpha'):has('1.2.3-alpha'),
        '1.2.3-alpha should have 1.2.3-alpha'
      )
      assert(
        not vim.version.range('1.2.3-alpha'):has('1.2.3-beta'),
        '1.2.3-alpha should not have 1.2.3-beta'
      )
      assert(vim.version.range('>0.10'):has('0.12.0-dev'), '>0.10 should have 0.12.0-dev')
      assert(not vim.version.range('>=0.12'):has('0.12.0-dev'), '>=0.12 should not have 0.12.0-dev')
    end)

    it('returns nil with empty version', function()
      eq(vim.version.parse(''), nil)
    end)
  end)

  describe('cmp()', function()
    local testcases = {
      { v1 = 'v0.0.99', v2 = 'v9.0.0', want = -1 },
      { v1 = 'v0.4.0', v2 = 'v0.9.99', want = -1 },
      { v1 = 'v0.2.8', v2 = 'v1.0.9', want = -1 },
      { v1 = 'v0.0.0', v2 = 'v0.0.0', want = 0 },
      { v1 = 'v9.0.0', v2 = 'v0.9.0', want = 1 },
      { v1 = 'v0.9.0', v2 = 'v0.0.0', want = 1 },

Review comment (bug):
don't need the extra messages. the code is already quite readable. though it was wrong before :)
```suggestion
      assert(not vim.version.range('1.2.3'):has('1.2.3-alpha'))
```

Code after:
      it('[from] in range ' .. input, function()
        assert(range:has(output.from))
      end)

      it('[from-1] not in range ' .. input, function()
        local lower = vim.deepcopy(range.from)
        lower.major = lower.major - 1
        assert(not range:has(lower))
      end)

      it('[to] not in range ' .. input .. ' to:' .. tostring(range.to), function()
        if range.to and range.to ~= range.from then
          assert(not (range.to < range.to))
          assert(not range:has(range.to))
        end
      end)

      it('[to] in range ' .. input .. ' to:' .. tostring(range.to), function()
        if range.to and range.to == range.from then
          assert(range:has(range.to))
        end
      end)
    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'))
      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'))
    end)

    it('returns nil with empty version', function()
      eq(vim.version.parse(''), nil)
    end)
  end)

  describe('cmp()', function()
    local testcases = {
      { v1 = 'v0.0.99', v2 = 'v9.0.0', want = -1 },
      { v1 = 'v0.4.0', v2 = 'v0.9.99', want = -1 },
      { v1 = 'v0.2.8', v2 = 'v1.0.9', want = -1 },
      { v1 = 'v0.0.0', v2 = 'v0.0.0', want = 0 },
      { 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 },