コード例 #1
0
ファイル: test_parser.py プロジェクト: Devecor/codebang
 def test_head_and_end(self):
     path = write2file(self.md)
     tokens = lex(path)
     node_list = cga.make_token_list(tokens)
     code_block = parser.CodeBlock(parser.CODE_TYPE.C)
     for i in node_list:
         code_block.append(i)
     self.assertEqual(node_list[0], code_block.head)
     self.assertEqual(node_list[-1], code_block.end)
コード例 #2
0
def execute_cga(i_file_path: str, o_file_path: str) -> None:
    tokens = ds.lex(i_file_path)
    node_list = make_token_list(tokens)
    all_code_block = parser.hunt(node_list)

    for code_block in all_code_block:
        info_block = ca.build_block(ca.gcc(code_block.code))
        parser.insert(code_block.end, info_block)

    gener.write_to_md(node_list, o_file_path)
コード例 #3
0
 def test_lex_with_text(self):
     md = '## this is h2\n  hello world!\nhappy tdd\n'
     file_path = write2file(md)
     act = ds.lex(file_path)
     expect = [{
         'h2': '##'
     }, {
         'text_line': 'this is h2'
     }, {
         'text_line': '  hello world!'
     }, {
         'text_line': 'happy tdd'
     }]
     self.assertListEqual(expect, act)
コード例 #4
0
ファイル: test_parser.py プロジェクト: Devecor/codebang
    def test_code(self):
        md = [
            '```c', 'int main() {', '    printf("hello!");', 'return 0;', '}',
            '```'
        ]
        path = write2file('\n'.join(md) + '\n')
        tokens = lex(path)
        node_list = cga.make_token_list(tokens)

        code_block = parser.CodeBlock(parser.CODE_TYPE.C)

        for i in node_list:
            code_block.append(i)

        self.assertEqual('int main() {\n    printf("hello!");\nreturn 0;\n}\n',
                         code_block.code)
コード例 #5
0
 def test_lex_with_code_block(self):
     md = '## this is h2\n```c\nint main() {\n    return 0;\n}\n```\n'
     file_path = write2file(md)
     act = ds.lex(file_path)
     expect = [{
         'h2': '##'
     }, {
         'text_line': 'this is h2'
     }, {
         'code_start': '```c'
     }, {
         'text_line': 'int main() {'
     }, {
         'text_line': '    return 0;'
     }, {
         'text_line': '}'
     }, {
         'code_end': '```'
     }]
     self.assertListEqual(expect, act)
コード例 #6
0
 def test_lex_with_headline(self):
     md = '# this is h1\n'
     file_path = write2file(md)
     act = ds.lex(file_path)
     expect = [{'h1': '#'}, {'text_line': 'this is h1'}]
     self.assertListEqual(expect, act)