예제 #1
0
    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)
예제 #2
0
 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)
예제 #3
0
    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)
예제 #4
0
 def test_val(self):
     node = cga.TokenNode({'h1': 'the h1 title'})
     self.assertEqual('the h1 title', node.val)
예제 #5
0
 def test_key(self):
     node = cga.TokenNode({'h1': 'the h1 title'})
     self.assertEqual('h1', node.key)
예제 #6
0
 def test_get(self):
     node = cga.TokenNode({'h1': 'the h1 title'})
     self.assertEqual('the h1 title', node.get('h1'))
예제 #7
0
    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)