package net.kenro.ji.jin.purescript.parser;

import com.intellij.lang.ParserDefinition;
import com.intellij.mock.MockVirtualFile;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.ParsingTestCase;
import com.intellij.testFramework.TestDataFile;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

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


public abstract class PSLanguageParserTestBase extends ParsingTestCase {

    public PSLanguageParserTestBase(
        String dataPath,
        String fileExt,
        ParserDefinition... definitions
    ) {
        super(dataPath, fileExt, definitions);
    }

    @Override
    protected String getTestDataPath() {
        return this.getClass().getClassLoader().getResource("gold").getPath();
    }

    @Override
    protected boolean skipSpaces() {
        return true;
    }

    /**
     * Perform a test. Add tests that should work but does not work yet with
     * doTest(false, false).
     */
    protected void doTestOld(boolean checkResult, boolean shouldPass) {
        doTest(true);
        if (shouldPass) {
            assertFalse(
                "PsiFile contains error elements",
                toParseTreeText(myFile, skipSpaces(), includeRanges()).contains(
                    "PsiErrorElement")
            );
        }
    }


    @Override
    protected void checkResult(
        @NotNull @NonNls @TestDataFile String targetDataName,
        @NotNull final PsiFile file
    ) throws IOException {
        final String fullTargetDataName = "" + File.separator + targetDataName;
        doCheckResult(
            myFullDataPath,
            file,
            checkAllPsiRoots(),
            fullTargetDataName,
            skipSpaces(),
            includeRanges()
        );
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        VirtualFile m = new MockVirtualFile(true, myFullDataPath);
        myProject.setBaseDir(m);
    }

}

@@ -409,36 +409,8 @@
 le;%0A
-import java.io.IOException;%0A
 %0A%0Apu
@@ -1513,27 +1513,8 @@
    )
- throws IOException
  %7B%0A 

Remove exception that is never thrown