aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jantuomi/tunkki
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2016-07-26 19:43:13 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2016-07-26 19:47:14 +0300
commit8234767203a7f673b12c8f51b83762c511274366 (patch)
tree3dfa221a1bc0c94860363a74bdaf4c3dbb23226d /src/test/com/jantuomi/tunkki
parent9c189c2d1ef35184ec9a9d08bdeeb52936902867 (diff)
Rename project to tunkki
Diffstat (limited to 'src/test/com/jantuomi/tunkki')
-rw-r--r--src/test/com/jantuomi/tunkki/MainTest.java52
-rw-r--r--src/test/com/jantuomi/tunkki/core/CommandLineArgumentContainerTest.java24
-rw-r--r--src/test/com/jantuomi/tunkki/core/parser/ParserTest.java30
-rw-r--r--src/test/com/jantuomi/tunkki/core/tokenizer/TokenizerTest.java26
-rw-r--r--src/test/com/jantuomi/tunkki/resources/funcdef.bork8
-rw-r--r--src/test/com/jantuomi/tunkki/resources/program.bork13
-rw-r--r--src/test/com/jantuomi/tunkki/resources/test.file4
7 files changed, 157 insertions, 0 deletions
diff --git a/src/test/com/jantuomi/tunkki/MainTest.java b/src/test/com/jantuomi/tunkki/MainTest.java
new file mode 100644
index 0000000..d76bac1
--- /dev/null
+++ b/src/test/com/jantuomi/tunkki/MainTest.java
@@ -0,0 +1,52 @@
+package com.jantuomi.tunkki;
+
+import com.jantuomi.tunkki.exception.BorkError;
+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;
+
+/**
+ * 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"};
+ assertFalse(Main.parseArguments(notAnArgument));
+ }
+
+ @Test
+ public void testParseArguments2() {
+ String[] fileTestArgument = {"-f", "test.file"};
+ assertTrue(Main.parseArguments(fileTestArgument));
+ }
+
+ @Test
+ public void testWholeProcedure() throws BorkError {
+ String input = "- + 2 5 1";
+
+ Main.run(input);
+ assertTrue(out.toString().contains("6"));
+ }
+} \ No newline at end of file
diff --git a/src/test/com/jantuomi/tunkki/core/CommandLineArgumentContainerTest.java b/src/test/com/jantuomi/tunkki/core/CommandLineArgumentContainerTest.java
new file mode 100644
index 0000000..437c602
--- /dev/null
+++ b/src/test/com/jantuomi/tunkki/core/CommandLineArgumentContainerTest.java
@@ -0,0 +1,24 @@
+package com.jantuomi.tunkki.core;
+
+import com.jantuomi.tunkki.utils.Utilities;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by jan on 10.6.2016.
+ */
+public class CommandLineArgumentContainerTest {
+ @Test
+ public void getSourceFileContents() throws Exception {
+ CommandLineArgumentContainer c = CommandLineArgumentContainer.getInstance();
+ File basePath = new File(Utilities.getBasePath());
+ c.setFile(new File(basePath, "src/test/com/jantuomi/tunkki/resources/test.file"));
+ String contents = c.getSourceFileContents();
+ System.out.println(contents);
+ assertTrue(contents.contains("###"));
+ }
+
+} \ No newline at end of file
diff --git a/src/test/com/jantuomi/tunkki/core/parser/ParserTest.java b/src/test/com/jantuomi/tunkki/core/parser/ParserTest.java
new file mode 100644
index 0000000..2e8421d
--- /dev/null
+++ b/src/test/com/jantuomi/tunkki/core/parser/ParserTest.java
@@ -0,0 +1,30 @@
+package com.jantuomi.tunkki.core.parser;
+
+import com.jantuomi.tunkki.core.tokenizer.token.Token;
+import com.jantuomi.tunkki.core.tokenizer.token.types.AdditionToken;
+import com.jantuomi.tunkki.core.tokenizer.token.types.IntegerLiteralToken;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Created by jan on 12.6.2016.
+ */
+public class ParserTest {
+
+ @Test
+ public void testParseAddition() throws Exception {
+ List<Token> tokens = Arrays.asList(
+ new IntegerLiteralToken("1"),
+ new IntegerLiteralToken("2"),
+ new AdditionToken()
+ );
+
+ Parser parser = Parser.getInstance();
+ List<Token> sequence = parser.parse(tokens);
+ for (Token t : sequence) {
+ parser.printTree(t);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/com/jantuomi/tunkki/core/tokenizer/TokenizerTest.java b/src/test/com/jantuomi/tunkki/core/tokenizer/TokenizerTest.java
new file mode 100644
index 0000000..dff1e96
--- /dev/null
+++ b/src/test/com/jantuomi/tunkki/core/tokenizer/TokenizerTest.java
@@ -0,0 +1,26 @@
+package com.jantuomi.tunkki.core.tokenizer;
+
+import com.jantuomi.tunkki.core.tokenizer.token.Token;
+import com.jantuomi.tunkki.core.tokenizer.token.types.IntegerLiteralToken;
+import com.jantuomi.tunkki.exception.BorkError;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by jan on 10.6.2016.
+ */
+public class TokenizerTest {
+
+ @Test
+ public void testAddition() throws BorkError {
+ String testString = "1 2 +";
+ List<Token> list = Tokenizer.getInstance().tokenize(testString);
+
+ System.out.println(String.format("test string:\n%s", testString));
+ Tokenizer.printTokens(list);
+ assertTrue(list.contains(new IntegerLiteralToken("2")));
+ }
+} \ No newline at end of file
diff --git a/src/test/com/jantuomi/tunkki/resources/funcdef.bork b/src/test/com/jantuomi/tunkki/resources/funcdef.bork
new file mode 100644
index 0000000..8412129
--- /dev/null
+++ b/src/test/com/jantuomi/tunkki/resources/funcdef.bork
@@ -0,0 +1,8 @@
+/* kommentti juu jee */
+
+func my_func x y as
+ + x 1
+ - y x
+end
+
+my_func(1 2) \ No newline at end of file
diff --git a/src/test/com/jantuomi/tunkki/resources/program.bork b/src/test/com/jantuomi/tunkki/resources/program.bork
new file mode 100644
index 0000000..7034625
--- /dev/null
+++ b/src/test/com/jantuomi/tunkki/resources/program.bork
@@ -0,0 +1,13 @@
+/* get an integer from the user */
+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(lhs) as_int(rhs)
+
+/* print the sum */
+out( concat(lhs " + " rhs " = " sum) )
+
+"done" \ No newline at end of file
diff --git a/src/test/com/jantuomi/tunkki/resources/test.file b/src/test/com/jantuomi/tunkki/resources/test.file
new file mode 100644
index 0000000..3b723c0
--- /dev/null
+++ b/src/test/com/jantuomi/tunkki/resources/test.file
@@ -0,0 +1,4 @@
+###
+This test file starts and
+ends in three # symbols
+### \ No newline at end of file