aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2011-09-14 23:01:11 +0200
committerMartin Vilcans <martin@librador.com>2011-09-21 23:24:59 +0200
commitf38a458da58b0cbd456ff935f8a8f84f1a1f385d (patch)
treebdbc705361f048ef9945fa443c9768d2fdb13708 /tests
parentb504daae552e0ca07c1946e49812e05363834f46 (diff)
downloadscreenplain-f38a458da58b0cbd456ff935f8a8f84f1a1f385d.tar.gz
Parse bold, italic and underline (no output yet).
Diffstat (limited to 'tests')
-rw-r--r--tests/richstring_test.py122
-rw-r--r--tests/spmd_test.py4
2 files changed, 122 insertions, 4 deletions
diff --git a/tests/richstring_test.py b/tests/richstring_test.py
new file mode 100644
index 0000000..bd7ea22
--- /dev/null
+++ b/tests/richstring_test.py
@@ -0,0 +1,122 @@
+import unittest2
+from screenplain.richstring import RichString, Bold, Italic, Underline
+from screenplain.richstring import parse_emphasis
+from screenplain.types import Slug, Action, Dialog, DualDialog, Transition
+
+class RichStringOperatorTests(unittest2.TestCase):
+
+ def test_repr(self):
+ s = RichString(Bold('Hello'), ' there ', Bold('folks'))
+ self.assertEquals(
+ "RichString(Bold('Hello'), ' there ', Bold('folks'))",
+ repr(s)
+ )
+
+ def test_eq(self):
+ self.assertEquals(Bold('Hello'), Bold('Hello'))
+ self.assertNotEquals(Bold('Hello'), Bold('Foo'))
+ self.assertNotEquals('Hello', Bold('Hello'))
+ self.assertEquals(
+ Bold('a', Italic('b'), 'c'),
+ Bold('a', Italic('b'), 'c')
+ )
+ self.assertNotEquals(
+ Bold('a', Italic('b'), 'c'),
+ Bold('a', Italic('b'), 'd')
+ )
+
+ def test_ne(self):
+ self.assertFalse(Bold('Hello') != Bold('Hello'))
+
+class RichStringTests(unittest2.TestCase):
+
+ def test_to_html(self):
+ s = RichString(
+ Bold('bold'),
+ ' normal ',
+ Italic('italic'),
+ Underline('wonderline')
+ )
+ self.assertEquals(
+ '<strong>bold</strong> normal <em>italic</em><u>wonderline</u>',
+ s.to_html()
+ )
+
+class ParseEmphasisTests(unittest2.TestCase):
+
+ def test_parse_without_emphasis(self):
+ self.assertEquals(RichString('Hello'), parse_emphasis('Hello'),
+ 'Expected parse_emphasis to return a string')
+
+ def test_parse_bold(self):
+ self.assertEquals(
+ parse_emphasis('**Hello**'),
+ Bold('Hello')
+ )
+
+ def test_parse_pre_and_postfix_and_bold(self):
+ self.assertEquals(
+ parse_emphasis('pre**Hello**post'),
+ RichString('pre', Bold('Hello'), 'post'),
+ )
+
+ def test_parse_multiple_bold(self):
+ self.assertEquals(
+ parse_emphasis('x**Hello** **there**'),
+ RichString('x', Bold('Hello'), ' ', Bold('there'))
+ )
+
+ def test_parse_adjacent_bold(self):
+ self.assertEquals(
+ parse_emphasis('**123****456**'),
+ RichString(Bold('123**'), '456**')
+ )
+
+ def test_italic(self):
+ self.assertEquals(
+ parse_emphasis('*Italian style*'),
+ Italic('Italian style')
+ )
+
+ def test_bold_inside_italic(self):
+ self.assertEquals(
+ parse_emphasis('*Swedish **style** rules*'),
+ Italic('Swedish ', Bold('style'), ' rules')
+ )
+
+ def test_italic_inside_bold(self):
+ self.assertEquals(
+ parse_emphasis('**Swedish *style* rules**'),
+ Bold('Swedish ', Italic('style'), ' rules')
+ )
+
+ def test_italic_and_bold(self):
+ self.assertEquals(
+ parse_emphasis('***really strong***'),
+ Bold(Italic('really strong'))
+ )
+
+ @unittest2.expectedFailure
+ def test_additional_star(self):
+ self.assertEquals(
+ parse_emphasis('*foo* bar* baz'),
+ RichString(Italic('foo'), ' bar* baz')
+ )
+
+ def test_underline(self):
+ self.assertEquals(
+ parse_emphasis('_hello_'),
+ Underline('hello')
+ )
+
+ def test_bold_inside_underline(self):
+ self.assertEquals(
+ parse_emphasis('_**hello**_'),
+ Underline(Bold('hello'))
+ )
+
+ def test_overlapping_underscore_and_italic(self):
+ self.assertEquals(
+ parse_emphasis('_*he_llo*'),
+ RichString(Underline('*he'), 'llo*')
+ )
diff --git a/tests/spmd_test.py b/tests/spmd_test.py
index caa5b20..4a04660 100644
--- a/tests/spmd_test.py
+++ b/tests/spmd_test.py
@@ -4,10 +4,6 @@ from screenplain.types import Slug, Action, Dialog, DualDialog, Transition
class ParseTests(unittest2.TestCase):
- # Without this, the @skip decorator gives
- # AttributeError: 'ParseTests' object has no attribute '__name__'
- __name__ = 'ParseTests'
-
# A Scene Heading, or "slugline," is any line that has a blank
# line following it, and either begins with INT or EXT, or has
# two empty lines preceding it. A Scene Heading always has at