diff options
author | Martin Vilcans <martin@librador.com> | 2011-11-10 23:33:02 +0100 |
---|---|---|
committer | Martin Vilcans <martin@librador.com> | 2011-11-10 23:53:34 +0100 |
commit | 083800d933041f7a35cb19011d68d1e51c7f8b9f (patch) | |
tree | d2c81877c8c31c1b985ddf9e1ff5ff16a31ee998 /tests/richstring_test.py | |
parent | a7f8938b10877ff207688b3ff02f62c55e6c1266 (diff) | |
download | screenplain-083800d933041f7a35cb19011d68d1e51c7f8b9f.tar.gz |
Made RichString non-hierarchical (simpler).
Also: FDX output should have correct line breaks now.
Diffstat (limited to 'tests/richstring_test.py')
-rw-r--r-- | tests/richstring_test.py | 96 |
1 files changed, 61 insertions, 35 deletions
diff --git a/tests/richstring_test.py b/tests/richstring_test.py index b442f90..c79981d 100644 --- a/tests/richstring_test.py +++ b/tests/richstring_test.py @@ -1,128 +1,154 @@ import unittest2 -from screenplain.richstring import RichString, Bold, Italic, Underline +from screenplain.richstring import ( + RichString, Segment, + Bold, Italic, + plain, bold, italic, underline +) from screenplain.richstring import parse_emphasis from screenplain.types import Slug, Action, Dialog, DualDialog, Transition +class LowLevelRichStringTests(unittest2.TestCase): + + def test_plain_string_has_one_single_segment(self): + s = RichString(plain('hello')) + self.assertEqual((plain('hello'),), s.segments) + + class RichStringOperatorTests(unittest2.TestCase): def test_repr(self): - s = RichString(Bold('Hello'), ' there ', Bold('folks')) + s = bold('Hello') + plain(' there ') + bold('folks') self.assertEquals( - "RichString(Bold('Hello'), ' there ', Bold('folks'))", + "(bold)('Hello') + (plain)(' 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('Hello'), bold('Hello')) + self.assertNotEquals(bold('Hello'), bold('Foo')) + self.assertNotEquals(plain('Hello'), bold('Hello')) + + def test_ne(self): + self.assertFalse(bold('Hello') != bold('Hello')) + + def test_concatenating_two_richstrings(self): + expected = RichString(Segment('hello', ()), Segment(' there', (Bold,))) + s1 = plain('hello') + s2 = bold(' there') + result = s1 + s2 + self.assertEquals(expected, result) + + +class StyleGeneratorTests(unittest2.TestCase): + + def test_bold_function_creates_bold_richstring(self): self.assertEquals( - Bold('a', Italic('b'), 'c'), - Bold('a', Italic('b'), 'c') - ) - self.assertNotEquals( - Bold('a', Italic('b'), 'c'), - Bold('a', Italic('b'), 'd') + RichString(Segment('a', (Bold,))), + bold('a') ) - def test_ne(self): - self.assertFalse(Bold('Hello') != Bold('Hello')) + def test_adding_functions(self): + self.assertEquals( + RichString(Segment('a', (Bold, Italic))), + (bold + italic)('a') + ) class RichStringTests(unittest2.TestCase): def test_plain_to_html(self): - self.assertEquals('hello', RichString('hello').to_html()) + self.assertEquals('hello', RichString(plain('hello')).to_html()) def test_to_html(self): s = RichString( - Bold('bold'), - ' normal ', - Italic('italic'), - Underline('wonderline') + bold('bold'), + plain(' 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') + self.assertEquals(plain('Hello'), parse_emphasis('Hello'), + 'Expected parse_emphasis to return a plain string') def test_parse_bold(self): self.assertEquals( parse_emphasis('**Hello**'), - Bold('Hello') + bold('Hello') ) def test_parse_pre_and_postfix_and_bold(self): self.assertEquals( parse_emphasis('pre**Hello**post'), - RichString('pre', Bold('Hello'), 'post'), + plain('pre') + bold('Hello') + plain('post') ) def test_parse_multiple_bold(self): self.assertEquals( parse_emphasis('x**Hello** **there**'), - RichString('x', Bold('Hello'), ' ', Bold('there')) + plain('x') + bold('Hello') + plain(' ') + bold('there') ) def test_parse_adjacent_bold(self): self.assertEquals( - parse_emphasis('**123****456**'), - RichString(Bold('123**'), '456**') + parse_emphasis('**123**456**'), + bold('123') + plain('456**') ) def test_italic(self): self.assertEquals( parse_emphasis('*Italian style*'), - Italic('Italian style') + italic('Italian style') ) def test_bold_inside_italic(self): self.assertEquals( parse_emphasis('*Swedish **style** rules*'), - Italic('Swedish ', Bold('style'), ' rules') + italic('Swedish ') + (bold + italic)('style') + italic(' rules') ) def test_italic_inside_bold(self): self.assertEquals( parse_emphasis('**Swedish *style* rules**'), - Bold('Swedish ', Italic('style'), ' rules') + bold('Swedish ') + (bold + italic)('style') + bold(' rules') ) def test_italic_and_bold(self): self.assertEquals( parse_emphasis('***really strong***'), - Bold(Italic('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') + italic('foo') + plain(' bar* baz') ) def test_underline(self): self.assertEquals( parse_emphasis('_hello_'), - Underline('hello') + underline('hello') ) def test_bold_inside_underline(self): self.assertEquals( parse_emphasis('_**hello**_'), - Underline(Bold('hello')) + (bold + underline)('hello') ) def test_overlapping_underscore_and_italic(self): + # It's unclear what result to expect in this case. + # This is one way of interpreting it self.assertEquals( parse_emphasis('_*he_llo*'), - RichString(Underline('*he'), 'llo*') + (italic + underline)('he') + italic('llo') ) |