summaryrefslogtreecommitdiff
path: root/chapter01/src/test
diff options
context:
space:
mode:
authordibyendumajumdar <mobile@majumdar.org.uk>2023-08-26 12:28:48 +0100
committerdibyendumajumdar <mobile@majumdar.org.uk>2023-08-26 12:28:48 +0100
commit3b07be6d2c30f7539c5e71964c7a1e4c6790f91f (patch)
tree3b09d3a0a08322721756669ce6e1f4fbf58d97ac /chapter01/src/test
parentb8f815a16ebad6675b6305d623196a8210145b75 (diff)
downloadSimple-3b07be6d2c30f7539c5e71964c7a1e4c6790f91f.tar.gz
Simple-3b07be6d2c30f7539c5e71964c7a1e4c6790f91f.zip
Update the lexer, parser and AST to match the language definition.
Add toString() method on AST nodes so that we can easily check the results of parsing. Remove AA lexer Move the Ecstasy lexer classes to one package, except Handy
Diffstat (limited to 'chapter01/src/test')
-rw-r--r--chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java20
1 files changed, 9 insertions, 11 deletions
diff --git a/chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java b/chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java
index a89c1f6a..80917c0f 100644
--- a/chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java
+++ b/chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java
@@ -1,4 +1,4 @@
-/**
+/*
* DO NOT REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Contributor(s):
@@ -15,10 +15,9 @@
package com.seaofnodes.simple.lexer;
-import com.seaofnodes.simple.common.ErrorListener;
+import com.seaofnodes.simple.lexer.ecstasy.ErrorListener;
import com.seaofnodes.simple.lexer.ecstasy.Lexer;
import com.seaofnodes.simple.lexer.ecstasy.Source;
-import com.seaofnodes.simple.parser.Ast;
import com.seaofnodes.simple.parser.Parser;
import org.junit.Assert;
import org.junit.Test;
@@ -28,30 +27,28 @@ public class TestParser {
@Test
public void testParseSingleDecl()
{
- final String source = "var i: Int;";
+ final String source = "int i;";
Lexer lexer = new Lexer(new Source(source), new ErrorListener());
Parser parser = new Parser(lexer);
var ast = parser.parse();
- Assert.assertTrue(ast instanceof Ast.Block
- && ((Ast.Block) ast).stmtList.size() == 1);
+ Assert.assertEquals("{int i;}", ast.toString());
}
@Test
public void testParseTwoDecls() {
- final String source = "var i: Int;\nvar j: Int;";
+ final String source = "int i;\nint j;";
Lexer lexer = new Lexer(new Source(source), new ErrorListener());
Parser parser = new Parser(lexer);
var ast = parser.parse();
- Assert.assertTrue(ast instanceof Ast.Block
- && ((Ast.Block) ast).stmtList.size() == 2);
+ Assert.assertEquals("{int i;int j;}", ast.toString());
}
@Test
public void testIfAndWhile() {
final String source =
"""
- var i: Int;
- var j: Int;
+ int i;
+ int j;
i = 0;
j = 100;
@@ -64,5 +61,6 @@ public class TestParser {
Lexer lexer = new Lexer(new Source(source), new ErrorListener());
Parser parser = new Parser(lexer);
var ast = parser.parse();
+ Assert.assertEquals("{int i;int j;i=0;j=100;while(1) {i=(i+1);j=(j-1);if((i>=j)) break;}}", ast.toString());
}
}