From 7ce86a138eab0ed9fc4af0360b875c140d516cd9 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 14 Feb 2012 14:21:17 +0400 Subject: [PATCH] Added simple IDE templates test which checks that folding worked normally. --- idea/testData/templates/IdeTemplates.kt | 42 +++++++++++++ .../plugin/codeInsight/IdeTemplatesTest.java | 63 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 idea/testData/templates/IdeTemplates.kt create mode 100644 idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java diff --git a/idea/testData/templates/IdeTemplates.kt b/idea/testData/templates/IdeTemplates.kt new file mode 100644 index 00000000000..f13e6d27dfb --- /dev/null +++ b/idea/testData/templates/IdeTemplates.kt @@ -0,0 +1,42 @@ +fun main(args : Array) { + if (<##>) { + <##> + } else { + <##> + } + + fun <##>(<##>) : <##> { + <##> + } + + for (<##> in <##>) { + <##> + } + + when (<##>) { + <##> -> <##> + else -> <##> + } + + var <##> = <##> + + class <##> { + <##> + } + + class <##> { + var <##> : <##> + get() { + <##> + } + set(value) { + <##> + } + + val <##> : <##> + get() { + <##> + } + } +} + diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java new file mode 100644 index 00000000000..819b0c6b6de --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/IdeTemplatesTest.java @@ -0,0 +1,63 @@ +package org.jetbrains.jet.plugin.codeInsight; + +import com.intellij.codeInsight.folding.CodeFoldingManager; +import com.intellij.openapi.editor.FoldRegion; +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import org.jetbrains.jet.plugin.PluginTestCaseBase; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Evgeny Gerashchenko + * @since 2/14/12 + */ +public class IdeTemplatesTest extends LightCodeInsightFixtureTestCase { + public void testAll() { + myFixture.configureByFile(PluginTestCaseBase.getTestDataPathBase() + "/templates/IdeTemplates.kt"); + CodeFoldingManager.getInstance(myFixture.getProject()).buildInitialFoldings(myFixture.getEditor()); + + ArrayList regions = getExpectedRegions(); + assertEquals(regions.toString(), getActualRegions().toString()); + + } + + private ArrayList getExpectedRegions() { + Pattern regex = Pattern.compile("<#<(\\w+)>#>"); + Matcher matcher = regex.matcher(myFixture.getEditor().getDocument().getText()); + ArrayList expected = new ArrayList(); + while (matcher.find()) { + expected.add(new Region(matcher.start(), matcher.end(), matcher.group(1))); + } + return expected; + } + + private ArrayList getActualRegions() { + ArrayList actual = new ArrayList(); + for (FoldRegion fr : myFixture.getEditor().getFoldingModel().getAllFoldRegions()) { + if (fr.shouldNeverExpand()) { + assertFalse(fr.isExpanded()); + actual.add(new Region(fr.getStartOffset(), fr.getEndOffset(), fr.getPlaceholderText())); + } + } + return actual; + } + + private static class Region { + public int start; + public int end; + public String group; + + private Region(int start, int end, String group) { + this.start = start; + this.end = end; + this.group = group; + } + + @Override + public String toString() { + return String.format("%d..%d:%s", start, end, group); + } + } +}