Skip to content

Commit

Permalink
Add testcase for cdata not working
Browse files Browse the repository at this point in the history
See #1694

Signed-off-by: Christoph Läubrich <[email protected]>
  • Loading branch information
laeubi committed Nov 7, 2024
1 parent 830e00d commit 64f111b
Showing 1 changed file with 93 additions and 0 deletions.
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);
}

}

0 comments on commit 64f111b

Please sign in to comment.