summaryrefslogtreecommitdiff
path: root/chapter03/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
authortannal <tannal2409@gmail.com>2025-01-19 00:21:18 +0800
committerCliff Click <cliffc@acm.org>2025-01-18 12:02:36 -0800
commit83bc7cc22d7ace761b6d1be565e2dc71d556d31e (patch)
treeecf5597c798e388776227071e2e8ce996c2cb995 /chapter03/src/test/java/com/seaofnodes
parent366059262e7360e07955c0a1f41ad89ffe44423b (diff)
downloadSimple-83bc7cc22d7ace761b6d1be565e2dc71d556d31e.tar.gz
Simple-83bc7cc22d7ace761b6d1be565e2dc71d556d31e.zip
Add a test for redefining variables in chapter 3
Diffstat (limited to 'chapter03/src/test/java/com/seaofnodes')
-rw-r--r--chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java b/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java
index bdb1d9ea..3b8b3449 100644
--- a/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java
+++ b/chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java
@@ -55,6 +55,16 @@ public class Chapter03Test {
}
@Test
+ public void testRedeclareVar() {
+ try {
+ new Parser("int a=1; int b=2; int c=0; int b=3; c=a+b;").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Redefining name 'b'",e.getMessage());
+ }
+ }
+
+ @Test
public void testBad1() {
try {
new Parser("int a=1; int b=2; int c=0; { int b=3; c=a+b;").parse();