diff options
| author | Cliff Click <cliffc@acm.org> | 2024-08-18 10:37:43 -0700 |
|---|---|---|
| committer | Thalia Archibald <thalia@archibald.dev> | 2024-09-07 10:54:48 -0700 |
| commit | a04599b6fc90bbab443d883595a415238586a526 (patch) | |
| tree | 5dc872cfb088233d7090ac1be892728fe956ab09 /chapter14/src/test/java/com | |
| parent | dead068fc0e3d637419fa5508c32856bc8340dc9 (diff) | |
| download | Simple-a04599b6fc90bbab443d883595a415238586a526.tar.gz Simple-a04599b6fc90bbab443d883595a415238586a526.zip | |
Shift operators; sign extension
Diffstat (limited to 'chapter14/src/test/java/com')
| -rw-r--r-- | chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java index f76e1903..268111d8 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java @@ -89,4 +89,30 @@ return f.b; assertEquals("return 1;", stop.toString()); assertEquals(1L, Evaluator.evaluate(stop, 0)); } + + @Test + public void testSigned() { + Parser parser = new Parser( +""" +i8 b = 255; // Chopped +return b; // Sign extend +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return -1;", stop.toString()); + assertEquals(-1L, Evaluator.evaluate(stop, 0)); + } + + @Test + public void testMask() { + Parser parser = new Parser( +""" +u16 mask = (1<<16)-1; // AND mask +int c = 123456789 & mask; +return c; // +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 52501;", stop.toString()); + assertEquals(52501L, Evaluator.evaluate(stop, 0)); + } + } |
