Properties files: formatter tests added

This commit is contained in:
Dmitry Batkovich
2016-02-01 11:49:01 +03:00
parent 003dce56a7
commit 5f03bd6de2
3 changed files with 99 additions and 5 deletions
@@ -44,7 +44,7 @@ public class PropertiesCodeStyleSettingsPanel extends OptionTableWithPreviewPane
@Override
protected void initTables() {
addOption("ALIGN_GROUP_FIELD_DECLARATIONS", "Align properties in column");
showStandardOptions("SPACE_AROUND_ASSIGNMENT_OPERATORS", "ALIGN_GROUP_FIELD_DECLARATIONS");
showStandardOptions("ALIGN_GROUP_FIELD_DECLARATIONS");
showCustomOption(PropertiesCodeStyleSettings.class, "SPACES_AROUND_KEY_VALUE_DELIMITER",
"Insert space around key-value delimiter", null);
showCustomOption(PropertiesCodeStyleSettings.class,
@@ -15,10 +15,7 @@
*/
package com.intellij.lang.properties.formatting;
import com.intellij.formatting.Alignment;
import com.intellij.formatting.Block;
import com.intellij.formatting.Spacing;
import com.intellij.formatting.Wrap;
import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.lang.properties.parsing.PropertiesTokenTypes;
import com.intellij.lang.properties.parsing.PropertyListStubElementType;
@@ -96,6 +93,9 @@ public class PropertiesRootBlock extends AbstractBlock {
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
if (child1 == null) {
return null;
}
return mySettings.getCustomSettings(PropertiesCodeStyleSettings.class).SPACES_AROUND_KEY_VALUE_DELIMITER &&
(child1 instanceof SeparatorBlock || child2 instanceof SeparatorBlock)
? Spacing.createSpacing(1, 1, 0, true, 0)
@@ -0,0 +1,94 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.lang.properties;
import com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.formatter.FormatterTestCase;
/**
* @author Dmitry Batkovich
*/
public class PropertiesFormatterTest extends FormatterTestCase {
private CommonCodeStyleSettings mySettings;
private PropertiesCodeStyleSettings myCustomSettings;
@Override
public void setUp() throws Exception {
super.setUp();
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
mySettings = settings.getCommonSettings(PropertiesLanguage.INSTANCE);
myCustomSettings = settings.getCustomSettings(PropertiesCodeStyleSettings.class);
mySettings.ALIGN_GROUP_FIELD_DECLARATIONS = false;
myCustomSettings.SPACES_AROUND_KEY_VALUE_DELIMITER = false;
}
@Override
public void tearDown() throws Exception {
super.tearDown();
}
public void testSimple1() {
doTextTest("\n\n" +
"qwe=asd\n" +
"#comment\n" +
" key1 = value1",
"qwe=asd\n" +
"#comment\n" +
"key1=value1");
}
public void testSimple2() {
mySettings.ALIGN_GROUP_FIELD_DECLARATIONS = true;
doTextTest(" qwe_very_big_property = asd\n" +
"#comment\n" +
" key1 = value1",
"qwe_very_big_property=asd\n" +
"#comment\n" +
"key1 =value1");
}
public void testSimple3() {
mySettings.ALIGN_GROUP_FIELD_DECLARATIONS = true;
myCustomSettings.SPACES_AROUND_KEY_VALUE_DELIMITER = true;
doTextTest(" qwe_very_big_property = asd\n" +
"#comment\n" +
" key1 = value1",
"qwe_very_big_property = asd\n" +
"#comment\n" +
"key1 = value1");
}
protected void doTextTest(String text) {
doTextTest(text, text);
}
@Override
protected String getBasePath() {
return "";
}
@Override
protected String getFileExtension() {
return PropertiesFileType.DEFAULT_EXTENSION;
}
}