Skip to content

Commit

Permalink
Merge pull request #215 from michaelnt/reformat
Browse files Browse the repository at this point in the history
 Remove trailing white space from every line of text
  • Loading branch information
jacebrowning committed Jan 19, 2017
2 parents a507ee8 + 9d8a59b commit 3acc4d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doorstop/core/test/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_text_formatting(self):
def test_text_non_heading(self):
"""Verify newlines are preserved around non-headings."""
self.item.text = "break (before \n#2) symbol should not be a heading."
expected = "break (before \n#2) symbol should not be a heading."
expected = "break (before\n#2) symbol should not be a heading."
self.assertEqual(expected, self.item.text)

def test_text_heading(self):
Expand Down
14 changes: 10 additions & 4 deletions doorstop/core/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ def test_init(self):

def test_repr(self):
"""Verify text can be represented."""
self.assertEqual("'Hello, \\nworld!'", repr(self.text))
self.assertEqual("'Hello,\\nworld!'", repr(self.text))

def test_str(self):
"""Verify text can be converted to strings."""
self.assertEqual("Hello, \nworld!", str(self.text))
self.assertEqual("Hello,\nworld!", str(self.text))

def test_eq(self):
"""Verify text can be equated."""
self.assertEqual(Text("Hello, \nworld!"), self.text)
self.assertEqual(Text("Hello,\nworld!"), self.text)

def test_yaml(self):
"""Verify levels can be converted to their YAML representation."""
self.assertEqual('Hello, \nworld!\n', self.text.yaml)
self.assertEqual('Hello,\nworld!\n', self.text.yaml)

def test_dump_yaml(self):
"""Verify levels can be converted to their YAML representation."""
Expand All @@ -197,6 +197,12 @@ def test_dump_yaml_space(self):
text = Text(' abc ')
self.assertEqual('|2\n abc\n', yaml.dump(text.yaml))

def test_dump_yaml_space_before_newline(self):
"""Text starting with a space is encoded to a yaml literal string
with a hint as to the indent."""
text = Text('hello \nworld\n')
self.assertEqual('|\n hello\n world\n', yaml.dump(text.yaml))


class TestLevel(unittest.TestCase):
"""Unit tests for the Level class.""" # pylint: disable=W0212
Expand Down
3 changes: 2 additions & 1 deletion doorstop/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def load_text(value):
return ""
text_value = re.sub('^\n+', '', value)
text_value = re.sub('\n+$', '', text_value)
return text_value.rstrip(' ')
text_value = '\n'.join([s.rstrip() for s in text_value.split('\n')])
return text_value

@staticmethod
def save_text(text, end='\n'):
Expand Down

0 comments on commit 3acc4d6

Please sign in to comment.