Skip to content

Commit

Permalink
Merge pull request #536 from benoit-pierre/fix_535
Browse files Browse the repository at this point in the history
formatting: check an action word too when handling replace
  • Loading branch information
morinted committed Jun 2, 2016
2 parents 5e77cc0 + 98c503f commit b7a630a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
9 changes: 6 additions & 3 deletions plover/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ def _actions_to_text(action_list, text=u''):
for a in action_list:
if a.replace and text.endswith(a.replace):
text = text[:-len(a.replace)]
if a.text:
# With numbers, it's possible to have a.text='2' with a.word='1.2'
# folowing by an action that replaces '1.2' by '$1.20'...
if len(a.word) > len(a.text) and a.word.endswith(text):
text = a.word
else:
text += a.text
return text

Expand Down Expand Up @@ -186,8 +190,7 @@ def render(self, undo, do):
for a in do:
if a.replace and self.after.endswith(a.replace):
self.after = self.after[:-len(a.replace)]
if a.text:
self.after += a.text
self.after += a.text
if a.combo:
self.commit()
self.output.send_key_combination(a.combo)
Expand Down
60 changes: 60 additions & 0 deletions test/test_blackbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import unittest

from plover.steno import Stroke
from plover.formatting import Formatter
from plover.translation import Translator
from plover.steno_dictionary import StenoDictionary


class CaptureOutput(object):

def __init__(self):
self.instructions = []
self.text = u''

def send_backspaces(self, n):
assert n <= len(self.text)
self.text = self.text[:-n]
self.instructions.append(('b', n))

def send_string(self, s):
self.text += s
self.instructions.append(('s', s))

def send_key_combination(self, c):
self.instructions.append(('c', c))

def send_engine_command(self, c):
self.instructions.append(('e', c))


def steno_to_stroke(steno):
stroke = Stroke(())
stroke.rtfcre = steno
return stroke


class BlackboxTest(unittest.TestCase):

def setUp(self):
self.output = CaptureOutput()
self.formatter = Formatter()
self.formatter.set_output(self.output)
self.translator = Translator()
self.translator.add_listener(self.formatter.format)
self.dictionary = self.translator.get_dictionary()
self.dictionary.set_dicts([StenoDictionary()])

def test_bug535(self):
self.dictionary.set(('P-P',), '{^.^}')
self.dictionary.set(('KR*UR',), '{*($c)}')
for steno in (
'1',
'P-P',
'2',
'KR*UR',
):
stroke = steno_to_stroke(steno)
self.translator.translate(stroke)
self.assertEqual(self.output.text, u' $1.20')

0 comments on commit b7a630a

Please sign in to comment.