def test_completion_on_macro_attribute_returns_expected(
        self,
        galaxy_xsd_tree: XsdTree,
        source_with_mark: str,
        expected_item_names: List[str],
        mocker: MockerFixture,
    ) -> None:
        position, source_without_mark = TestUtils.extract_mark_from_source(
            "^", source_with_mark)
        document = TestUtils.from_source_to_xml_document(source_without_mark)
        context_service = XmlContextService(galaxy_xsd_tree)
        context = context_service.get_xml_context(document, position)
        fake_completion_context = CompletionContext(
            trigger_kind=CompletionTriggerKind.Invoked)
        workspace = mocker.Mock()
        definitions_provider = DocumentDefinitionsProvider(
            MacroDefinitionsProvider(workspace))
        completion_service = XmlCompletionService(galaxy_xsd_tree,
                                                  definitions_provider)

        completion_result = completion_service.get_completion_at_context(
            context, fake_completion_context)

        assert completion_result
        assert sorted([item.label for item in completion_result.items
                       ]) == sorted(expected_item_names)
Example #2
0
    def test_return_empty_attribute_completion_when_empty_context(
        self,
        fake_tree: XsdTree,
        fake_empty_context,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        actual = service.get_attribute_completion(fake_empty_context)

        assert len(actual.items) == 0
Example #3
0
    def test_completion_return_root_node_when_empty_context(
        self,
        fake_tree: XsdTree,
        fake_empty_context,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        actual = service.get_node_completion(fake_empty_context)

        assert len(actual.items) == 1
        assert actual.items[0].label == fake_tree.root.name
Example #4
0
    def test_return_valid_completion_with_node_context(
        self,
        fake_tree: XsdTree,
        fake_context_on_root_node,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        actual = service.get_node_completion(fake_context_on_root_node)

        assert len(actual.items) == 2
        assert actual.items[0].label == fake_tree.root.children[0].name
        assert actual.items[1].label == "expand"
Example #5
0
    def test_auto_close_returns_none_when_expected(
        self,
        fake_tree: XsdTree,
        line_with_mark: str,
        trigger: str,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        service = XmlCompletionService(fake_tree, fake_definitions_provider)
        position, line = TestUtils.extract_mark_from_source("^", line_with_mark)
        fake_context = get_context_from_line_position(fake_tree, line, position)

        actual = service.get_auto_close_tag(fake_context, trigger)

        assert actual is None
Example #6
0
    def test_get_completion_at_context_inside_cdata_returns_none(
        self,
        fake_tree: XsdTree,
        fake_xml_doc: XmlDocument,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        fake_element = XmlCDATASection(0, 0)
        fake_context = XmlContext(fake_xml_doc, fake_tree.root, fake_element)
        fake_completion_context = CompletionContext(trigger_kind=CompletionTriggerKind.Invoked)
        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        actual = service.get_completion_at_context(fake_context, fake_completion_context)

        assert not actual
Example #7
0
    def test_auto_close_with_slash_returns_none_when_at_cdata(
        self,
        fake_tree: XsdTree,
        fake_xml_doc: XmlDocument,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        service = XmlCompletionService(fake_tree, fake_definitions_provider)
        trigger = "/"
        fake_node = XmlCDATASection(0, 0)
        fake_node.name = fake_tree.root.name
        fake_context = XmlContext(fake_xml_doc, fake_tree.root, fake_node)

        actual = service.get_auto_close_tag(fake_context, trigger)

        assert not actual
Example #8
0
    def test_return_valid_attribute_value_completion_when_enum_context(
        self,
        fake_tree: XsdTree,
        fake_xml_doc: XmlDocument,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        fake_attr = XmlAttribute("attr", 0, 0, XmlElement())
        fake_attr.set_value(None, 0, 0)
        fake_context = XmlContext(fake_xml_doc, fake_tree.root, fake_attr.value)

        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        actual = service.get_attribute_value_completion(fake_context)

        assert len(actual.items) == 2
Example #9
0
    def test_get_completion_at_context_with_open_tag_trigger_returns_expected_node(
        self,
        fake_tree: XsdTree,
        fake_xml_doc: XmlDocument,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        fake_context = XmlContext(fake_xml_doc, fake_tree.root, XmlElement())
        fake_completion_context = CompletionContext(trigger_kind=CompletionTriggerKind.TriggerCharacter, trigger_character="<")
        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        actual = service.get_completion_at_context(fake_context, fake_completion_context)

        assert actual
        assert len(actual.items) == 2
        assert actual.items[0].label == "child"
        assert actual.items[0].kind == CompletionItemKind.Class
        assert actual.items[1].label == "expand"
        assert actual.items[1].kind == CompletionItemKind.Class
Example #10
0
    def test_completion_node_reached_max_occurs_return_expected(
        self,
        fake_tree: XsdTree,
        fake_xml_doc: XmlDocument,
        fake_definitions_provider: DocumentDefinitionsProvider,
    ) -> None:
        fake_root = XmlElement()
        fake_root.name = fake_tree.root.name
        fake_root.end_tag_open_offset = 10
        fake_root.end_tag_close_offset = 15
        fake_child = XmlElement()
        fake_child.name = "child"
        fake_child.parent = fake_root
        fake_child = XmlElement()
        fake_child.parent = fake_root
        fake_context = XmlContext(fake_xml_doc, fake_tree.root, fake_root)
        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        actual = service.get_node_completion(fake_context)

        assert len(actual.items) == 1
        assert actual.items[0].label == "expand"
Example #11
0
    def test_init_sets_properties(self, fake_tree: XsdTree, fake_definitions_provider: DocumentDefinitionsProvider) -> None:

        service = XmlCompletionService(fake_tree, fake_definitions_provider)

        assert service.xsd_tree