diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-09-19 21:48:26 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-19 21:48:26 +0100 |
| commit | 3563b294bfaeb494511d6542301ea2a3b77091d5 (patch) | |
| tree | f97e823708849501b69252567315bc258b4f1ec7 /src/test/java | |
| parent | 72b49c434662cc5df5294c89eb349ae1dfb70972 (diff) | |
Add imports to TypeScript AST
Diffstat (limited to 'src/test/java')
4 files changed, 132 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 56c51f5..7497421 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 @@ -35,6 +35,38 @@ public class TypescriptWriterTests { } @Test + public void moduleWithImports() throws IOException { + var typescript = TypescriptModule.arbitrary() + .addImport(TypescriptImportDeclaration.arbitrary() + .addNamedImport(TypescriptNamedImport.arbitrary() + .withExportName(id("Rectangle")) + .withImportName(id("ShapeRectangle")) + ) + .addNamedImport(TypescriptNamedImport.arbitrary() + .withExportName(id("Triangle")) + .withImportName(id("ShapeTriangle")) + ) + .withFromModule("./shapes") + ) + .build(); + + var string = write(writer -> writer.writeModule(typescript)); + + assertThat(string, equalTo(""" + // Generated by hobgoblin. + + // Custom area start: imports + // Custom area end: imports + + import {Rectangle as ShapeRectangle, Triangle as ShapeTriangle} from "./shapes"; + + // Custom area start: body + // Custom area end: body + """ + )); + } + + @Test public void moduleWithStatements() throws IOException { var typescript = TypescriptModule.arbitrary() .addBodyElement(TypescriptClassDeclaration.arbitrary() diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclarationMatcher.java new file mode 100644 index 0000000..f2989ad --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptImportDeclarationMatcher.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.TypescriptImportDeclarationMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher imports + +public final class TypescriptImportDeclarationMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher isTypescriptImportDeclaration() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>> submatchers; + + private TypescriptImportDeclarationMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>> 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.TypescriptImportDeclaration.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher withNamedImports(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>> namedImports) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("namedImports", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration::namedImports, (org.zwobble.precisely.Matcher) namedImports)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher withFromModule(org.zwobble.precisely.Matcher<? super String> fromModule) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("fromModule", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration::fromModule, (org.zwobble.precisely.Matcher) fromModule)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclarationMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java index fdae828..9996e06 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java @@ -36,6 +36,12 @@ public final class TypescriptModuleMatcher implements org.zwobble.precisely.Matc return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher withImports(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptImportDeclaration>> imports) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("imports", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule::imports, (org.zwobble.precisely.Matcher) imports)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(submatchers); + } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher withBody(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptStatement>> body) { var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule>>(this.submatchers); submatchers.add(org.zwobble.precisely.Matchers.has("body", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule::body, (org.zwobble.precisely.Matcher) body)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImportMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImportMatcher.java new file mode 100644 index 0000000..3b85311 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNamedImportMatcher.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.TypescriptNamedImportMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher imports + +public final class TypescriptNamedImportMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher isTypescriptNamedImport() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher(java.util.List.of()); + } + + private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>> submatchers; + + private TypescriptNamedImportMatcher( + java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>> 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.TypescriptNamedImport.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher withExportName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> exportName) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("exportName", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport::exportName, (org.zwobble.precisely.Matcher) exportName)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher(submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher withImportName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier> importName) { + var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport>>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("importName", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImport::importName, (org.zwobble.precisely.Matcher) importName)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNamedImportMatcher body +} |
