From 477c71d89d107936cd0c4776bb2d5ff37cb91539 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Wed, 13 Nov 2024 20:53:05 -0800 Subject: Allow oper-assign, += -= etc --- .../java/com/seaofnodes/simple/Chapter17Test.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'chapter17/src/test/java/com') diff --git a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java index b1f7eb43..176a9236 100644 --- a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java +++ b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java @@ -105,6 +105,14 @@ return s.x; assertEquals(255L, Evaluator.evaluate(stop, 0)); } + @Test + public void testInc8() { + Parser parser = new Parser("int x; x+=2; return x+=3;"); + StopNode stop = parser.parse().iterate(); + assertEquals("return 5;", stop.toString()); + assertEquals(5L, Evaluator.evaluate(stop, 0)); + } + // --------------------------------------------------------------- @Test public void testVar0() { Parser parser = new Parser("var d; return d;"); @@ -288,7 +296,7 @@ return b ? b.next ? b.next.x : b.x; // parses "b ? (b.next ? b.next.x : b.x) : 0 Parser parser = new Parser(""" int sum=0; for( int i=0; i=arg ) break; - sum = sum + i; + sum += i; } return sum; """); @@ -329,7 +337,7 @@ return sum; Parser parser = new Parser(""" int sum=0; for( int i=0; i