aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/MainTest.java24
-rw-r--r--test/core/CommandLineArgumentContainerTest.java26
-rw-r--r--test/core/parser/ParserTest.java34
-rw-r--r--test/core/tokenizer/TokenizerTest.java80
-rw-r--r--test/resources/test.file4
5 files changed, 168 insertions, 0 deletions
diff --git a/test/MainTest.java b/test/MainTest.java
new file mode 100644
index 0000000..fec91a7
--- /dev/null
+++ b/test/MainTest.java
@@ -0,0 +1,24 @@
+package com.jantuomi.interpreter.test;
+
+import com.jantuomi.interpreter.main.Main;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by jan on 10.6.2016.
+ */
+public class MainTest {
+ @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));
+ }
+} \ No newline at end of file
diff --git a/test/core/CommandLineArgumentContainerTest.java b/test/core/CommandLineArgumentContainerTest.java
new file mode 100644
index 0000000..f6a6ead
--- /dev/null
+++ b/test/core/CommandLineArgumentContainerTest.java
@@ -0,0 +1,26 @@
+package com.jantuomi.interpreter.test.core;
+
+import com.jantuomi.interpreter.main.core.CommandLineArgumentContainer;
+import com.jantuomi.interpreter.main.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/com/jantuomi/interpreter/test/resources/test.file"));
+ String contents = c.getSourceFileContents();
+ System.out.println(contents);
+ assertTrue(contents.contains("###"));
+ }
+
+} \ No newline at end of file
diff --git a/test/core/parser/ParserTest.java b/test/core/parser/ParserTest.java
new file mode 100644
index 0000000..913896e
--- /dev/null
+++ b/test/core/parser/ParserTest.java
@@ -0,0 +1,34 @@
+package com.jantuomi.interpreter.test.core.parser;
+
+import com.jantuomi.interpreter.main.core.parser.Parser;
+import com.jantuomi.interpreter.main.core.parser.ast.ASTNode;
+import com.jantuomi.interpreter.main.core.tokenizer.token.Token;
+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 parseAssignment() throws Exception {
+ List<Token> tokens = Arrays.asList(
+ new Token(Token.Type.SymbolToken, "x"),
+ new Token(Token.Type.AssignmentToken),
+ new Token(Token.Type.SymbolToken, "y"),
+ new Token(Token.Type.AdditionToken),
+ new Token(Token.Type.SymbolToken, "x"),
+ new Token(Token.Type.AdditionToken),
+ new Token(Token.Type.IntegerLiteralToken, "1")
+ );
+
+ Parser parser = Parser.getInstance();
+ List<ASTNode> sequence = parser.parse(tokens);
+ for (ASTNode e : sequence) {
+ parser.printTree(e);
+ }
+ }
+} \ No newline at end of file
diff --git a/test/core/tokenizer/TokenizerTest.java b/test/core/tokenizer/TokenizerTest.java
new file mode 100644
index 0000000..7b29020
--- /dev/null
+++ b/test/core/tokenizer/TokenizerTest.java
@@ -0,0 +1,80 @@
+package com.jantuomi.interpreter.test.core.tokenizer;
+
+import com.jantuomi.interpreter.main.core.tokenizer.Tokenizer;
+import com.jantuomi.interpreter.main.core.tokenizer.token.Token;
+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 testTokenizeCommentAndSymbol() {
+ String testString = "\"string literal\"\n/*comment*/\n1 2\nsymbol_Test3";
+ List<Token> list = Tokenizer.getInstance().tokenize(testString);
+
+ System.out.println(String.format("test string:\n%s", testString));
+ Tokenizer.printTokens(list);
+ assertTrue(list.contains(new Token(Token.Type.CommentToken, "comment")));
+ }
+
+ @Test
+ public void testTokenizeMultilineString() {
+ String testString = "\"this is a\nmultiline\nstring\"";
+ List<Token> list = Tokenizer.getInstance().tokenize(testString);
+
+ System.out.println(String.format("test string:\n%s", testString));
+ Tokenizer.printTokens(list);
+ assertTrue(list.contains(new Token(Token.Type.StringLiteralToken, "this is a\nmultiline\nstring")));
+ }
+
+ @Test
+ public void testTokenizeMath() {
+ String testString = "x <- (1 + 2) / 3 * 4";
+ List<Token> list = Tokenizer.getInstance().tokenize(testString);
+
+ System.out.println(String.format("test string:\n%s", testString));
+ Tokenizer.printTokens(list);
+ for (Token t : list) {
+ if (t.isSameType(new Token(Token.Type.AssignmentToken))) {
+ return;
+ }
+ }
+ assertTrue("No assignment token found!" == null);
+ }
+
+ @Test
+ public void testTokenizeDeclAndAssign() {
+ String testString = "decl x\nx <- 1 + 2";
+ List<Token> list = Tokenizer.getInstance().tokenize(testString);
+
+ System.out.println(String.format("test string:\n%s", testString));
+ Tokenizer.printTokens(list);
+ for (Token t : list) {
+ if (t.isSameType(new Token(Token.Type.DeclarationToken))) {
+ return;
+ }
+ }
+ assertTrue("No declaration token found!" == null);
+ }
+
+ @Test
+ public void testTokenizeFunction() {
+ String testString = "func name(arg)\nx <- 1\nend";
+ List<Token> list = Tokenizer.getInstance().tokenize(testString);
+
+ System.out.println(String.format("test string:\n%s", testString));
+ Tokenizer.printTokens(list);
+ for (Token t : list) {
+ if (t.isSameType(new Token(Token.Type.FunctionDefineToken))) {
+ return;
+ }
+ }
+ assertTrue("No function declaration token found!" == null);
+ }
+} \ No newline at end of file
diff --git a/test/resources/test.file b/test/resources/test.file
new file mode 100644
index 0000000..3b723c0
--- /dev/null
+++ b/test/resources/test.file
@@ -0,0 +1,4 @@
+###
+This test file starts and
+ends in three # symbols
+### \ No newline at end of file