<commit_before>package trinity.tests;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.Ignore;
import trinity.*;
import org.junit.Test;
import trinity.CustomExceptions.ParseException;
import trinity.visitors.ReachabilityVisitor;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


public class    ReachabilityVisitorTest {

    private boolean reachabilityTest(String str) throws Exception{
        ErrorReporter er = new StandardErrorReporter(false, str);
        ReachabilityVisitor ReachabilityVisitor = new ReachabilityVisitor(er);

        ANTLRInputStream input = new ANTLRInputStream(str);
        TrinityLexer lexer = new TrinityLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        TrinityParser parser = new TrinityParser(tokens);

        ParseTree tree = parser.prog();

        if (parser.getNumberOfSyntaxErrors() != 0) {
            throw new ParseException("Invalid reachability test.");
        }

        tree.accept(ReachabilityVisitor);

        return er.getErrorAmount() == 0;
    }

    @Test
    public void testSimpleFunctionFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar k () do\n" +
                "    1 + 1;\n" +
                "end"));
    }

    @Ignore
    public void testSimpleFunctionTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    return 1;\n" +
                "end"));
    }

    @Ignore
    public void testBlockHellNestedFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        return 1;\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    return 1;\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "end"));

    }

    @Ignore
    public void testBlockHellNestedTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "           return 1;" +
                "        end\n" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "        return 1;" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "    return 1;" +
                "end"));
    }

    @Ignore
    public void testBlockHellContinuedFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "    end\n" +
                "    do\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "    do\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "            return 1;\n" +
                "        end\n" +
                "    end\n" +
                "    do\n" +
                "    end\n" +
                "end"));
    }

    @Ignore
    public void testBlockHellContinuedTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "    end\n" +
                "    do\n" +
                "        return 1;\n" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "    do\n" +
                "        return 1;\n" +
                "    end\n" +
                "end"));

    }

    @Ignore
    public void testFunctionsWithIfStatementFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        return true;\n" +
                "    else\n" +
                "        1 + 1;\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        1 + 1;\n" +
                "    else\n" +
                "        return false;\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        1 + 1;\n" +
                "    else\n" +
                "        1 + 1;\n" +
                "    end\n" +
                "end"));
    }

    @Ignore
    public void testFunctionsWithIfStatementTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        return true;\n" +
                "    else\n" +
                "        return false;\n" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        if true then\n" +
                "            return true;\n" +
                "        else\n" +
                "            return false;\n" +
                "        end\n" +
                "    end\n" +
                "end"));
    }
}<commit_msg>New reachabilitytests<commit_after>package trinity.tests;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.Ignore;
import trinity.*;
import org.junit.Test;
import trinity.CustomExceptions.ParseException;
import trinity.visitors.ReachabilityVisitor;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class    ReachabilityVisitorTest {

    private boolean reachabilityTest(String str) throws Exception{
        ErrorReporter er = new StandardErrorReporter(false, str);
        ReachabilityVisitor ReachabilityVisitor = new ReachabilityVisitor(er);

        ANTLRInputStream input = new ANTLRInputStream(str);
        TrinityLexer lexer = new TrinityLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        TrinityParser parser = new TrinityParser(tokens);

        ParseTree tree = parser.prog();

        if (parser.getNumberOfSyntaxErrors() != 0) {
            throw new ParseException("Invalid reachability test.");
        }

        tree.accept(ReachabilityVisitor);

        return er.getErrorAmount() == 0;
    }

    @Ignore
    public void testSimpleIfFunctionFalseOnly() throws Exception{
        assertFalse(reachabilityTest("if false then\n" +
                "    1+1;\n" +
                "end"));
    }

    @Test
    public void testSimpleFunctionFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar k () do\n" +
                "    1 + 1;\n" +
                "end"));
    }

    @Ignore
    public void testSimpleFunctionTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    return 1;\n" +
                "end"));
    }

    @Ignore
    public void testBlockHellNestedFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        return 1;\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    return 1;\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "end"));

    }

    @Ignore
    public void testBlockHellNestedTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "           return 1;" +
                "        end\n" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "        return 1;" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "    return 1;" +
                "end"));
    }

    @Ignore
    public void testBlockHellContinuedFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "    end\n" +
                "    do\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "    do\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "            return 1;\n" +
                "        end\n" +
                "    end\n" +
                "    do\n" +
                "    end\n" +
                "end"));
    }

    @Ignore
    public void testBlockHellContinuedTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "    end\n" +
                "    do\n" +
                "        return 1;\n" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        do\n" +
                "        end\n" +
                "    end\n" +
                "    do\n" +
                "        return 1;\n" +
                "    end\n" +
                "end"));

    }

    @Ignore
    public void testFunctionsWithIfStatementFalseOnly() throws Exception{
        assertFalse(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        return true;\n" +
                "    else\n" +
                "        1 + 1;\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        1 + 1;\n" +
                "    else\n" +
                "        return false;\n" +
                "    end\n" +
                "end"));
        assertFalse(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        1 + 1;\n" +
                "    else\n" +
                "        1 + 1;\n" +
                "    end\n" +
                "end"));
    }

    @Ignore
    public void testFunctionsWithIfStatementTrueOnly() throws Exception{
        assertTrue(reachabilityTest("Boolean b () do\n" +
                "    if true then\n" +
                "        return true;\n" +
                "    else\n" +
                "        return false;\n" +
                "    end\n" +
                "end"));
        assertTrue(reachabilityTest("Scalar s () do\n" +
                "    do\n" +
                "        if true then\n" +
                "            return true;\n" +
                "        else\n" +
                "            return false;\n" +
                "        end\n" +
                "    end\n" +
                "end"));
    }

}
{'fraction_non_alphanumeric': 0.11993957703927492, 'fraction_numerical': 0.0037764350453172208, 'mean_word_length': 1.0046934140802422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3105456', 'n_tokens_mistral': 3882, 'n_tokens_neox': 3588, 'n_words': 652}