From e2b042bd9721995486f4f0cf96847c02d27908e3 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 24 Oct 2026 15:26:23 -0700 Subject: Fix chained comparisons and restore recursion coverage --- .../seaofnodes/simple/ChainedComparisonTest.java | 37 ++++++++++++++++++++++ .../java/com/seaofnodes/simple/Chapter13Test.java | 6 ++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 chapter23/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java (limited to 'chapter23/src/test') diff --git a/chapter23/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java b/chapter23/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java new file mode 100644 index 00000000..99f18e62 --- /dev/null +++ b/chapter23/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java @@ -0,0 +1,37 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.type.TypeInteger; +import org.junit.Test; +import static org.junit.Assert.*; + +public class ChainedComparisonTest { + @Test public void testAdjacentOperandsAndOperators() { + String[] expressions = {"10 < arg < 20", "0 < arg <= 3", "3 >= arg > 0", + "0 <= arg < 3", "0 < arg <= 3 < 4"}; + String[][] expected = {{"0","0","1","0"}, {"0","1","0","0"}, + {"0","1","0","0"}, {"1","0","0","0"}, + {"0","1","0","0"}}; + int[] args = {0,3,15,30}; + for(int i=0;i 1;").parse(); + fail("mixed directions"); + } catch(RuntimeException e) { + assertEquals("Mixing relational directions in a chained relational test",e.getMessage()); + } + } +} diff --git a/chapter23/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/chapter23/src/test/java/com/seaofnodes/simple/Chapter13Test.java index 6451ad1d..9a645833 100644 --- a/chapter23/src/test/java/com/seaofnodes/simple/Chapter13Test.java +++ b/chapter23/src/test/java/com/seaofnodes/simple/Chapter13Test.java @@ -8,9 +8,11 @@ import static org.junit.Assert.assertEquals; public class Chapter13Test { - // A placeholder test used to rapidly rotate through fuzzer produced issues + // Historical fuzzer scratch: its mixed-direction comparisons use the old + // left-associative syntax. Chapter 23 now rejects them as invalid chains. + @org.junit.Ignore("Pre-chaining fuzzer scratch; mixed relational directions") @Test - public void testFuzzer() { + public void testJigFuzzer() { CodeGen code = new CodeGen( """ while(---- -arg) { -- cgit v1.2.3