Exemplo n.º 1
0
 def test_process_rst_code_blocks(self):
     m = macro.CodeHighlightingMacro(self.logtest)
     hl = m.process(self.sample_html)
     self.assertTrue(hl[0].startswith('<p>Let me give you this'))
     self.assertTrue(hl[0].find('<p>Then this one') > 0)
     self.assertTrue(hl[0].find('<p>Then this other one') > 0)
     self.assertTrue(hl[0].find('<div class="highlight"><pre') > 0)
     self.assertEquals(hl[1][0], u'has_code')
Exemplo n.º 2
0
 def test_process(self):
     m = macro.CodeHighlightingMacro(self.logtest)
     hl = m.process("<pre><code>!php\n$foo;</code></pre>")
     self.assertTrue(hl[0].startswith('<div class="highlight"><pre'))
     self.assertEquals(hl[1][0], u'has_code')
     input = "<p>Nothing to declare</p>"
     self.assertEquals(m.process(input)[0], input)
     self.assertEquals(m.process(input)[1], [])
Exemplo n.º 3
0
 def test_descape(self):
     m = macro.CodeHighlightingMacro(self.logtest)
     self.assertEquals(m.descape('foo'), 'foo')
     self.assertEquals(m.descape('&gt;'), '>')
     self.assertEquals(m.descape('&lt;'), '<')
     self.assertEquals(m.descape('&amp;lt;'), '&lt;')
     self.assertEquals(m.descape('&lt;span&gt;'), '<span>')
     self.assertEquals(m.descape('&lt;spam&amp;eggs&gt;'), '<spam&eggs>')
Exemplo n.º 4
0
 def test_parsing_code_blocks(self):
     m = macro.CodeHighlightingMacro(self.logtest)
     blocks = m.code_blocks_re.findall(self.sample_html)
     self.assertEquals(len(blocks), 3)
     self.assertEquals(blocks[0][2], 'python')
     self.assertTrue(blocks[0][3].startswith('def foo():'))
     self.assertEquals(blocks[1][2], 'php')
     self.assertTrue(blocks[1][3].startswith('<?php'))
     self.assertEquals(blocks[2][2], 'xml')
     self.assertTrue(blocks[2][3].startswith('<foo>'))
Exemplo n.º 5
0
 def test_parsing_code_blocks(self):
     m = macro.CodeHighlightingMacro(self.logtest)
     blocks = m.banged_blocks_re.finditer(self.sample_html)
     match = blocks.next()
     self.assertEquals(match.group('lang'), 'python')
     self.assertTrue(match.group('code').startswith('def foo():'))
     match = blocks.next()
     self.assertEquals(match.group('lang'), 'php')
     self.assertTrue(match.group('code').startswith('<?php'))
     match = blocks.next()
     self.assertEquals(match.group('lang'), 'xml')
     self.assertTrue(match.group('code').startswith('<foo>'))
     with self.assertRaises(StopIteration):
         blocks.next()