aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2011-12-16 20:53:09 +0100
committerMartin Vilcans <martin@librador.com>2011-12-16 23:05:17 +0100
commit1fc5cb7fe743133470c32fa4d0a13666c6735b05 (patch)
treebbcb16bdcfc333ee0b9bef1c7c0d3629b7fc46fb
parent92b56357798394415ae17d4a7253b111be91e01f (diff)
downloadscreenplain-1fc5cb7fe743133470c32fa4d0a13666c6735b05.tar.gz
A line with two spaces inside dialog keeps the dialog together.
Fixed according to spec.
-rw-r--r--screenplain/parsers/spmd.py7
-rw-r--r--tests/spmd_test.py16
2 files changed, 20 insertions, 3 deletions
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py
index 76d50c4..621e8df 100644
--- a/screenplain/parsers/spmd.py
+++ b/screenplain/parsers/spmd.py
@@ -27,7 +27,7 @@ centered_re = re.compile(r'\s*>\s*(.*)\s*<\s*$')
def is_blank(string):
- return string == '' or string.isspace() and string != ' '
+ return string == '' or string.isspace() and string != TWOSPACE
def is_slug(blanks_before, line_list):
@@ -97,7 +97,10 @@ def clean_line(line):
Leading whitespace is insignificant in SPMD, and trailing EOL
appear when reading from a file or HTML form.
"""
- return line.lstrip().rstrip('\r\n')
+ stripped = line.rstrip('\r\n')
+ if line == ' ':
+ return line
+ return line.lstrip()
def parse(source):
diff --git a/tests/spmd_test.py b/tests/spmd_test.py
index 28078c0..2efa2d4 100644
--- a/tests/spmd_test.py
+++ b/tests/spmd_test.py
@@ -5,7 +5,7 @@
import unittest2
from screenplain.parsers.spmd import parse
from screenplain.types import Slug, Action, Dialog, DualDialog, Transition
-from screenplain.richstring import plain
+from screenplain.richstring import plain, empty_string
class ParseTests(unittest2.TestCase):
@@ -100,6 +100,20 @@ class ParseTests(unittest2.TestCase):
dialog.blocks[1]
)
+ def test_twospace_keeps_dialog_together(self):
+ paras = list(parse([
+ 'SOMEONE',
+ 'One',
+ ' ',
+ 'Two',
+ ]))
+ self.assertEquals([Dialog], [type(p) for p in paras])
+ self.assertEquals([
+ (False, plain('One')),
+ (False, empty_string),
+ (False, plain('Two')),
+ ], paras[0].blocks)
+
def test_dual_dialog(self):
paras = list(parse([
'BRICK',