Added simple IDE templates test which checks that folding worked normally.

This commit is contained in:
Evgeny Gerashchenko
2012-02-14 14:21:17 +04:00
parent e3fdc5d595
commit 7ce86a138e
2 changed files with 105 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
fun main(args : Array<String>) {
if (<#<condition>#>) {
<#<block>#>
} else {
<#<block>#>
}
fun <#<name>#>(<#<params>#>) : <#<returnType>#> {
<#<body>#>
}
for (<#<i>#> in <#<elements>#>) {
<#<body>#>
}
when (<#<expression>#>) {
<#<condition>#> -> <#<value>#>
else -> <#<elseValue>#>
}
var <#<name>#> = <#<value>#>
class <#<name>#> {
<#<body>#>
}
class <#<name>#> {
var <#<name>#> : <#<varType>#>
get() {
<#<body>#>
}
set(value) {
<#<body>#>
}
val <#<name>#> : <#<valType>#>
get() {
<#<body>#>
}
}
}
@@ -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<Region> regions = getExpectedRegions();
assertEquals(regions.toString(), getActualRegions().toString());
}
private ArrayList<Region> getExpectedRegions() {
Pattern regex = Pattern.compile("<#<(\\w+)>#>");
Matcher matcher = regex.matcher(myFixture.getEditor().getDocument().getText());
ArrayList<Region> expected = new ArrayList<Region>();
while (matcher.find()) {
expected.add(new Region(matcher.start(), matcher.end(), matcher.group(1)));
}
return expected;
}
private ArrayList<Region> getActualRegions() {
ArrayList<Region> actual = new ArrayList<Region>();
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);
}
}
}