From d88d4c7cb9e09dbe9819307c10c7269417f6c692 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 | 16 ++++++ .../tests/templating/fixtures/test.html.twig | 5 ++ 3 files changed, 50 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..5df643ad0 --- /dev/null +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/fixtures/ide-twig.json @@ -0,0 +1,16 @@ +{ + "namespaces": [ + { + "namespace": "foo", + "path": "res" + }, + { + "path": "res" + }, + { + "type": "Bundle", + "namespace": "FooBundle", + "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