From 475f66adc7c1c9f1cd479c4492999eae4c060c5b Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 12 Oct 2024 14:10:40 -0700 Subject: Add a first test to code to --- .../java/com/seaofnodes/simple/Chapter16Test.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java (limited to 'chapter16/src/test/java') diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java new file mode 100644 index 00000000..d49d7ede --- /dev/null +++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java @@ -0,0 +1,39 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.evaluator.Evaluator; +import com.seaofnodes.simple.node.StopNode; +import org.junit.Test; +import org.junit.Ignore; + +import java.nio.charset.StandardCharsets; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class Chapter16Test { + + @Test + public void testJig() { + Parser parser = new Parser( +""" +return 3.14; +"""); + StopNode stop = parser.parse().iterate(); + assertEquals("return 3.14;", stop.toString()); + assertEquals(3.14, Evaluator.evaluate(stop, 0)); + } + + @Test + public void testBasicFinal() { + Parser parser = new Parser( +""" +struct Point { int !x, !y; } +Point p = new P { x=3; y=4; } +return p; +"""); + StopNode stop = parser.parse().iterate(); + assertEquals("return P;", stop.toString()); + assertEquals(3.14, Evaluator.evaluate(stop, 0)); + } + +} -- cgit v1.2.3