diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-31 22:56:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-31 22:56:01 +0100 |
| commit | 30c7a202bbc3928cbc321974e417ef902e719692 (patch) | |
| tree | 65a835ded10f8d9f2403733404bb2fb6e8546df9 /src/test/java | |
| parent | 46005281330e2a001aba50a5c1358d9ae22334ec (diff) | |
Add type alias to TypeScript AST
Diffstat (limited to 'src/test/java')
2 files changed, 61 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 c7d2e2d..56cbc6c 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 @@ -159,6 +159,20 @@ public class TypescriptWriterTests { assertThat(string, equalTo("42.0;")); } + // === Type aliases === + + @Test + public void typeAlias() throws IOException { + var typescript = TypescriptTypeAlias.arbitrary() + .withName(id("X")) + .withType(ref("number")) + .build(); + + var string = write(writer -> writer.writeStatement(typescript)); + + assertThat(string, equalTo("type X = number;")); + } + // == Class elements == // === Class constructors === diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeAliasMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeAliasMatcher.java new file mode 100644 index 0000000..039e67b --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeAliasMatcher.java @@ -0,0 +1,47 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher imports + +public final class TypescriptTypeAliasMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher isTypescriptTypeAlias() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAlias>> submatchers; + + private TypescriptTypeAliasMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAlias>> 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.TypescriptTypeAlias.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher withName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> name) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAlias>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAlias::name, (org.zwobble.precisely.Matcher) name)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher withType(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression> type) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAlias>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAlias::type, (org.zwobble.precisely.Matcher) type)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeAliasMatcher body +} |
