Skip to content

Commit

Permalink
Add test for noGrammar (see #218)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Dec 5, 2018
1 parent 57cfba0 commit 2f0ee11
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public static void testDiagnosticsFor(String xml, String catalogPath, Diagnostic

public static void testDiagnosticsFor(String xml, String catalogPath, Consumer<XMLLanguageService> configuration,
String fileURI, Diagnostic... expected) {
testDiagnosticsFor(xml, catalogPath, configuration, fileURI, true, expected);
}

public static void testDiagnosticsFor(String xml, String catalogPath, Consumer<XMLLanguageService> configuration,
String fileURI, boolean filter, Diagnostic... expected) {
TextDocument document = new TextDocument(xml, fileURI != null ? fileURI : "test.xml");

XMLLanguageService xmlLanguageService = new XMLLanguageService();
Expand All @@ -257,7 +262,7 @@ public static void testDiagnosticsFor(String xml, String catalogPath, Consumer<X

List<Diagnostic> actual = xmlLanguageService.doDiagnostics(xmlDocument, () -> {
});
assertDiagnostics(actual, expected);
assertDiagnostics(actual, Arrays.asList(expected), filter);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* 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 <[email protected]> - initial API and implementation
*/
package org.eclipse.lsp4xml.extensions.catalog;

import static org.eclipse.lsp4xml.XMLAssert.c;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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 <[email protected]> - initial API and implementation
*/
package org.eclipse.lsp4xml.extensions.contentmodel;

import static org.eclipse.lsp4xml.XMLAssert.r;

import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4xml.XMLAssert;
import org.eclipse.lsp4xml.commons.BadLocationException;
import org.eclipse.lsp4xml.extensions.contentmodel.settings.ContentModelSettings;
import org.eclipse.lsp4xml.extensions.contentmodel.settings.XMLProblems;
import org.junit.Test;

/**
* XML problems like noGrammar.
*
*/
public class XMLProblemsTest {

@Test
public void noGrammarIgnore() throws BadLocationException {
String xml = "<root /> ";
XMLAssert.testDiagnosticsFor(xml);
}

@Test
public void noGrammarHint() throws BadLocationException {
String xml = "<root /> ";
// Set noGrammar has 'hint'
XMLAssert.testDiagnosticsFor(xml, null, ls -> {
ContentModelSettings settings = new ContentModelSettings();
XMLProblems problems = new XMLProblems();
problems.setNoGrammar("hint");
settings.setProblems(problems);
ls.doSave(new XMLAssert.SettingsSaveContext(settings));
}, null, false, new Diagnostic(r(0, 1, 0, 5), "No grammar constraints (DTD or XML Schema).",
DiagnosticSeverity.Hint, "test.xml", "XML"));
}
}

0 comments on commit 2f0ee11

Please sign in to comment.