summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/LiteralTest.java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-08-10 11:11:18 -0700
committerCliff Click <cliffc@acm.org>2026-10-08 16:52:27 -0700
commitd32f97238c903765dec4e9a9f3cbfa5fd12cded6 (patch)
treea5ac731801ef7066bab6359c4e85c2bdd20082a6 /src/test/java/com/seaofnodes/simple/LiteralTest.java
parentb5ebb2032aa04cf4506d533127d373d4cf5a25c6 (diff)
downloadSimple-linear.tar.gz
Simple-linear.zip
Chapter 25: Modules, Separate Compilation, and SSA Constructionlinear
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/LiteralTest.java')
-rw-r--r--src/test/java/com/seaofnodes/simple/LiteralTest.java65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/test/java/com/seaofnodes/simple/LiteralTest.java b/src/test/java/com/seaofnodes/simple/LiteralTest.java
deleted file mode 100644
index 09ee30f5..00000000
--- a/src/test/java/com/seaofnodes/simple/LiteralTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.seaofnodes.simple;
-
-import com.seaofnodes.simple.codegen.CodeGen;
-import com.seaofnodes.simple.type.TypeConAryB;
-import com.seaofnodes.simple.type.TypeInteger;
-import com.seaofnodes.simple.type.TypeMemPtr;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class LiteralTest {
- private static final String[] ESCAPES = {"\\0", "\\n", "\\t", "\\r", "\\\\", "\\\"", "\\'"};
- private static final int[] VALUES = {0, 10, 9, 13, 92, 34, 39};
-
- @Test public void testStringEscapes() {
- for (int i = 0; i < ESCAPES.length; i++)
- assertString(ESCAPES[i], new byte[]{(byte)VALUES[i]});
- assertString("a\\\"b\\\\c\\0d", new byte[]{97, 34, 98, 92, 99, 0, 100});
- assertString("", new byte[]{});
- assertString("plain", new byte[]{112, 108, 97, 105, 110});
- }
-
- private static void assertString(String text, byte[] expected) {
- var code = new CodeGen("return \"" + text + "\";").parse().opto().typeCheck();
- TypeMemPtr ptr = (TypeMemPtr)code.expr()._type;
- TypeConAryB bytes = (TypeConAryB)ptr._obj.field("[]")._t;
- assertArrayEquals(text, expected, bytes._ary);
- }
-
- @Test public void testCharacterEscapes() {
- for (int i = 0; i < ESCAPES.length; i++)
- assertCharacter(ESCAPES[i], VALUES[i]);
- assertCharacter("A", 65);
- }
-
- private static void assertCharacter(String text, int expected) {
- var code = new CodeGen("return '" + text + "';").parse().opto().typeCheck();
- assertEquals(text, expected, ((TypeInteger)code.expr()._type).value());
- }
-
- @Test public void testMalformedStrings() {
- assertBadLiteral("return \"\\q\";", "Unknown string escape");
- assertBadLiteral("return \"abc", "Unclosed string");
- assertBadLiteral("return \"abc\\", "Unclosed string");
- // The quote closes the string at EOF; the missing token is the semicolon.
- assertBadLiteral("return \"plain\"", ";");
- }
-
- @Test public void testMalformedCharacters() {
- assertBadLiteral("return '\\q';", "Unknown character escape");
- assertBadLiteral("return '", "Unclosed character");
- assertBadLiteral("return '\\", "Unclosed character");
- assertBadLiteral("return '';", "Syntax error");
- assertBadLiteral("return 'ab';", "Syntax error");
- assertBadLiteral("return 'a", "Syntax error");
- }
-
- private static void assertBadLiteral(String src, String message) {
- try {
- new CodeGen(src).parse();
- fail("Accepted malformed literal: " + src);
- } catch (Parser.ParseException e) {
- assertTrue(e.getMessage(), e.getMessage().contains(message));
- }
- }
-}