package de.bmoth.typechecker;

import de.bmoth.parser.Parser;
import de.bmoth.parser.ast.TypeErrorException;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class TypeErrorExceptionTest {

    @Test(expected = TypeErrorException.class)
    public void testTypeErrorException() {
        String formula = "a = TRUE & b = 1 & a = b";
        Parser.getFormulaAsSemanticAst(formula);
    }

    @Test(expected = TypeErrorException.class)
    public void testTypeErrorException2() {
        String formula = "a = TRUE & a = 1 + 1";
        Parser.getFormulaAsSemanticAst(formula);
    }

    @Test
    public void testSetEnumeration() {
        String formula = "x = {1,2,(3,4)}";
        String exceptionMessage = getExceptionMessage(formula);
        assertTrue(exceptionMessage.contains("Expected INTEGER but found INTEGER*INTEGER"));
    }

    @Test
    public void testSetEnumeration2() {
        String formula = "x = {1,2,{3,4}}";
        String exceptionMessage = getExceptionMessage(formula);
        assertTrue(exceptionMessage.contains("found POW"));
    }

    private static String getExceptionMessage(String formula) {
        try {
            Parser.getFormulaAsSemanticAst(formula);
            throw new RuntimeException("Expected a type error exception.");
        } catch (TypeErrorException e) {
            return e.getMessage();
        }
    }
}

@@ -168,16 +168,53 @@
 ertTrue;
+%0Aimport static org.junit.Assert.fail;
 %0A%0Apublic
@@ -1270,34 +1270,12 @@
     
-throw new RuntimeException
+fail
 (%22Ex
@@ -1308,16 +1308,41 @@
 ion.%22);%0A
+            return null;%0A
         

use junit fail instead of new exception