package org.metaborg.meta.lang.dynsem.interpreter.nodes.rules.premises;

import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.metaborg.meta.lang.dynsem.interpreter.DynSemContext;
import org.metaborg.meta.lang.dynsem.interpreter.DynSemLanguage;
import org.metaborg.meta.lang.dynsem.interpreter.nodes.matching.PatternMatchFailure;
import org.metaborg.meta.lang.dynsem.interpreter.nodes.matching.TrueLiteralTermMatchPattern;
import org.metaborg.meta.lang.dynsem.interpreter.nodes.matching.TrueLiteralTermMatchPatternNodeGen;
import org.metaborg.meta.lang.dynsem.interpreter.nodes.matching.WldMatchPattern;
import static org.mockito.Mockito.*;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

public class TestCase {

	private static SourceSection src;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		src = SourceSection.createUnavailable("test", "unit");
		DynSemContext.LANGUAGE = mock(DynSemLanguage.class);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		DynSemContext.LANGUAGE = null;
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testExecuteCaseOtherwise() {
		VirtualFrame f = mock(VirtualFrame.class);
		Premise p = mock(Premise.class);
		Case c = new Case.CaseOtherwise(src, new Premise[] { p });
		c.execute(f, true);

		verify(p).execute(f);
	}

	@Test
	public void testExecuteCaseMatchSuccess() {
		VirtualFrame f = mock(VirtualFrame.class);
		Premise p = mock(Premise.class);

		Case c = new Case.CasePattern(src, TrueLiteralTermMatchPatternNodeGen.create(src), new Premise[] { p });
		c.execute(f, true);

		verify(p).execute(f);
	}

	@Test(expected = PatternMatchFailure.class)
	public void testExecuteCaseMatchFailure() {
		VirtualFrame f = mock(VirtualFrame.class);
		Premise p = mock(Premise.class);

		Case c = new Case.CasePattern(src, TrueLiteralTermMatchPatternNodeGen.create(src), new Premise[] { p });
		try {
			c.execute(f, false);
		} catch (PatternMatchFailure pmfx) {
			verify(p, never()).execute(f);
			throw pmfx;
		}
	}

}

@@ -88,51 +88,111 @@
 org.
-junit.Assert.*
+mockito.Mockito.mock
 ;%0A
-%0A
 import 
-java.io.IOException
+static org.mockito.Mockito.never;%0Aimport static org.mockito.Mockito.verify
 ;%0A%0Ai
@@ -539,101 +539,8 @@
 re;%0A
-import org.metaborg.meta.lang.dynsem.interpreter.nodes.matching.TrueLiteralTermMatchPattern;%0A
 impo
@@ -694,339 +694,106 @@
 des.
-matching.WldMatchPattern;%0Aimport static org.mockito.Mockito.*;%0Aimport com.oracle.truffle.api.CallTarget;%0Aimport com.oracle.truffle.api.Truffle;%0Aimport com.oracle.truffle.api.frame.FrameDescriptor;%0Aimport com.oracle.truffle.api.frame.VirtualFrame;%0Aimport com.oracle.truffle.api.nodes.Node;%0Aimport com.oracle.truffle.api.source.Sourc
+rules.premises.CaseMatchPremise.CaseMatchFailure;%0A%0Aimport com.oracle.truffle.api.frame.VirtualFram
 e;%0Ai
@@ -1861,23 +1861,20 @@
 ected = 
-Pattern
+Case
 MatchFai
@@ -2161,23 +2161,20 @@
  catch (
-Pattern
+Case
 MatchFai
@@ -2178,17 +2178,17 @@
 Failure 
-p
+c
 mfx) %7B%0A%09
@@ -2229,17 +2229,17 @@
 %09%09throw 
-p
+c
 mfx;%0A%09%09%7D

Update test