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)
예제 #2
0
    def test_get_xml_context_returns_context_with_expected_node(
        self,
        fake_xsd_tree: XsdTree,
        source_with_mark: str,
        expected_token_name: Optional[str],
        expected_node_type: NodeType,
        expected_xsd_node_name: XsdNode,
        expected_stack: List[str],
    ) -> None:
        service = XmlContextService(fake_xsd_tree)
        position, source = TestUtils.extract_mark_from_source(
            "^", source_with_mark)
        xml_document = TestUtils.from_source_to_xml_document(source)
        print(fake_xsd_tree.render())
        print(
            f"Test context at position [line={position.line}, char={position.character}]"
        )
        print(f"Document:\n{xml_document.document.source}")

        context = service.get_xml_context(xml_document, position)

        assert context
        assert context.node
        assert context.node.name == expected_token_name
        assert context.node.node_type == expected_node_type
        assert context.stack == expected_stack
        if expected_xsd_node_name is None:
            assert context.xsd_element is None
        else:
            assert context.xsd_element
            assert context.xsd_element.name == expected_xsd_node_name
예제 #3
0
    def test_get_xml_context_returns_empty_document_context(
            self, mocker: MockerFixture) -> None:
        empty_xml_content = ""
        position = Position(line=0, character=0)
        xsd_tree_mock = mocker.Mock()
        service = XmlContextService(xsd_tree_mock)

        context = service.get_xml_context(
            TestUtils.from_source_to_xml_document(empty_xml_content), position)

        assert context.is_empty
예제 #4
0
    def test_context_returns_expected_is_attribute_end(
        self,
        fake_xsd_tree: XsdTree,
        source_with_mark: str,
        is_attribute_end: bool,
    ) -> None:
        service = XmlContextService(fake_xsd_tree)
        position, source = TestUtils.extract_mark_from_source(
            "^", source_with_mark)
        xml_document = TestUtils.from_source_to_xml_document(source)

        context = service.get_xml_context(xml_document, position)

        assert context.is_attribute_end == is_attribute_end
예제 #5
0
    def test_get_range_for_context_attribute_returns_expected_offsets(
        self,
        fake_xsd_tree: XsdTree,
        source_with_mark: str,
        expected_token_name: Optional[str],
        expected_offsets: Tuple[int, int],
    ) -> None:
        service = XmlContextService(fake_xsd_tree)
        position, source = TestUtils.extract_mark_from_source(
            "^", source_with_mark)
        xml_document = TestUtils.from_source_to_xml_document(source)
        context = service.get_xml_context(xml_document, position)

        actual_offsets = service.get_range_for_context(xml_document, context)

        assert context.node
        assert context.node.name == expected_token_name
        assert actual_offsets == expected_offsets
예제 #6
0
def get_context_from_line_position(fake_tree: XsdTree, line: str, position: Position) -> XmlContext:
    return XmlContextService(fake_tree).get_xml_context(TestUtils.from_source_to_xml_document(line), position)
예제 #7
0
    def test_init_sets_properties(self, mocker: MockerFixture) -> None:
        expected = mocker.Mock()

        service = XmlContextService(expected)

        assert service.xsd_tree