Files
openide/java/java-tests/testSrc/com/intellij/ide/fileTemplates/FileTemplatesProcessingTest.java
Vladimir Krivosheev 2a3ea3b088 prefer jdk collections
GitOrigin-RevId: 5634ed51a4458b904c3a1d913c1978b5b3bb84e0
2020-07-29 07:02:03 +00:00

64 lines
2.4 KiB
Java

// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.fileTemplates;
import com.intellij.platform.templates.SaveProjectAsTemplateAction;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Dmitry Avdeev
*/
public class FileTemplatesProcessingTest extends BasePlatformTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
PlatformTestUtil.setLongMeaninglessFileIncludeTemplateTemporarilyFor(getProject(), getTestRootDisposable());
}
public void testExtractTemplate() {
doTest(true, "/** Special Velocity symbols # and $ should be escaped */\n" +
"\n" +
"/**\n" +
" * Created by Dmitry.Avdeev on 1/22/13.\n" +
" */\n" +
"public class Bar {\n" +
"}",
"/** Special Velocity symbols \\# and #[[\\$]]# should be escaped */\n" +
"\n" +
"/**\n" +
" * Created by ${USER} on ${DATE}.\n" +
" */\n" +
"\n" +
"public class Bar {\n" +
"}");
}
private void doTest(boolean shouldEscape, String input, String expected) {
FileTemplate template = FileTemplateManager.getInstance(getProject()).getDefaultTemplate(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
Pattern pattern = FileTemplateUtil.getTemplatePattern(template, getProject(), new Int2ObjectOpenHashMap<>());
Matcher matcher = pattern.matcher(input);
assertTrue(matcher.matches());
String result = SaveProjectAsTemplateAction.convertTemplates(input, pattern, template.getText(), shouldEscape);
assertEquals(expected, result);
}
public void testExtractTemplateUnescaped() {
doTest(false, "/** Special Velocity symbols # and $ should not be escaped */\n" +
"\n" +
"/**\n" +
" * Created by Dmitry.Avdeev on 1/22/13.\n" +
" */\n" +
"public class Bar {\n" +
"}",
"/** Special Velocity symbols # and $ should not be escaped */\n" +
"\n" +
"<IntelliJ_File_Header>\n" +
"public class Bar {\n" +
"}");
}
}