diff options
author | kotfu <kotfu@kotfu.net> | 2019-03-10 21:43:20 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2019-03-10 21:43:20 -0600 |
commit | a4ff1a45b205171663559b0f7003ecf84face2aa (patch) | |
tree | e078cbba60ff46563b7a92965ab81bb21ca52310 | |
parent | 0ff0dfe37b7a9e6998a133452d4718a119b82cf7 (diff) | |
download | cmd2-git-a4ff1a45b205171663559b0f7003ecf84face2aa.tar.gz |
Allow both history indices to be negative
-rw-r--r-- | cmd2/history.py | 4 | ||||
-rw-r--r-- | docs/freefeatures.rst | 3 | ||||
-rw-r--r-- | tests/test_history.py | 5 |
3 files changed, 6 insertions, 6 deletions
diff --git a/cmd2/history.py b/cmd2/history.py index 819989b1..04baf014 100644 --- a/cmd2/history.py +++ b/cmd2/history.py @@ -167,9 +167,7 @@ class History(list): end = int(end) if start is not None and end is not None: - # we have both start and end, return a slice of history, unless both are negative - if start < 0 and end < 0: - raise ValueError + # we have both start and end, return a slice of history result = self[start:end] elif start is not None and sep is not None: # take a slice of the array diff --git a/docs/freefeatures.rst b/docs/freefeatures.rst index 027caa91..4bfeffd0 100644 --- a/docs/freefeatures.rst +++ b/docs/freefeatures.rst @@ -310,8 +310,7 @@ last number, it will continue to the end:: 3 alias create three !echo three 4 alias create four !echo four -You can use negative numbers as either the first or second number of the range -(but not both). If you want to display the last three commands entered:: +If you want to display the last three commands entered:: (Cmd) history -- -3: 2 alias create two !echo two diff --git a/tests/test_history.py b/tests/test_history.py index 1554df5e..d9918b7a 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -77,11 +77,14 @@ def test_history_class_span(hist): assert hist.span('1..3') == ['first', 'second', 'third'] assert hist.span('1:3') == ['first', 'second', 'third'] + assert hist.span('2:-1') == ['second', 'third'] + assert hist.span('-3:4') == ['second', 'third','fourth'] + assert hist.span('-4:-2') == ['first', 'second'] assert hist.span(':-2') == ['first', 'second'] assert hist.span('..-2') == ['first', 'second'] - value_errors = ['fred', 'fred:joe', 'a..b', '2 ..', '1 : 3', '-2..-3' ] + value_errors = ['fred', 'fred:joe', 'a..b', '2 ..', '1 : 3'] for tryit in value_errors: with pytest.raises(ValueError): hist.span(tryit) |