diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-09-27 11:06:03 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-27 11:06:03 +0100 |
| commit | bc817ec7c383a015daf015626ef71f6d071b519c (patch) | |
| tree | 0af7d9639d5ee1a1043def6560d773eafd287aed /src/test/java | |
| parent | 416a876e17a6ea6b2d2440726b81343b0d6c0c2c (diff) | |
Add string literals to TypeScript AST
Diffstat (limited to 'src/test/java')
2 files changed, 67 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java index 4963e09..86a94ea 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java @@ -567,6 +567,26 @@ public class TypescriptWriterTests { assertThat(string, equalTo("x")); } + // === String literals === + + @Test + public void stringLiteral() throws IOException { + var typescript = string("hello"); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("\"hello\"")); + } + + @Test + public void stringLiteralWithSpecialCharacters() throws IOException { + var typescript = string("\"\\\n\r\u000b\t\b\f"); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("\"\\\"\\\\\\n\\r\\v\\t\\b\\f\"")); + } + // === typeof === @Test @@ -615,6 +635,12 @@ public class TypescriptWriterTests { .build(); } + private static TypescriptStringLiteral string(String value) { + return TypescriptStringLiteral.arbitrary() + .withValue(value) + .build(); + } + private String write(TypescriptWriter.Write write) throws IOException { return write(write, Optional.empty()); } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptStringLiteralMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptStringLiteralMatcher.java new file mode 100644 index 0000000..8dd0f6a --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptStringLiteralMatcher.java @@ -0,0 +1,41 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher imports + +public final class TypescriptStringLiteralMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher isTypescriptStringLiteral() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteral>> submatchers; + + private TypescriptStringLiteralMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteral>> submatchers + ) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteral.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher withValue(org.zwobble.precisely.Matcher<? super String> value) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteral>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteral::value, (org.zwobble.precisely.Matcher) value)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStringLiteralMatcher body +} |
