Exemplo n.º 1
0
def test_free_parser():
    """
    HelloWorld.cbl and HelloWorldFree.cbl must have the same ast.
    """
    with open('test/testfiles/HelloWorld.cbl') as f:
        content = f.read()
    non_free_ast, non_free_vars, non_free_procs = parser.defined_names(content)
    with open('test/testfiles/HelloWorldFree.cbl') as f:
        content = f.read()
    free_ast, free_vars, free_procs = parser.defined_names(content,
                                                           free_format=True)
    result = parser.cmp_name(non_free_ast, free_ast)
    assert result
Exemplo n.º 2
0
def test_free_parser():
    """
    HelloWorld.cbl and HelloWorldFree.cbl must have the same ast.
    """
    with open('test/testfiles/HelloWorld.cbl') as f:
        content = f.read()
    non_free_ast, non_free_vars, non_free_procs = parser.defined_names(content)
    with open('test/testfiles/HelloWorldFree.cbl') as f:
        content = f.read()
    free_ast, free_vars, free_procs = parser.defined_names(
        content, free_format=True)
    result = parser.cmp_name(non_free_ast, free_ast)
    assert result
Exemplo n.º 3
0
def test_copy_book():
    with open('test/testfiles/test.cpy') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 8 variables
    assert len(vars) == 21
    assert vars[0].name == 'txt-lower'
Exemplo n.º 4
0
 def complete(self, code, *_):
     global free_format, lower_case_keywords
     completions = []
     try:
         root, vars, functions = defined_names(
             code, free_format=free_format)
     except AttributeError:
         vars = []
         functions = []
     for var in vars:
         completions.append({
             'name': var.name,
             'icon': icons.ICON_VAR,
             'tooltip': var.description
         })
     for func in functions:
         completions.append({
             'name': func.name,
             'icon': icons.ICON_FUNC
         })
     if lower_case_keywords:
         completions += [{'name': k['name'].lower(), 'icon': k['icon']}
                         for k in self._kwds]
     else:
         completions += self._kwds
     return completions
Exemplo n.º 5
0
 def complete(self, code, *_):
     global free_format, lower_case_keywords
     completions = []
     try:
         root, vars, functions = defined_names(
             code, free_format=free_format)
     except AttributeError:
         vars = []
         functions = []
     for var in vars:
         completions.append({
             'name': var.name,
             'icon': icons.ICON_VAR,
             'tooltip': var.description
         })
     for func in functions:
         completions.append({
             'name': func.name,
             'icon': icons.ICON_FUNC
         })
     if lower_case_keywords:
         completions += [{'name': k['name'].lower(), 'icon': k['icon']}
                         for k in self._kwds]
     else:
         completions += self._kwds
     return completions
Exemplo n.º 6
0
def test_copy_book():
    with open('test/testfiles/test.cpy') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 8 variables
    assert len(vars) == 21
    assert vars[0].name == 'txt-lower'
