aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fdx_test.py
blob: 9737493ea0b9ac1ca9eeb439f87469d3d91781af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import unittest2
from StringIO import StringIO

from screenplain.export.fdx import write_text

from screenplain.richstring import RichString, Bold, Italic

class OutputTests(unittest2.TestCase):

    def setUp(self):
        self.out = StringIO()

    def test_plain_text_should_have_no_style(self):
        write_text(self.out, RichString('hello'))
        self.assertEqual(
            self.out.getvalue(),
            '<Text>hello</Text>'
        )

    def test_bold_text_should_have_bold_style(self):
        write_text(self.out, Bold('hello'))
        self.assertEqual(
            self.out.getvalue(),
            '<Text style="Bold">hello</Text>'
        )

    def test_sequential_styles(self):
        rich = RichString('plain', Bold('b'), Italic('i'))
        write_text(self.out, rich)
        self.assertEqual(
            self.out.getvalue(),
            '<Text>plain</Text>'
            '<Text style="Bold">b</Text>'
            '<Text style="Italic">i</Text>'
        )

    def test_nested_styles(self):
        rich = Bold('outer', Italic('inner'), 'outer')
        write_text(self.out, rich)
        self.assertEqual(
            self.out.getvalue(),
            '<Text style="Bold">outer</Text>'
            '<Text style="Bold+Italic">inner</Text>'
            '<Text style="Bold">outer</Text>'
        )