From fa02123ab00be8b8fe212c5d34ed021f1b63de74 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 22 Jun 2016 22:33:33 +0300 Subject: Add double type and fix exception types --- test/MainTest.java | 22 ++++++++++++++++++++++ test/resources/program.bork | 14 ++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/MainTest.java b/test/MainTest.java index 1730a6b..f90e367 100644 --- a/test/MainTest.java +++ b/test/MainTest.java @@ -2,8 +2,13 @@ package com.jantuomi.interpreter.test; import com.jantuomi.interpreter.main.Main; import com.jantuomi.interpreter.main.exception.InterpreterException; +import org.junit.After; +import org.junit.Before; import org.junit.Test; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -11,6 +16,21 @@ import static org.junit.Assert.assertTrue; * Created by jan on 10.6.2016. */ public class MainTest { + + private final ByteArrayOutputStream out = new ByteArrayOutputStream(); + private PrintStream originalOut; + + @Before + public void setupStreams() { + originalOut = System.out; + System.setOut(new PrintStream(out)); + } + + @After + public void cleanStreams() { + System.setOut(originalOut); + } + @Test public void testParseArguments1() { String[] notAnArgument = {"--not-an-argument"}; @@ -26,6 +46,8 @@ public class MainTest { @Test public void testWholeProcedure() throws InterpreterException { String input = "- + 2 5 1"; + Main.run(input); + assertTrue(out.toString().contains("6")); } } \ No newline at end of file diff --git a/test/resources/program.bork b/test/resources/program.bork index 52cee38..7034625 100644 --- a/test/resources/program.bork +++ b/test/resources/program.bork @@ -1,15 +1,13 @@ /* get an integer from the user */ -decl user_input -set user_input in("give integer: ") -out( concat("your input was: " user_input "!") ) - -/* add 10 to the integer */ -decl operand set operand 10 +decl lhs decl rhs +set lhs in("give an integer: ") +set rhs in("give another: ") +/* add the inputs together */ decl sum -set sum + as_int(user_input) operand +set sum + as_int(lhs) as_int(rhs) /* print the sum */ -out( concat(user_input " + " operand " = " sum) ) +out( concat(lhs " + " rhs " = " sum) ) "done" \ No newline at end of file -- cgit v1.3