TSILGeneratorHelpers { public static int parseCharacterLiteral(String literal) throws IllegalArgumentException { if (literal.length() < 1) { throw new IllegalArgumentException("A character literal must have at least one character."); } if (literal.charAt(0) == '*') { if (literal.length() == 2) { switch (literal.charAt(1)) { case 'c': case 'C': return 13; case 'n': case 'N': return 10; case 't': case 'T': return 9; case 's': case 'S': return 32; case '\'': return 39; case '"': return 34; case '*': return 42; default: break; } } else if (literal.length() == 4 && literal.charAt(1) == '#') { return Integer.parseInt(literal.substring(2, 4), 16); } else { throw new IllegalArgumentException(String.format("Illegal literal escape sequence %s", literal)); } } else { if (literal.length() != 1) { throw new IllegalArgumentException("A normal character literal must be exactly one character."); } else { int literalValue = (int)literal.charAt(0); if (32 <= literalValue && literalValue <= 127) { return literalValue; } else { throw new IllegalArgumentException(String.format("The character %c is not permitted in a character literal.", literal.charAt(0))); } } } throw new IllegalArgumentException("The character literal provided is not legal."); }  static String generateTempVariable(); static NamedOperand resolveAbbreviations(NamedOperand<?> operand); static ILBlock<UUID,ILOp<UUID>> loadConstant(T value, String typeName); static ILBlock<UUID,ILOp<UUID>> parallel(List<ILBlock<UUID,ILOp<UUID>>> statementBlocks, List<Integer> workspaceIds); static int parseCharacterLiteral(String literal); static void abbreviate(Scope currentScope, NamedOperand operand, String name, String spec);  }
@Test public void testParseCharacterLiteral() { Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*c"), (int)'\r'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*C"), (int)'\r'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*n"), (int)'\n'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*N"), (int)'\n'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*t"), (int)'\t'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*T"), (int)'\t'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*s"), (int)' '); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*S"), (int)' '); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*'"), (int)'\''); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*\""), (int)'"'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("**"), (int)'*'); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*#00"), 0); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*#01"), 1); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*#6C"), 108); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("*#7F"), 127); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("a"), 97); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("A"), 65); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral("}"), 125); Assert.assertEquals(TSILGeneratorHelpers.parseCharacterLiteral(" "), 32); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("***")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("*")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("*nn")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("*a")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("*#")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("*#123")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("*#1")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("'*#01'")).isInstanceOf(IllegalArgumentException.class); assertThatThrownBy(() -> TSILGeneratorHelpers.parseCharacterLiteral("\n")).isInstanceOf(IllegalArgumentException.class); }