summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-30 15:16:58 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-30 15:16:58 +0100
commit119324389887cf76e7e0f52bcb9c1067ede463d4 (patch)
tree76fb573ae03d0689702194b00a706d87f4ece1ad /src/test/java
parent3a6771834e55a64c04337bb0ee83fbfc57524edf (diff)
Add type parameters to class declaration in TypeScript AST
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java17
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.java41
3 files changed, 64 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 2606dd4..81dd965 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
@@ -72,6 +72,23 @@ public class TypescriptWriterTests {
}
@Test
+ public void classDeclarationWithTypeParams() throws IOException {
+ var typescript = TypescriptClassDeclaration.arbitrary()
+ .withName(id("X"))
+ .addTypeParam(TypescriptTypeParam.arbitrary().withName(id("Y")))
+ .addTypeParam(TypescriptTypeParam.arbitrary().withName(id("Z")))
+ .build();
+
+ var string = write(writer -> writer.writeStatement(typescript));
+
+ assertThat(string, equalTo("""
+ class X<Y, Z> {
+ }"""
+ ));
+ }
+
+
+ @Test
public void classDeclarationWithElements() throws IOException {
var typescript = TypescriptClassDeclaration.arbitrary()
.withName(id("X"))
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java
index 46eeaa2..188df2d 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassDeclarationMatcher.java
@@ -36,6 +36,12 @@ public final class TypescriptClassDeclarationMatcher implements org.zwobble.prec
return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher withTypeParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParam>> typeParams) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("typeParams", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration::typeParams, (org.zwobble.precisely.Matcher) typeParams));
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclarationMatcher withBody(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassElement>> body) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassDeclaration::body, (org.zwobble.precisely.Matcher) body));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.java
new file mode 100644
index 0000000..635fa27
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptTypeParamMatcher.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.TypescriptTypeParamMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher imports
+
+public final class TypescriptTypeParamMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher isTypescriptTypeParam() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParam>> submatchers;
+
+ private TypescriptTypeParamMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParam>> 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.TypescriptTypeParam.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher 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.TypescriptTypeParam>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParam::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptTypeParamMatcher body
+}