diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-31 22:58:36 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-31 22:58:36 +0100 |
| commit | b853399ce5ab5adb1a8899265d106ae1ab96bb35 (patch) | |
| tree | 2fd1f63f8686e27775586a6a0e027fbddc7e1ca2 /src/test/java | |
| parent | 30c7a202bbc3928cbc321974e417ef902e719692 (diff) | |
Add type unions to TypeScript AST
Diffstat (limited to 'src/test/java')
2 files changed, 56 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 56cbc6c..b6f666e 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 @@ -432,6 +432,21 @@ public class TypescriptWriterTests { assertThat(string, equalTo("x")); } + // === Type unions === + + @Test + public void typeUnion() throws IOException { + var typescript = TypescriptTypeUnion.arbitrary() + .addVariant(ref("X")) + .addVariant(ref("Y")) + .addVariant(ref("Z")) + .build(); + + var string = write(writer -> writer.writeExpression(typescript)); + + assertThat(string, equalTo("X | Y | Z")); + } + // == Utilities == private static TypescriptIdentifier id(String name) { diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeUnionMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeUnionMatcher.java new file mode 100644 index 0000000..66cc995 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeUnionMatcher.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.TypescriptTypeUnionMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnionMatcher imports + +public final class TypescriptTypeUnionMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnionMatcher isTypescriptTypeUnion() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnionMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion>> submatchers; + + private TypescriptTypeUnionMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion>> 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.TypescriptTypeUnion.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnionMatcher withVariants(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression>> variants) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("variants", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnion::variants, (org.zwobble.precisely.Matcher) variants)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnionMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnionMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeUnionMatcher body +} |
