package org.spoofax.jsglr2.integrationtest;

import static org.junit.Assert.assertEquals;

import org.metaborg.parsetable.IParseTable;
import org.spoofax.interpreter.terms.IStrategoTerm;
import org.spoofax.jsglr2.integration.ParseTableVariant;
import org.spoofax.jsglr2.parseforest.ParseForestRepresentation;
import org.spoofax.jsglr2.parser.result.ParseResult;

public abstract class BaseTestWithLayoutSensitiveSdf3ParseTables extends BaseTestWithSdf3ParseTables {

    protected BaseTestWithLayoutSensitiveSdf3ParseTables(String sdf3Resource) {
        super(sdf3Resource);
    }

    @Override public IParseTable getParseTable(ParseTableVariant variant, String sdf3Resource) throws Exception {
        return sdf3ToParseTable.getLayoutSensitiveParseTable(variant, sdf3Resource);
    }

    protected void testLayoutSensitiveParseFailure(String inputString) {
        for(TestVariant variant : getTestVariants()) {
            if(!variant.variant.parser.parseForestRepresentation.equals(ParseForestRepresentation.LayoutSensitive))
                continue;

            ParseResult<?> parseResult = variant.parser().parse(inputString);

            assertEquals("Variant '" + variant.name() + "' should fail: ", false, parseResult.isSuccess());
        }
    }

    protected void testLayoutSensitiveSuccessByExpansions(String inputString, String expectedOutputAstString) {
        testLayoutSensitiveSuccess(inputString, expectedOutputAstString, null, true);
    }

    private void testLayoutSensitiveSuccess(String inputString, String expectedOutputAstString, String startSymbol,
        boolean equalityByExpansions) {
        for(TestVariant variant : getTestVariants()) {
            if(!variant.variant.parser.parseForestRepresentation.equals(ParseForestRepresentation.LayoutSensitive))
                continue;

            IStrategoTerm actualOutputAst = testSuccess(variant, startSymbol, inputString);

            assertEqualAST("Variant '" + variant.name() + "' has incorrect AST", expectedOutputAstString,
                actualOutputAst, equalityByExpansions);
        }
    }

}

@@ -84,16 +84,54 @@
 quals;%0A%0A
+import java.util.function.Predicate;%0A%0A
 import o
@@ -826,33 +826,47 @@
 %0A%0A    pr
-otected void test
+ivate Predicate%3CTestVariant%3E is
 LayoutSe
@@ -876,42 +876,17 @@
 tive
-ParseFailure(String inputString) %7B
+Variant =
 %0A   
@@ -882,37 +882,33 @@
 riant =%0A        
-for(T
+t
 estVariant varia
@@ -906,56 +906,16 @@
 ant 
-variant : getTestVariants()) %7B%0A            if(!v
+-%3E testV
 aria
@@ -949,32 +949,45 @@
 stRepresentation
+%0A            
 .equals(ParseFor
@@ -1024,36 +1024,162 @@
 ive)
-)
+;%0A
 %0A    
-            continue;%0A
+protected void testLayoutSensitiveParseFailure(String inputString) %7B%0A        for(TestVariant variant : getTestVariants(isLayoutSensitiveVariant)) %7B
 %0A   
@@ -1794,155 +1794,36 @@
 nts(
-)) %7B%0A            if(!variant.variant.parser.parseForestRepresentation.equals(ParseForestRepresentation.LayoutSensitive))%0A                continue;%0A
+isLayoutSensitiveVariant)) %7B
 %0A   

Use a predicate to filter layout-sensitive variants