From 57e7b2c5331d8f951176f758fda09b845e45010b Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Mon, 11 Apr 2022 12:15:27 +0200 Subject: [PATCH] provide more tests for incomplete completion --- ...TwigTemplateCompletionContributorTest.java | 53 ++++++++++--------- .../tests/templating/fixtures/ide-twig.json | 7 +++ .../tests/templating/fixtures/test.html.twig | 5 ++ 3 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/ide-twig.json create mode 100644 src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/test.html.twig diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/TwigTemplateCompletionContributorTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/TwigTemplateCompletionContributorTest.java index 595017d38..6d98af06a 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/TwigTemplateCompletionContributorTest.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/TwigTemplateCompletionContributorTest.java @@ -1,14 +1,8 @@ package fr.adrienbrault.idea.symfony2plugin.tests.templating; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.patterns.PlatformPatterns; import com.jetbrains.twig.TwigFileType; import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; /** * @author Daniel Espendiller @@ -21,6 +15,9 @@ public void setUp() throws Exception { myFixture.copyFileToProject("classes.php"); myFixture.copyFileToProject("TwigTemplateCompletionContributorTest.php"); myFixture.copyFileToProject("routing.xml"); + + myFixture.copyFileToProject("ide-twig.json", "ide-twig.json"); + myFixture.copyFileToProject("test.html.twig", "res/test.html.twig"); } public String getTestDataPath() { @@ -129,23 +126,31 @@ public void testThatIncompleteForStatementIsCompletedWithVariables() { ); } - private void createWorkaroundFile(@NotNull String file, @NotNull String content) { - - try { - createDummyFiles(file); - } catch (Exception e) { - e.printStackTrace(); - } - - // build pseudo file with block - final VirtualFile relativeFile = VfsUtil.findRelativeFile(getProject().getBaseDir(), file.split("/")); - ApplicationManager.getApplication().runWriteAction(() -> { - try { - relativeFile.setBinaryContent(content.getBytes()); - } catch (IOException e2) { - e2.printStackTrace(); - } - relativeFile.refresh(false, false); - }); + public void testThatIncompleteExtendsStatementIsCompleted() { + assertCompletionContains(TwigFileType.INSTANCE, "" + + "{% ext %}\n", + "extends 'test.html.twig'" + ); + } + + public void testThatIncompleteIncludeStatementIsCompleted() { + assertCompletionContains(TwigFileType.INSTANCE, "" + + "{% inc %}\n", + "include 'test.html.twig'" + ); + } + + public void testThatIncompleteEmbedStatementIsCompleted() { + assertCompletionContains(TwigFileType.INSTANCE, "" + + "{% emb %}\n", + "embed 'test.html.twig'" + ); + } + + public void testThatIncompleteIncludePrintIsCompleted() { + assertCompletionContains(TwigFileType.INSTANCE, "" + + "{{ inc }}\n", + "include('test.html.twig')" + ); } } diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/ide-twig.json b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/ide-twig.json new file mode 100644 index 000000000..f110c6b6b --- /dev/null +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/ide-twig.json @@ -0,0 +1,7 @@ +{ + "namespaces": [ + { + "path": "res" + } + ] +} \ No newline at end of file diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/test.html.twig b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/test.html.twig new file mode 100644 index 000000000..6f4729cc2 --- /dev/null +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/test.html.twig @@ -0,0 +1,5 @@ +{% include 'test.html.twig' %} + +{% embed 'test.html.twig' %} + +{% block test %}{% endblock %} \ No newline at end of file