From d6442ce5d00b9bea52d366ff4d6ae8c03b84aabb Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Mon, 1 Jul 2024 08:42:23 -0700 Subject: Fix grammar and forward-port minor changes (#91) * Backport test exception handling to chapter 1 * Add unary ! to chapter 10 and 11 grammars * Lex { } ! as punctuation * Forward-port format whitespace * Forward-port test organization * Forward-port replace build-graphs.sh with Makefile * Add chapter title to chapter 11 --- .../java/com/seaofnodes/simple/Chapter01Test.java | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'chapter01/src/test/java') diff --git a/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java b/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java index 6989d0b9..a91aabb1 100644 --- a/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java +++ b/chapter01/src/test/java/com/seaofnodes/simple/Chapter01Test.java @@ -1,17 +1,12 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.node.*; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import static org.junit.Assert.*; public class Chapter01Test { - @Rule - public ExpectedException exceptionRule = ExpectedException.none(); - @Test public void testSimpleProgram() { Parser parser = new Parser("return 1;"); @@ -60,9 +55,12 @@ public class Chapter01Test { @Test public void testBad3() { - exceptionRule.expect(RuntimeException.class); - exceptionRule.expectMessage("Syntax error, expected integer literal"); - new Parser("return --12;").parse(); + try { + new Parser("return --12;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Syntax error, expected integer literal",e.getMessage()); + } } @Test @@ -78,9 +76,12 @@ public class Chapter01Test { // Negative numbers require unary operator support that is not in scope @Test public void testBad5() { - exceptionRule.expect(RuntimeException.class); - exceptionRule.expectMessage("Syntax error, expected integer literal"); - new Parser("return -100;").parse(); + try { + new Parser("return -100;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Syntax error, expected integer literal",e.getMessage()); + } } @Test -- cgit v1.2.3