Skip to content

Commit

Permalink
Fixing issue neovim#398: buf1 != buf2 doesn't work in python2
Browse files Browse the repository at this point in the history
Adding __ne__ function to pynvim.api.buffer.Buffer to correctly test
two buffers are not equal in Python 2. Test added to demonstrate.
  • Loading branch information
noelevans committed Jun 21, 2019
1 parent 4dd9962 commit a6b190d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pynvim/api/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def __delitem__(self, idx):
"""
self.__setitem__(idx, None)

def __ne__(self, other):
""" Test inequality of Buffers.
Necessary for Python 2 compatibility """
return not self.__eq__(other)

def append(self, lines, index=-1):
"""Append a string or list of lines to the buffer."""
if isinstance(lines, (basestring, bytes)):
Expand Down
6 changes: 6 additions & 0 deletions test/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ def test_update_highlights(vim):
vim.current.buffer[:] = ['a', 'b', 'c']
src_id = vim.new_highlight_source()
vim.current.buffer.update_highlights(src_id, [["Comment", 0, 0, -1], ("String", 1, 0, 1)], clear=True, async_=False)


def test_buffer_inequality(vim):
b = vim.current.buffer
assert not (b != vim.current.buffer)

0 comments on commit a6b190d

Please sign in to comment.