示例#1
0
    def test_parse_quoted_list_item_containing_multiple_items(self):
        givenAst = ast.Ast()
        result = givenAst.parse("set(TabsPls_Source " \
                + "\"anything can be put here, and it will be only one item, even with a ${variable}\"\n"
                + "main.cpp\n" \
                + "${other_var}\n" \
                + "\"${another_var_in_quotes}\"\n" \
                + "#a comment that will be ignored\n" \
                + '"a complete line with only text"\n' \
                + ")"
                )

        expected_result = ast.SetNormalVariable(
            "TabsPls_Source",
            ast.CMakeStringList([
                ast.ListItemString(
                    "\"anything can be put here, and it will be only one item, even with a ${variable}\""
                ),
                ast.ListItemString("main.cpp"),
                ast.VariableUse("other_var"),
                ast.VariableUse("another_var_in_quotes"),
                ast.ListItemString('"a complete line with only text"')
            ]))

        self.assertTrue(list(result)[0].is_same(expected_result))
示例#2
0
    def test_parse_set_normal_variable(self):
        givenAst = ast.Ast()
        result = givenAst.parse("set(TabsPls_Source main.cpp)")

        expected_result = ast.SetNormalVariable(
            "TabsPls_Source",
            ast.CMakeStringList([ast.ListItemString("main.cpp")]))

        self.assertTrue(list(result)[0].is_same(expected_result))
示例#3
0
    def test_parse_set_normal_variable_using_other_variable_in_quotes(self):
        givenAst = ast.Ast()
        result = givenAst.parse("set(TabsPls_Source \"${other_var}\")")

        expected_result = ast.SetNormalVariable(
            "TabsPls_Source",
            ast.CMakeStringList([ast.VariableUse("other_var")]))

        self.assertTrue(list(result)[0].is_same(expected_result))
示例#4
0
    def test_scan_all_complete_project_source(self):
        given_source = (
            "project(TabsPls)\n" + "\tset(TabsPls_Headers File.hpp\n" +
            "Directory.hpp\n" + ")\n\n" + "set(TabsPls_Sources File.cpp\n" +
            "\tDirectory.cpp\n" + "\tMain.cpp\n" + ")\n\n" +
            "add_executable(TabsPls ${TabsPls_Headers} ${TabsPls_Sources})\n\n"
            + "target_sources(TabsPls PRIVATE windows_util.h windows_util.c)")

        given_ast = ast.Ast()
        matches = given_ast.scan_all(given_source)
        self.assertEqual(len(matches), 4)

        expected_first_match = ast.SetNormalVariable(
            "TabsPls_Headers",
            ast.CMakeStringList([
                ast.ListItemStringWithLocation("File.hpp", 38),
                ast.ListItemStringWithLocation("Directory.hpp", 47)
            ]))
        self.assertTrue(list(matches[0])[0].is_same(expected_first_match))

        expected_second_match = ast.SetNormalVariable(
            "TabsPls_Sources",
            ast.CMakeStringList([
                ast.ListItemStringWithLocation("File.cpp", 84),
                ast.ListItemStringWithLocation("Directory.cpp", 94),
                ast.ListItemStringWithLocation("Main.cpp", 109)
            ]))
        self.assertTrue(list(matches[1])[0].is_same(expected_second_match))

        expected_third_match = ast.AddExecutable(
            "TabsPls",
            ast.CMakeStringList([
                ast.VariableUseWithLocation("TabsPls_Headers", 144),
                ast.VariableUseWithLocation("TabsPls_Sources", 163)
            ]))
        self.assertTrue(list(matches[2])[0].is_same(expected_third_match))

        expected_fourth_match = ast.TargetSources(
            "TabsPls",
            ast.CMakeStringList([
                ast.ListItemStringWithLocation("windows_util.h", 215),
                ast.ListItemStringWithLocation("windows_util.c", 230)
            ]))
        self.assertTrue(list(matches[3])[0].is_same(expected_fourth_match))
示例#5
0
    def test_parse_quoted_list_item_containing_variable_use(self):
        givenAst = ast.Ast()
        result = givenAst.parse(
            "set(TabsPls_Source \"anything can be put here, and it will be only one item, even with a ${variable}\")"
        )

        expected_result = ast.SetNormalVariable(
            "TabsPls_Source",
            ast.CMakeStringList([
                ast.ListItemString(
                    "\"anything can be put here, and it will be only one item, even with a ${variable}\""
                )
            ]))

        self.assertTrue(list(result)[0].is_same(expected_result))