-
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.
See #1694 Signed-off-by: Christoph Läubrich <[email protected]>
- Loading branch information
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...inx/src/test/java/org/eclipse/lemminx/services/extensions/XMLCompletionExtensionTest.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,93 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Christoph Läubrich 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: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.lemminx.services.extensions; | ||
|
||
import org.eclipse.lemminx.AbstractCacheBasedTest; | ||
import org.eclipse.lemminx.XMLAssert; | ||
import org.eclipse.lemminx.commons.BadLocationException; | ||
import org.eclipse.lemminx.services.XMLLanguageService; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionParticipant; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionRequest; | ||
import org.eclipse.lemminx.services.extensions.completion.ICompletionResponse; | ||
import org.eclipse.lsp4j.CompletionItem; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* XML completion tests which uses the {@link ICompletionParticipant} | ||
*/ | ||
public class XMLCompletionExtensionTest extends AbstractCacheBasedTest { | ||
|
||
private static final CompletionItem HELLO_WORLD_ITEM = XMLAssert.c("World", "World"); | ||
|
||
private final class TestCompletionParticipant implements ICompletionParticipant { | ||
@Override | ||
public void onXMLContent(ICompletionRequest request, ICompletionResponse response, CancelChecker cancelChecker) | ||
throws Exception { | ||
System.out.println("onXMLContent: " + request.getCurrentTag()); | ||
if (request.getCurrentTag().equals("hello")) { | ||
response.addCompletionAttribute(HELLO_WORLD_ITEM); | ||
} | ||
} | ||
|
||
@Override | ||
public void onTagOpen(ICompletionRequest completionRequest, ICompletionResponse completionResponse, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onDTDSystemId(String valuePrefix, ICompletionRequest request, ICompletionResponse response, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onAttributeValue(String valuePrefix, ICompletionRequest request, ICompletionResponse response, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
|
||
@Override | ||
public void onAttributeName(boolean generateValue, ICompletionRequest request, ICompletionResponse response, | ||
CancelChecker cancelChecker) throws Exception { | ||
} | ||
} | ||
|
||
/** | ||
* Test that | ||
* {@link ICompletionParticipant#onXMLContent(ICompletionRequest, ICompletionResponse, CancelChecker)} | ||
* is called for a simple content tag | ||
* | ||
* @throws BadLocationException | ||
*/ | ||
@Test | ||
public void testSimpleCompletion() throws BadLocationException { | ||
XMLLanguageService service = new XMLLanguageService(); | ||
service.registerCompletionParticipant(new TestCompletionParticipant()); | ||
XMLAssert.testCompletionFor(service, "<hello>|</hello>", (String) null, null, null, null, true, | ||
HELLO_WORLD_ITEM); | ||
} | ||
|
||
/** | ||
* Test that | ||
* {@link ICompletionParticipant#onXMLContent(ICompletionRequest, ICompletionResponse, CancelChecker)} | ||
* is called for a CDATA content tag | ||
* | ||
* @throws BadLocationException | ||
*/ | ||
@Test | ||
public void testCDATACompletion() throws BadLocationException { | ||
XMLLanguageService service = new XMLLanguageService(); | ||
service.registerCompletionParticipant(new TestCompletionParticipant()); | ||
XMLAssert.testCompletionFor(service, "<hello><![CDATA[|]]></hello>", (String) null, null, null, null, true, | ||
HELLO_WORLD_ITEM); | ||
} | ||
|
||
} |