diff options
| author | tannal <tannal2409@gmail.com> | 2025-01-19 00:21:18 +0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-01-18 12:02:36 -0800 |
| commit | 83bc7cc22d7ace761b6d1be565e2dc71d556d31e (patch) | |
| tree | ecf5597c798e388776227071e2e8ce996c2cb995 | |
| parent | 366059262e7360e07955c0a1f41ad89ffe44423b (diff) | |
| download | Simple-83bc7cc22d7ace761b6d1be565e2dc71d556d31e.tar.gz Simple-83bc7cc22d7ace761b6d1be565e2dc71d556d31e.zip | |
Add a test for redefining variables in chapter 3
| -rw-r--r-- | chapter03/src/test/java/com/seaofnodes/simple/Chapter03Test.java | 10 |
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(); |
