-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checking base complex type for annotations
Signed-off-by: Matt Bowersox <m.bowersox@ibm.com>
- Loading branch information
1 parent
fd0cec5
commit 9827ac2
Showing
3 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...va/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaHoverExtendedComplexTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.contentmodel; | ||
|
||
import static org.eclipse.lemminx.XMLAssert.r; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.apache.xerces.impl.XMLEntityManager; | ||
import org.apache.xerces.util.URI.MalformedURIException; | ||
import org.eclipse.lemminx.XMLAssert; | ||
import org.eclipse.lemminx.commons.BadLocationException; | ||
import org.eclipse.lemminx.services.XMLLanguageService; | ||
import org.eclipse.lemminx.settings.SchemaDocumentationType; | ||
import org.eclipse.lemminx.settings.SharedSettings; | ||
import org.eclipse.lsp4j.HoverCapabilities; | ||
import org.eclipse.lsp4j.MarkupKind; | ||
import org.eclipse.lsp4j.Range; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class XMLSchemaHoverExtendedComplexTypeTest { | ||
|
||
@Test | ||
public void testHoverComplexTypeDocumentation() throws BadLocationException, MalformedURIException { | ||
String schemaURI = getXMLSchemaFileURI("extendedComplexType.xsd"); | ||
|
||
String xml = "<t|estType\n" + | ||
" xmlns=\"http://extendedComplexType\"\n" + | ||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + | ||
" xsi:schemaLocation=\"http://extendedComplexType xsd/extendedComplexType.xsd\">\n" + | ||
"</testType>\n"; | ||
|
||
String expected = "base type documentation value" + // | ||
System.lineSeparator() + // | ||
System.lineSeparator() + // | ||
"Source: [extendedComplexType.xsd](" + schemaURI + ")"; | ||
|
||
assertHover(xml, expected, r(0, 1, 0, 9)); | ||
} | ||
|
||
@Test | ||
public void testHoverExtendedComplexTypeDocumentation() throws BadLocationException, MalformedURIException { | ||
String schemaURI = getXMLSchemaFileURI("extendedComplexType.xsd"); | ||
|
||
String xml = "<e|xtendedTestType\n" + | ||
" xmlns=\"http://extendedComplexType\"\n" + | ||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + | ||
" xsi:schemaLocation=\"http://extendedComplexType xsd/extendedComplexType.xsd\">\n" + | ||
"</extendedTestType>\n"; | ||
|
||
String expected = "extending type documentation value" + // | ||
System.lineSeparator() + // | ||
System.lineSeparator() + // | ||
"base type documentation value" + // | ||
System.lineSeparator() + // | ||
System.lineSeparator() + // | ||
"Source: [extendedComplexType.xsd](" + schemaURI + ")"; | ||
|
||
assertHover(xml, expected, r(0, 1, 0, 17)); | ||
} | ||
|
||
private SharedSettings createSharedSettings(SchemaDocumentationType docSource, boolean markdownSupported) { | ||
SharedSettings settings = new SharedSettings(); | ||
if (markdownSupported) { | ||
HoverCapabilities capabilities = new HoverCapabilities(Arrays.asList(MarkupKind.MARKDOWN), false); | ||
settings.getHoverSettings().setCapabilities(capabilities); | ||
} | ||
settings.getPreferences() | ||
.setShowSchemaDocumentationType(docSource); | ||
return settings; | ||
} | ||
|
||
private static String getXMLSchemaFileURI(String schemaURI) throws MalformedURIException { | ||
return XMLEntityManager.expandSystemId("xsd/" + schemaURI, "src/test/resources/test.xml", true).replace("///", | ||
"/"); | ||
} | ||
|
||
private void assertHover(String xml, String expected, Range range) throws BadLocationException, MalformedURIException { | ||
XMLAssert.assertHover(new XMLLanguageService(), xml, null, "src/test/resources/extendedComplexType.xml", expected, range, // | ||
createSharedSettings(SchemaDocumentationType.documentation, true)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
org.eclipse.lemminx/src/test/resources/xsd/extendedComplexType.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<xs:schema elementFormDefault='qualified' xmlns:xs='http://www.w3.org/2001/XMLSchema'> | ||
<xs:complexType name='baseType'> | ||
<xs:annotation> | ||
<xs:documentation>base type documentation value</xs:documentation> | ||
<xs:appinfo>base type appinfo value</xs:appinfo> | ||
</xs:annotation> | ||
</xs:complexType> | ||
<xs:complexType name="extendingType"> | ||
<xs:complexContent> | ||
<xs:extension base="baseType"> | ||
<xs:annotation> | ||
<xs:documentation>extending type documentation value</xs:documentation> | ||
<xs:appinfo>extending type appinfo value</xs:appinfo> | ||
</xs:annotation> | ||
</xs:extension> | ||
</xs:complexContent> | ||
</xs:complexType> | ||
<xs:element name='testType' type='baseType'/> | ||
<xs:element name='extendedTestType' type='extendingType'/> | ||
</xs:schema> |