Example #1
0
 def test_path_aware_list_item_string_equality(self):
     given_reference_source = "header.h"
     given_cmake_string_list_item = "include/testlib/header.h"
     self.assertEqual(
         list_item_string_path.PathAwareListItemString(
             given_reference_source), given_cmake_string_list_item)
     given_cmake_string_list_item = "include/testlib/other_header.h"
     self.assertNotEqual(
         list_item_string_path.PathAwareListItemString(
             given_reference_source), given_cmake_string_list_item)
    def test_insert_next_to_other_source_directly_at_target_using_path_aware_reference(
            self):
        given_ast = ast.Ast()
        given_source = "add_executable(TabsPls Main.cpp)"
        given_cmake_ast = given_ast.parse(given_source)

        insert_action = source_inserter.insert_source_item_next_to_other_source(
            given_cmake_ast, "file.cpp",
            list_item_string_path.PathAwareListItemString("Main.cpp"))
        self.assertEqual(insert_action.position, 31)
        self.assertEqual(insert_action.content, " file.cpp")
        self.assertEqual(insert_action.do(given_source),
                         "add_executable(TabsPls Main.cpp file.cpp)")
Example #3
0
def _insert_single_source_next_to_reference_in_full_cmake_source(
        full_cmake_source, source_item, reference_source_item):
    full_cmake_ast = _parse_cmakelists_contents(full_cmake_source)

    reference_source_item = _make_reference_path_aware_if_needed(
        reference_source_item)

    inserter_with_reference = source_inserter._make_inserter_for_item_next_to_other_source(
        full_cmake_ast,
        list_item_string_path.PathAwareListItemString(reference_source_item))
    try:
        insert_action = source_inserter.insert_source_considering_existing_whitespace(
            inserter_with_reference, source_item, full_cmake_source)
        return insert_action.do(full_cmake_source)
    except source_inserter.SourceInserterException as e:
        raise CMakeClassCreatorException(str(e))
Example #4
0
def create_class(cmakelists_path, class_name, reference_class_name):
    full_cmake_source = _read_cmakelists_contents(cmakelists_path)

    full_cmake_ast = _parse_cmakelists_contents(full_cmake_source)

    try:
        header_and_implementation_actions = class_inserter.insert_class_next_to_other_class_with_whitespace_enhancement(
            full_cmake_source, full_cmake_ast, class_name,
            list_item_string_path.PathAwareListItemString(
                reference_class_name))
    except class_inserter.ClassInserterException as e:
        raise CMakeClassCreatorException(str(e))

    full_cmake_source = _do_all_actions(
        list(header_and_implementation_actions), full_cmake_source)
    return full_cmake_source
Example #5
0
 def test_path_aware_list_item_string_append_string(self):
     given_reference_source = "class"
     self.assertEqual(
         list_item_string_path.PathAwareListItemString(
             given_reference_source) + ".h", "class.h")
Example #6
0
 def test_path_aware_list_item_string_to_string(self):
     given_reference_source = "header.h"
     path_aware_reference = list_item_string_path.PathAwareListItemString(
         given_reference_source)
     self.assertEqual(str(path_aware_reference), "header.h")
Example #7
0
def _make_reference_path_aware_if_needed(reference_source_item):
    return reference_source_item \
        if not list_item_string_path.is_cmake_path(reference_source_item) \
            else list_item_string_path.PathAwareListItemString(reference_source_item)