-
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.
Add XSD completion + validation tests (see #178)
- Loading branch information
1 parent
4a8b5bf
commit d3c8ef4
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/xsd/XSDCompletionExtensionsTest.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,41 @@ | ||
/** | ||
* Copyright (c) 2018 Angelo ZERR. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4xml.extensions.xsd; | ||
|
||
import static org.eclipse.lsp4xml.XMLAssert.c; | ||
import static org.eclipse.lsp4xml.XMLAssert.te; | ||
|
||
import org.eclipse.lsp4j.CompletionItem; | ||
import org.eclipse.lsp4xml.XMLAssert; | ||
import org.eclipse.lsp4xml.commons.BadLocationException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* XSD completion tests which test the {@link XDLURIResolverExtension}. | ||
* | ||
*/ | ||
public class XSDCompletionExtensionsTest { | ||
|
||
@Test | ||
public void completion() throws BadLocationException { | ||
// completion on | | ||
String xml = "<?xml version=\"1.1\"?>\r\n" | ||
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\"> \r\n" | ||
+ // | ||
"|"; | ||
testCompletionFor(xml, c("xs:annotation", te(2, 0, 2, 0, "<xs:annotation></xs:annotation>"), "xs:annotation"), | ||
c("xs:attribute", te(2, 0, 2, 0, "<xs:attribute name=\"\"></xs:attribute>"), "xs:attribute")); | ||
} | ||
|
||
private void testCompletionFor(String xml, CompletionItem... expectedItems) throws BadLocationException { | ||
XMLAssert.testCompletionFor(xml, null, expectedItems); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...lsp4xml/src/test/java/org/eclipse/lsp4xml/extensions/xsd/XSDValidationExtensionsTest.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,40 @@ | ||
/** | ||
* Copyright (c) 2018 Angelo ZERR. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4xml.extensions.xsd; | ||
|
||
import static org.eclipse.lsp4xml.XMLAssert.d; | ||
|
||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4xml.XMLAssert; | ||
import org.eclipse.lsp4xml.commons.BadLocationException; | ||
import org.eclipse.lsp4xml.extensions.contentmodel.participants.XMLSchemaErrorCode; | ||
import org.junit.Test; | ||
|
||
/** | ||
* XSL completion tests which test the {@link XDLURIResolverExtension}. | ||
* | ||
*/ | ||
public class XSDValidationExtensionsTest { | ||
|
||
@Test | ||
public void xsdInvalid() throws BadLocationException { | ||
String xml = "<?xml version=\"1.1\"?>\r\n" | ||
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\"> \r\n" | ||
+ // | ||
" <foo>bar</foo>\r\n" + // <- error foo doesn't exist | ||
"</xs:schema>"; | ||
testDiagnosticsFor(xml, d(2, 4, 2, 7, XMLSchemaErrorCode.cvc_complex_type_2_4_a)); | ||
} | ||
|
||
private void testDiagnosticsFor(String xml, Diagnostic... expected) throws BadLocationException { | ||
XMLAssert.testDiagnosticsFor(xml, expected); | ||
} | ||
} |