def test_tokens_and_str(self): info_block = parser.InfoBlock() info_block.append(cga.TokenNode({'text_line': 'line1'})) info_block.append(cga.TokenNode({'text_line': 'line2'})) tokens = [ { 'text_line': '' }, { 'h2': '##' }, { 'text_line': 'error info' }, { 'code_start': '```' }, { 'text_line': 'line1' }, { 'text_line': 'line2' }, { 'code_end': '```' }, { 'text_line': '' }, ] self.assertEqual(str(tokens), str(info_block)) self.assertListEqual(tokens, info_block.tokens)
def test_hunt(self): node_list = cga.make_token_list(self.md) prey = parser.hunt(node_list) block = parser.CodeBlock(parser.CODE_TYPE.C) block.append(cga.TokenNode({'code_start': '```c'})) block.append(cga.TokenNode({'text_line': 'int main() {'})) block.append(cga.TokenNode({'text_line': ' return 0'})) block.append(cga.TokenNode({'text_line': '}'})) block.append(cga.TokenNode({'code_end': '```'})) expect = [block] for f, s in zip(expect, prey): self.assertEqual(f, s)
def test_make_token_list(self): tokens = [{ 'h2': '##' }, { 'text_line': 'this is h2' }, { 'code_start': '```c' }, { 'text_line': 'int main() {' }, { 'text_line': ' return 0;' }, { 'text_line': '}' }, { 'code_end': '```' }] expected = [cga.TokenNode(i) for i in tokens] for i in range(len(expected) - 1): expected[i].next = expected[i + 1] nodelist = cga.make_token_list(tokens) self.assertListEqual(expected, nodelist)
def test_val(self): node = cga.TokenNode({'h1': 'the h1 title'}) self.assertEqual('the h1 title', node.val)
def test_key(self): node = cga.TokenNode({'h1': 'the h1 title'}) self.assertEqual('h1', node.key)
def test_get(self): node = cga.TokenNode({'h1': 'the h1 title'}) self.assertEqual('the h1 title', node.get('h1'))
def test_next(self): headnode = cga.TokenNode({'h1': 'the h1 title'}) nextnode = cga.TokenNode({'text_line': 'here is text'}) headnode.next = nextnode self.assertIs(headnode.next, nextnode)