def test_parse_code_empty(self): """ Run parse_command on an empty code block. The return value should be an empty list. """ block = [] block.append("```root") block.append("```") retval = Markdown.parse_code(block) self.assertEqual(retval, [])
def test_parse_code_empty_pre(self): """ Run parse_command on an empty pre-block. The return value should be an empty list. """ block = [] block.append("<pre>") block.append("</pre>") retval = Markdown.parse_code(block) self.assertEqual(retval, [])
def test_parse_code_valid_unnamed(self): """ Run parse_command on an input without language indication and check that the return valid contains the specified block of code. """ block = [] block.append("```") block.append("void main() {};") block.append("```") retval = Markdown.parse_code(block) self.assertEqual(retval, ["void main() {};"])
def test_parse_code_valid_python(self): """ Run parse_command on an input with a different language indication and check that the return valid contains the specified block of code. """ block = [] block.append("```python") block.append("print(3)") block.append("```") retval = Markdown.parse_code(block) self.assertEqual(retval, ["print(3)"])
def test_parse_code_missing_end_pre(self): """ Run parse_command on pre-input without the block end and check that parsing failed. """ block = [] block.append("<pre>") block.append("touch /tmp") block.append("touch /home") retval = Markdown.parse_code(block) self.assertIsNone(retval) self.assertEqual(block, [])
def test_parse_code_missing_start(self): """ Run parse_command on input without the block start and check that parsing failed. """ block = [] block.append("touch /tmp") block.append("touch /home") block.append("```") retval = Markdown.parse_code(block) self.assertIsNone(retval) self.assertEqual(block, ['touch /tmp', 'touch /home', '```'])
def test_parse_code_leading_lines_pre(self): """ Run parse_command on pre-input with leading lines and check that parsing failed. The parse method should not remove any lines in this case. """ block = [] block.append("This is a leading line.") block.append("<pre>") block.append("touch /tmp") block.append("touch /home") block.append("</pre>") retval = Markdown.parse_code(block) self.assertIsNone(retval) self.assertEqual(len(block), 5)
def test_parse_code_trailing_lines_pre(self): """ Run parse_command on pre-input with trailing lines. Check that the trailing list is not in the output and all other lines have been removed from the input. """ block = [] block.append("<pre>") block.append("touch /tmp") block.append("touch /home") block.append("</pre>") block.append("This should not cause a crash.") retval = Markdown.parse_code(block) self.assertEqual(retval, ["touch /tmp", "touch /home"]) self.assertEqual(block, ["This should not cause a crash."])
def test_parse_code_mix_delimiter_2(self): """ Run parse_command on a block input which contains </pre> The parse_code should read this as-is and not interpret it as the block delimiter. """ block = [] block.append("```") block.append("<pre>") block.append("</pre>") block.append("```") retval = Markdown.parse_code(block) self.assertEqual(len(retval), 2) self.assertEqual(retval[0], "<pre>") self.assertEqual(retval[1], "</pre>") self.assertEqual(block, [])
def test_parse_code_valid_pre(self): """ Run parse_command on a pre-block input and check that the return value contains the specified block of code. The example should remove all lines from the input. """ block = [] block.append("<pre>") block.append("whoami") block.append("ls ~") block.append("</pre>") retval = Markdown.parse_code(block) self.assertEqual(len(retval), 2) self.assertEqual(retval[0], "whoami") self.assertEqual(retval[1], "ls ~") self.assertEqual(block, [])