diff options
| author | Cliff Click <cliffc@acm.org> | 2026-08-10 11:11:18 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-01 10:33:55 -0800 |
| commit | f66ab11456244b12c48ee9231cec5c8b54b47efe (patch) | |
| tree | aaf80846f49bad4cc24487306eac7464804513d1 /src/test/java/com/seaofnodes/simple/ParserTest.java | |
| parent | e646e5c534f8c5cbfd2969958cf6f4930e687aeb (diff) | |
| download | Simple-linear-chapter29.tar.gz Simple-linear-chapter29.zip | |
Chapter 29: Tech Debt Cleanuplinear-chapter29linear
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: Symious <14933944+symious@users.noreply.github.com>
Co-authored-by: Jun Kawasaki <jun784@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/ParserTest.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/ParserTest.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/java/com/seaofnodes/simple/ParserTest.java b/src/test/java/com/seaofnodes/simple/ParserTest.java new file mode 100644 index 00000000..364979f2 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/ParserTest.java @@ -0,0 +1,33 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.parser.Parser; +import org.junit.Test; +import static org.junit.Assert.*; + +public class ParserTest { + @Test public void testDeferredFragments() { + // The for update is scanned before the body, then parsed after it. + // Delimiters in strings, characters and comments must not end the scan. + String[] updates = {"n=n+\") (\"#", "n=n+')'", "n=n+/* ) */2", "n=n+{ -> 2; }()"}; + String[] results = {"6", "82", "4", "4"}; + for( int i = 0; i<updates.length; i++ ) { + CodeGen code = new CodeGen("int n=0; for(int i=0; i<2; "+updates[i]+") i++; return n;") + .driver(CodeGen.Phase.TypeCheck); + assertEquals(updates[i],results[i],Eval2.eval(code,0)); + } + // Declared constructor bodies use the same scanner with brace nesting. + CodeGen code = new CodeGen("struct Box { int x; new Box={ -> x=\"}\"#; }; }; return new Box().x;") + .driver(CodeGen.Phase.TypeCheck); + assertEquals("1",Eval2.eval(code,0)); + } + + @Test public void testUnclosedDeferredFragment() { + try { + new CodeGen("for(int i=0; i<2; i++").driver(CodeGen.Phase.TypeCheck); + fail("Accepted an unterminated for update"); + } catch( Parser.ParseException e ) { + assertEquals("Unclosed for update",e.getMessage()); + } + } +} |
