-
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.
DOCTYPE entities interfering with hover annotation display of tags /
attributes. Fixes redhat-developer/vscode-xml#716 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
c0eec05
commit 3d10a3a
Showing
3 changed files
with
114 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
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
89 changes: 89 additions & 0 deletions
89
...c/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLFileAssociationsHoverTest.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,89 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Red Hat Inc. 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: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.extensions.contentmodel; | ||
|
||
import static org.eclipse.lemminx.XMLAssert.r; | ||
|
||
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.extensions.contentmodel.settings.ContentModelSettings; | ||
import org.eclipse.lemminx.extensions.contentmodel.settings.XMLFileAssociation; | ||
import org.eclipse.lemminx.services.XMLLanguageService; | ||
import org.eclipse.lsp4j.Range; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* XML hover tests with file association. | ||
* | ||
*/ | ||
public class XMLFileAssociationsHoverTest { | ||
|
||
@Test | ||
public void hoverBasedOnXSDWithFileAssociation() throws BadLocationException, MalformedURIException { | ||
ContentModelSettings modelSettings = new ContentModelSettings(); | ||
modelSettings.setFileAssociations(createXSDAssociationsSchemaLocationLike("src/test/resources/xsd/")); | ||
|
||
String schemaURI = getXMLSchemaFileURI("maven-4.0.0.xsd"); | ||
String xml = "<pro|ject xmlns=\"http://maven.apache.org/POM/4.0.0\"\r\n>\r\n" + // | ||
"</project>"; | ||
assertHover(xml, "file:///test/pom.xml", modelSettings, "3.0.0+" + // | ||
System.lineSeparator() + // | ||
System.lineSeparator() + // | ||
"The `<project>` element is the root of the descriptor. The following table lists all of the possible child elements." | ||
+ // | ||
System.lineSeparator() + // | ||
System.lineSeparator() + // | ||
"Source: [maven-4.0.0.xsd](" + schemaURI + ")", r(0, 1, 0, 8)); | ||
} | ||
|
||
@Test | ||
public void hoverBasedOnXSDWithFileAssociationAndDocType() throws BadLocationException, MalformedURIException { | ||
ContentModelSettings modelSettings = new ContentModelSettings(); | ||
modelSettings.setFileAssociations(createXSDAssociationsSchemaLocationLike("src/test/resources/xsd/")); | ||
|
||
String schemaURI = getXMLSchemaFileURI("maven-4.0.0.xsd"); | ||
String xml = "<!DOCTYPE opt [\r\n" + // | ||
" <!ENTITY size \"short\">\r\n" + // | ||
"]>\r\n" + // | ||
"<pro|ject xmlns=\"http://maven.apache.org/POM/4.0.0\"\r\n>\r\n" + // | ||
"</project>"; | ||
assertHover(xml, "file:///test/pom.xml", modelSettings, "3.0.0+" + // | ||
System.lineSeparator() + // | ||
System.lineSeparator() + // | ||
"The `<project>` element is the root of the descriptor. The following table lists all of the possible child elements." | ||
+ // | ||
System.lineSeparator() + // | ||
System.lineSeparator() + // | ||
"Source: [maven-4.0.0.xsd](" + schemaURI + ")", r(3, 1, 3, 8)); | ||
} | ||
|
||
private static XMLFileAssociation[] createXSDAssociationsSchemaLocationLike(String baseSystemId) { | ||
XMLFileAssociation maven = new XMLFileAssociation(); | ||
maven.setPattern("**/pom.xml"); | ||
maven.setSystemId(baseSystemId + "maven-4.0.0.xsd"); | ||
return new XMLFileAssociation[] { maven }; | ||
} | ||
|
||
private static void assertHover(String value, String fileURI, ContentModelSettings modelSettings, | ||
String expectedHoverLabel, Range expectedHoverRange) throws BadLocationException { | ||
XMLAssert.assertHover(new XMLLanguageService(), value, null, fileURI, expectedHoverLabel, expectedHoverRange, | ||
modelSettings); | ||
} | ||
|
||
private static String getXMLSchemaFileURI(String schemaURI) throws MalformedURIException { | ||
return XMLEntityManager.expandSystemId("xsd/" + schemaURI, "src/test/resources/test.xml", true).replace("///", | ||
"/"); | ||
} | ||
|
||
} |