Skip to content
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

Fix cursorManager selection bugs #7131

Merged
merged 6 commits into from May 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/unit/test_cursorManager.py
Expand Up @@ -35,6 +35,8 @@ def test_selectNextChar(self):
self.assertEqual(cm.selectionOffsets, (0, 1)) # "a" selected

def test_selectPrevChar(self):
"""Same as test_selectNextChar, but with reversed direction.
"""
cm = CursorManager(text="abc", selection=(1, 1)) # Caret at "b"
cm.script_selectCharacter_back(None)
self.assertEqual(cm.selectionOffsets, (0, 1)) # "a" selected
Expand All @@ -47,6 +49,32 @@ def test_unselectPrevChar(self):
cm.script_selectCharacter_back(None) # "a" unselected
self.assertEqual(cm.selectionOffsets, (0, 0)) # Caret at "a", no selection

def test_unselectNextChar(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the names "unselectPrevChar" and "unselectNextChar" somehow they seem the wrong way around? They might be clearer if called "selectPreviousUnsel" and "selectNextUnsel"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the later tests use the term "forward" and "back" rather than "next" and "prev". It would be nice if we could be consistent here, I think forward and back make more sense since they are used in the name of the script_ functions.

"""Depends on behavior tested by test_selectPrevChar.
Same as test_unselectPrevChar, but with reversed directions.
"""
cm = CursorManager(text="abc", selection=(1, 1)) # Caret at "b"
cm.script_selectCharacter_back(None) # "a" selected
cm.script_selectCharacter_forward(None) # "a" unselected
self.assertEqual(cm.selectionOffsets, (1, 1)) # Caret at "b", no selection

def test_selectNextCharTwice(self):
"""Depends on behavior tested in test_selectNextChar.
"""
cm = CursorManager(text="abc") # Caret at "a"
cm.script_selectCharacter_forward(None) # "a" selected
cm.script_selectCharacter_forward(None) # "b" selected
self.assertEqual(cm.selectionOffsets, (0, 2)) # "ab" selected

def test_selectPrevCharTwice(self):
"""Depends on behavior tested in test_selectPrevChar.
Same as test_selectNextCharTwice, but with reversed directions.
"""
cm = CursorManager(text="abc", selection=(2, 2)) # Caret at "c"
cm.script_selectCharacter_back(None) # "b" selected
cm.script_selectCharacter_back(None) # "a" selected
self.assertEqual(cm.selectionOffsets, (0, 2)) # "ab" selected

def test_selForwardThenUnselThenSelBackward(self):
"""Test selecting forward, then unselecting and selecting backward.
Depends on behavior tested by test_unselectPrevChar.
Expand All @@ -57,6 +85,16 @@ def test_selForwardThenUnselThenSelBackward(self):
cm.script_selectCharacter_back(None)
self.assertEqual(cm.selectionOffsets, (0, 1)) # "a" selected

def test_selBackwardThenUnselThenSelForward(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on test_unselectNextChar

"""Test selecting backward, then unselecting and selecting forward.
Same as test_selForwardThenUnselThenSelBackward, but with reversed directions.
"""
cm = CursorManager(text="abc", selection=(1, 1)) # Caret at "b"
cm.script_selectCharacter_back(None) # "a" selected
cm.script_selectCharacter_forward(None) # "a" unselected, caret at "b"
cm.script_selectCharacter_forward(None)
self.assertEqual(cm.selectionOffsets, (1, 2)) # "b" selected

def test_selectForwardThenSelBackward(self):
"""Test selecting forward, then selecting backward without unselecting.
Depends on behavior tested by test_selectNextChar.
Expand Down