Exemplo n.º 7
0
def test_lvl88():
    """
    See OpenCobolIDE/OpenCobolIDE#95, first comment
    """
    with open('test/testfiles/TEST_LVL_88.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    assert len(vars) == 10
Exemplo n.º 8
0
def test_lvl88():
    """
    See OpenCobolIDE/OpenCobolIDE#95, first comment
    """
    with open('test/testfiles/TEST_LVL_88.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    assert len(vars) == 10
Exemplo n.º 9
0
def test_structure():
    # see OpenCobolIDE/OpenCobolIDE#336
    with open('test/testfiles/structure.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)

    l5_1_node = ast.children[0].children[0].children[0].children[0].children[1]
    assert len(l5_1_node.children) == 2
Exemplo n.º 10
0
def test_variables():
    """
    Virtual printer must have 8 vars
    """
    with open('test/testfiles/VIRTUAL-PRINTER.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 8 variables
    assert len(vars) == 8
Exemplo n.º 11
0
def test_paragraphes():
    """
    Test printer must have 2 procedures
    """
    with open('test/testfiles/TEST-PRINTER.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 1 procedure
    assert len(procs) == 2
Exemplo n.º 12
0
def test_variables():
    """
    Virtual printer must have 8 vars
    """
    with open('test/testfiles/VIRTUAL-PRINTER.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 8 variables
    assert len(vars) == 8
Exemplo n.º 13
0
def test_paragraphes():
    """
    Test printer must have 2 procedures
    """
    with open('test/testfiles/TEST-PRINTER.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 1 procedure
    assert len(procs) == 2
Exemplo n.º 14
0
def test_malformed():
    """
    Parses the hello world example
    """
    with open('test/testfiles/MALFORMED.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 4 divs
    assert len(ast.children) == 4
    # 2 sections in env div
    assert len(ast.children[0].children) == 2
    # 2 sections in data div
    assert len(ast.children[1].children) == 3
    assert len(vars) == 3
    assert len(procs) == 1
Exemplo n.º 15
0
def test_parse_names():
    """
    Parses the hello world example
    """
    with open('test/testfiles/HelloWorld.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 4 divs
    assert len(ast.children) == 4
    # 2 sections in env div
    assert len(ast.children[1].children) == 2
    # 2 sections in data div
    assert len(ast.children[2].children) == 2
    assert len(vars) == 0
    assert len(procs) == 1
Exemplo n.º 16
0
def test_parse_pco():
    """
    Parses a pco file, which contains characters in column 1-6 (see bug #23)
    """
    with open('test/testfiles/HelloWorld.pco') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 4 divs
    assert len(ast.children) == 4
    # 2 sections in env div
    assert len(ast.children[1].children) == 2
    # 2 sections in data div
    assert len(ast.children[2].children) == 2
    assert len(vars) == 0
    assert len(procs) == 1
Exemplo n.º 17
0
def test_parse_pco():
    """
    Parses a pco file, which contains characters in column 1-6 (see bug #23)
    """
    with open('test/testfiles/HelloWorld.pco') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 4 divs
    assert len(ast.children) == 4
    # 2 sections in env div
    assert len(ast.children[1].children) == 2
    # 2 sections in data div
    assert len(ast.children[2].children) == 2
    assert len(vars) == 0
    assert len(procs) == 1
Exemplo n.º 18
0
def test_malformed():
    """
    Parses the hello world example
    """
    with open('test/testfiles/MALFORMED.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 4 divs
    assert len(ast.children) == 4
    # 2 sections in env div
    assert len(ast.children[0].children) == 2
    # 2 sections in data div
    assert len(ast.children[1].children) == 3
    assert len(vars) == 3
    assert len(procs) == 1
Exemplo n.º 19
0
def test_parse_names():
    """
    Parses the hello world example
    """
    with open('test/testfiles/HelloWorld.cbl') as f:
        content = f.read()
    ast, vars, procs = parser.defined_names(content)
    # 4 divs
    assert len(ast.children) == 4
    # 2 sections in env div
    assert len(ast.children[1].children) == 2
    # 2 sections in data div
    assert len(ast.children[2].children) == 2
    assert len(vars) == 0
    assert len(procs) == 1
Exemplo n.º 20
0
 def complete(self, code, line, column, completionPrefix,
              file_path, file_encoding):
     global free_format
     completions = []
     try:
         root, vars, functions = defined_names(
             code, free_format=free_format)
     except AttributeError:
         vars = []
         functions = []
     for var in vars:
         completions.append({
             'name': var.name,
             'icon': icons.ICON_VAR,
             'tooltip': var.description
         })
     for func in functions:
         completions.append({
             'name': func.name,
             'icon': icons.ICON_FUNC
         })
     completions += self.__keywordsCompletions
     return completions
Exemplo n.º 21
0
def get_outline(data):
    if free_format is None:
        return None
    else:
        root_node, _, _ = defined_names(data['code'], free_format)
        return [ch.to_definition().to_dict() for ch in root_node.children]
Exemplo n.º 22
0
def get_outline(data):
    root_node, _, _ = defined_names(data['code'], free_format)
    return [ch.to_definition().to_dict() for ch in root_node.children]