diff options
| author | Cliff Click <cliffc@acm.org> | 2024-08-18 09:40:56 -0700 |
|---|---|---|
| committer | Thalia Archibald <thalia@archibald.dev> | 2024-09-07 10:54:48 -0700 |
| commit | dead068fc0e3d637419fa5508c32856bc8340dc9 (patch) | |
| tree | 78905e4ab4a628a08ae63d501b7117591f7c07bf /chapter14/src/test | |
| parent | 2af636382e865b93250270e903499cfd28eb6052 (diff) | |
| download | Simple-dead068fc0e3d637419fa5508c32856bc8340dc9.tar.gz Simple-dead068fc0e3d637419fa5508c32856bc8340dc9.zip | |
handle all unsigned int variants
and-masking and typenames for all!
Diffstat (limited to 'chapter14/src/test')
| -rw-r--r-- | chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java | 2 | ||||
| -rw-r--r-- | chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java | 44 |
2 files changed, 43 insertions, 3 deletions
diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java index 8eceb0fa..99c08f16 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java @@ -169,6 +169,6 @@ n.i = 3.14; return n.i; """); try { parser.parse(true).iterate(true); fail(); } - catch( Exception e ) { assertEquals("Cannot store 3.14 into field IntBot i",e.getMessage()); } + catch( Exception e ) { assertEquals("Cannot store 3.14 into field int i",e.getMessage()); } } } diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java index 4bf04b88..f76e1903 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java @@ -42,11 +42,51 @@ return c; """ u8 b = 123; b = b + 456;// Truncate -return 67; +return b; """); StopNode stop = parser.parse(false).iterate(false); assertEquals("return 67;", stop.toString()); - assertEquals(67, Evaluator.evaluate(stop, 0)); + assertEquals(67L, Evaluator.evaluate(stop, 0)); } + @Test + public void testU1() { + Parser parser = new Parser( +""" +bool b = 123; +b = b + 456;// Truncate +u1 c = b; // No more truncate needed +return c; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 1;", stop.toString()); + assertEquals(1L, Evaluator.evaluate(stop, 0)); + } + + @Test + public void testAnd() { + Parser parser = new Parser( +""" +int b = 123; +b = b+456 & 31; // Precedence +return b; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 3;", stop.toString()); + assertEquals(3L, Evaluator.evaluate(stop, 0)); + } + + @Test + public void testRefLoad() { + Parser parser = new Parser( +""" +struct Foo { u1 b; } +Foo f = new Foo; +f.b = 123; +return f.b; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 1;", stop.toString()); + assertEquals(1L, Evaluator.evaluate(stop, 0)); + } } |
