def test_several_styles(self): rich = bold('outer') + (bold + italic)('inner') + bold('outer') write_text(self.out, rich, False) self.assertEqual( self.out.getvalue(), ' <Text Style="Bold">outer</Text>\n' ' <Text Style="Bold+Italic">inner</Text>\n' ' <Text Style="Bold">outer</Text>\n')
def test_write_text_adds_line_break_if_requested(self): rich = bold('outer') + (bold + italic)('inner') + bold('outer') write_text(self.out, rich, True) self.assertEqual( self.out.getvalue(), ' <Text Style="Bold">outer</Text>\n' ' <Text Style="Bold+Italic">inner</Text>\n' ' <Text Style="Bold">outer\n</Text>\n' # note newline )
def test_several_styles(self): rich = bold('outer') + (bold + italic)('inner') + bold('outer') write_text(self.out, rich, False) self.assertEqual( self.out.getvalue(), ' <Text Style="Bold">outer</Text>\n' ' <Text Style="Bold+Italic">inner</Text>\n' ' <Text Style="Bold">outer</Text>\n' )
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)
def test_sequential_styles(self): rich = plain('plain') + bold('b') + italic('i') write_text(self.out, rich, False) self.assertEqual( self.out.getvalue(), ' <Text>plain</Text>\n' ' <Text Style="Bold">b</Text>\n' ' <Text Style="Italic">i</Text>\n')
def test_to_html(self): s = ( bold('bold') + plain(' normal ') + italic('italic') + underline('wonderline') ) self.assertEquals( '<strong>bold</strong> normal <em>italic</em><u>wonderline</u>', s.to_html() )
def test_sequential_styles(self): rich = plain('plain') + bold('b') + italic('i') write_text(self.out, rich, False) self.assertEqual( self.out.getvalue(), ' <Text>plain</Text>\n' ' <Text Style="Bold">b</Text>\n' ' <Text Style="Italic">i</Text>\n' )
def test_complicated(self): # As reported by Stu self.assertEquals( parse_emphasis( 'You can _underline_ words, make them **bold** or *italic* ' 'or even ***bold italic.***'), (plain('You can ') + underline('underline') + plain(' words, make them ') + bold('bold') + plain(' or ') + italic('italic') + plain(' or even ') + (bold + italic)('bold italic.')))
def test_complicated(self): # As reported by Stu self.assertEquals( parse_emphasis( 'You can _underline_ words, make them **bold** or *italic* ' 'or even ***bold italic.***' ), ( plain('You can ') + underline('underline') + plain(' words, make them ') + bold('bold') + plain(' or ') + italic('italic') + plain(' or even ') + (bold + italic)('bold italic.') ) )
def test_unicode(self): s = bold('Hello') + plain(' there ') + bold('folks') self.assertEquals( u'Hello there folks', unicode(s) )
def test_repr(self): s = bold('Hello') + plain(' there ') + bold('folks') self.assertEquals( "(bold)('Hello') + (plain)(' there ') + (bold)('folks')", repr(s) )
def test_two_bold_should_not_create_one_long_bold_string(self): self.assertEquals( parse_emphasis('**first** **second**'), bold('first') + plain(' ') + bold('second') )
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)
def test_parse_pre_and_postfix_and_bold(self): self.assertEquals( parse_emphasis('pre**Hello**post'), plain('pre') + bold('Hello') + plain('post') )
def test_bold_text_should_have_bold_style(self): write_text(self.out, bold('hello'), False) self.assertEqual( self.out.getvalue(), ' <Text Style="Bold">hello</Text>\n' )
def test_eq(self): 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_parse_multiple_bold(self): self.assertEquals( parse_emphasis('x**Hello** **there**'), plain('x') + bold('Hello') + plain(' ') + bold('there') )
def test_bold_function_creates_bold_richstring(self): self.assertEquals( RichString(Segment('a', (Bold,))), bold('a') )
def test_parse_adjacent_bold(self): self.assertEquals( parse_emphasis('**123**456**'), bold('123') + plain('456**') )
def test_parse_bold(self): self.assertEquals( parse_emphasis('**Hello**'), bold('Hello') )
def test_italic_inside_bold(self): self.assertEquals( parse_emphasis('**Swedish *style* rules**'), bold('Swedish ') + (bold + italic)('style') + bold(' rules') )