Skip to content

Check count for 'not None' instead of truthy in command decorator #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion neovim/plugin/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def dec(f):

if range is not None:
opts['range'] = '' if range is True else str(range)
elif count:
elif count is not None:
opts['count'] = count

if bang:
Expand Down
30 changes: 30 additions & 0 deletions test/test_decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from nose.tools import with_setup, eq_ as eq, ok_ as ok

from neovim.plugin.decorators import command


def test_command_count():
def function():
"A dummy function to decorate."
return

# ensure absence with default value of None
decorated = command('test')(function)
ok('count' not in decorated._nvim_rpc_spec['opts'])

# ensure absence with explicit value of None
count_value = None
decorated = command('test', count=count_value)(function)
ok('count' not in decorated._nvim_rpc_spec['opts'])

# Test presesence with value of 0
count_value = 0
decorated = command('test', count=count_value)(function)
ok('count' in decorated._nvim_rpc_spec['opts'])
eq(decorated._nvim_rpc_spec['opts']['count'], count_value)

# Test presence with value of 1
count_value = 1
decorated = command('test', count=count_value)(function)
ok('count' in decorated._nvim_rpc_spec['opts'])
eq(decorated._nvim_rpc_spec['opts']['count'], count_value)