@Test @DisplayName("Test character literals that are syntactically incorrect") void testBadStringLiterals() { final var sut = new CharacterLiteral(); Assertions.assertThrows(GeciException.class, () -> sut.apply(character("\n"))); Assertions.assertThrows(GeciException.class, () -> sut.apply(character("\r"))); Assertions.assertThrows(IllegalArgumentException.class, () -> sut.apply(character("\\z"))); Assertions.assertThrows(IllegalArgumentException.class, () -> sut.apply(character("\\"))); Assertions.assertThrows(IllegalArgumentException.class, () -> sut.apply(new StringBuilder("\'"))); Assertions.assertThrows(IllegalArgumentException.class, () -> sut.apply(new StringBuilder("\'\\"))); Assertions.assertThrows(IllegalArgumentException.class, () -> sut.apply(new StringBuilder("\'b"))); }
@Override public LexicalElement.CharacterLiteral apply(StringBuilder sb) { if (sb.length() == 0 || sb.charAt(0) != ENCLOSING) { return null; } final StringBuilder output = createOutput(sb, CHARACTER); final StringBuilder original = createOutput(sb, CHARACTER); sb.deleteCharAt(0); while (sb.length() > 0 && sb.charAt(0) != ENCLOSING) { final char ch = sb.charAt(0); if (ch == '\\') { handleEscape(sb, output,original); } else { handleNormalCharacter(sb, output,original); } } if (sb.length() == 0) { throw new IllegalArgumentException("Character is not terminated before eol"); } sb.deleteCharAt(0); return new LexicalElement.CharacterLiteral(output.toString(),original.toString()); }
CharacterLiteral implements LexEater { @Override public LexicalElement.CharacterLiteral apply(StringBuilder sb) { if (sb.length() == 0 || sb.charAt(0) != ENCLOSING) { return null; } final StringBuilder output = createOutput(sb, CHARACTER); final StringBuilder original = createOutput(sb, CHARACTER); sb.deleteCharAt(0); while (sb.length() > 0 && sb.charAt(0) != ENCLOSING) { final char ch = sb.charAt(0); if (ch == '\\') { handleEscape(sb, output,original); } else { handleNormalCharacter(sb, output,original); } } if (sb.length() == 0) { throw new IllegalArgumentException("Character is not terminated before eol"); } sb.deleteCharAt(0); return new LexicalElement.CharacterLiteral(output.toString(),original.toString()); } }
CharacterLiteral implements LexEater { @Override public LexicalElement.CharacterLiteral apply(StringBuilder sb) { if (sb.length() == 0 || sb.charAt(0) != ENCLOSING) { return null; } final StringBuilder output = createOutput(sb, CHARACTER); final StringBuilder original = createOutput(sb, CHARACTER); sb.deleteCharAt(0); while (sb.length() > 0 && sb.charAt(0) != ENCLOSING) { final char ch = sb.charAt(0); if (ch == '\\') { handleEscape(sb, output,original); } else { handleNormalCharacter(sb, output,original); } } if (sb.length() == 0) { throw new IllegalArgumentException("Character is not terminated before eol"); } sb.deleteCharAt(0); return new LexicalElement.CharacterLiteral(output.toString(),original.toString()); }  }
CharacterLiteral implements LexEater { @Override public LexicalElement.CharacterLiteral apply(StringBuilder sb) { if (sb.length() == 0 || sb.charAt(0) != ENCLOSING) { return null; } final StringBuilder output = createOutput(sb, CHARACTER); final StringBuilder original = createOutput(sb, CHARACTER); sb.deleteCharAt(0); while (sb.length() > 0 && sb.charAt(0) != ENCLOSING) { final char ch = sb.charAt(0); if (ch == '\\') { handleEscape(sb, output,original); } else { handleNormalCharacter(sb, output,original); } } if (sb.length() == 0) { throw new IllegalArgumentException("Character is not terminated before eol"); } sb.deleteCharAt(0); return new LexicalElement.CharacterLiteral(output.toString(),original.toString()); }  @Override LexicalElement.CharacterLiteral apply(StringBuilder sb); }
CharacterLiteral implements LexEater { @Override public LexicalElement.CharacterLiteral apply(StringBuilder sb) { if (sb.length() == 0 || sb.charAt(0) != ENCLOSING) { return null; } final StringBuilder output = createOutput(sb, CHARACTER); final StringBuilder original = createOutput(sb, CHARACTER); sb.deleteCharAt(0); while (sb.length() > 0 && sb.charAt(0) != ENCLOSING) { final char ch = sb.charAt(0); if (ch == '\\') { handleEscape(sb, output,original); } else { handleNormalCharacter(sb, output,original); } } if (sb.length() == 0) { throw new IllegalArgumentException("Character is not terminated before eol"); } sb.deleteCharAt(0); return new LexicalElement.CharacterLiteral(output.toString(),original.toString()); }  @Override LexicalElement.CharacterLiteral apply(StringBuilder sb);  }