/*
 * Copyright 2000-2017 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.ide.codeStyleSettings;

import com.intellij.editor.EditorColorSchemeTestCase;
import com.intellij.openapi.application.ex.PathManagerEx;
import com.intellij.openapi.options.SchemeFactory;
import com.intellij.openapi.options.SchemeImportException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.codeStyle.CodeStyleScheme;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.impl.source.codeStyle.CodeStyleSchemeImpl;
import com.intellij.psi.impl.source.codeStyle.CodeStyleSchemeXmlImporter;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;

@SuppressWarnings("SameParameterValue")
public abstract class CodeStyleTestCase extends LightPlatformTestCase {

  protected static final String BASE_PATH = PathManagerEx.getTestDataPath("/../../../platform/platform-tests/testData/codeStyle/");

  public static void assertXmlOutputEquals(String expected, Element root) throws IOException {
    EditorColorSchemeTestCase.assertXmlOutputEquals(expected, root);
  }

  protected static Element createOption(String name, String value) {
    Element optionElement = new Element("option");
    optionElement.setAttribute("name", name);
    optionElement.setAttribute("value", value);
    return optionElement;
  }

  @Nullable
  protected String getTestDir() {
    return null;
  }

  @NotNull
  protected final String getTestDataPath() {
    String testDir = getTestDir();
    return getBasePath() + (testDir != null ? testDir : "") + File.separator;
  }

  @NotNull
  @Override
  protected LightProjectDescriptor getProjectDescriptor() {
    return new LightProjectDescriptor() {
      @Override
      public void setUpProject(@NotNull Project project, @NotNull SetupHandler handler) throws Exception {
        setupProject();
        super.setUpProject(project, handler);
      }
    };
  }

  protected void setupProject() throws Exception {}

  protected CodeStyleSettings importSettings() throws SchemeImportException {
    final CodeStyleScheme targetScheme = new CodeStyleSchemeImpl("Test", false, null);
    SchemeFactory<CodeStyleScheme> schemeFactory = new SchemeFactory<CodeStyleScheme>() {
      @Override
      public CodeStyleScheme createNewScheme(@Nullable String name) {
        return targetScheme;
      }
    };
    File ioFile = new File(getTestDataPath() + getTestName(true) + ".xml");
    assertExists(ioFile);
    VirtualFile vFile = VfsUtil.findFileByIoFile(ioFile, true);
    CodeStyleSchemeXmlImporter importer = new CodeStyleSchemeXmlImporter();
    return importer.importScheme(getProject(), vFile, targetScheme, schemeFactory).getCodeStyleSettings();
  }

  protected String loadExpected(@NotNull String ext) throws IOException {
    return FileUtilRt
      .loadFile(new File(getBasePath() + File.separator + getTestDir() + File.separator + getTestName(true) + "." + ext));
  }

  protected CodeStyleScheme createTestScheme() {
    return new CodeStyleScheme() {
      @NotNull
      @Override
      public String getName() {
        return "Test";
      }

      @Override
      public boolean isDefault() {
        return false;
      }

      @NotNull
      @Override
      public CodeStyleSettings getCodeStyleSettings() {
        return new CodeStyleSettings();
      }
    };
  }

  protected String getBasePath() {
    return BASE_PATH;
  }
}

@@ -3809,16 +3809,22 @@
 %22 + ext)
+, true
 );%0A  %7D%0A%0A

Test fix: convert line separators