summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-30 11:32:18 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-30 13:28:46 +0100
commitcfb59a62fbdcbecb3b842e3df0bea3b6d159007c (patch)
treecc2a19bd88a58142bd3934c7f7d82f03de06d071 /src/test/java
parenta7d5133ac7cc82e3826f90d2e5f1ca5cd3f08676 (diff)
Add explicit visibility to TypeScript AST
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java30
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java6
3 files changed, 32 insertions, 10 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 bc02855..bca5ab3 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
@@ -76,9 +76,11 @@ public class TypescriptWriterTests {
var typescript = TypescriptClassDeclaration.arbitrary()
.withName(id("X"))
.addBodyElement(TypescriptClassFieldDeclaration.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.withName(id("a"))
)
.addBodyElement(TypescriptClassFieldDeclaration.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.withName(id("b"))
)
.build();
@@ -87,9 +89,9 @@ public class TypescriptWriterTests {
assertThat(string, equalTo("""
class X {
- a;
+ public a;
- b;
+ public b;
}"""
));
}
@@ -146,18 +148,21 @@ public class TypescriptWriterTests {
@Test
public void emptyClassConstructor() throws IOException {
- var typescript = TypescriptClassConstructor.arbitrary().build();
+ var typescript = TypescriptClassConstructor.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
+ .build();
var string = write(writer -> writer.writeClassElement(typescript));
assertThat(string, equalTo("""
- constructor() {
+ public constructor() {
}"""));
}
@Test
public void classConstructorWithParams() throws IOException {
var typescript = TypescriptClassConstructor.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.addParam(TypescriptParam.arbitrary()
.withName(id("a"))
.withType(ref("number"))
@@ -171,13 +176,14 @@ public class TypescriptWriterTests {
var string = write(writer -> writer.writeClassElement(typescript));
assertThat(string, equalTo("""
- constructor(a: number, b: string) {
+ public constructor(a: number, b: string) {
}"""));
}
@Test
public void classConstructorWithBody() throws IOException {
var typescript = TypescriptClassConstructor.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.addBodyElement(TypescriptExpressionStatement.arbitrary().withExpression(num(1)))
.addBodyElement(TypescriptExpressionStatement.arbitrary().withExpression(num(2)))
.build();
@@ -185,7 +191,7 @@ public class TypescriptWriterTests {
var string = write(writer -> writer.writeClassElement(typescript));
assertThat(string, equalTo("""
- constructor() {
+ public constructor() {
1.0;
2.0;
}"""));
@@ -196,41 +202,45 @@ public class TypescriptWriterTests {
@Test
public void classFieldDeclarationWithoutInitialValue() throws IOException {
var typescript = TypescriptClassFieldDeclaration.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.withName(id("a"))
.build();
var string = write(writer -> writer.writeClassElement(typescript));
- assertThat(string, equalTo("a;"));
+ assertThat(string, equalTo("public a;"));
}
@Test
public void classFieldDeclarationWithExplicitType() throws IOException {
var typescript = TypescriptClassFieldDeclaration.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.withName(id("a"))
.withType(ref("number"))
.build();
var string = write(writer -> writer.writeClassElement(typescript));
- assertThat(string, equalTo("a: number;"));
+ assertThat(string, equalTo("public a: number;"));
}
@Test
public void classFieldDeclarationWithInitialValue() throws IOException {
var typescript = TypescriptClassFieldDeclaration.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.withName(id("a"))
.withInitialValue(num(42))
.build();
var string = write(writer -> writer.writeClassElement(typescript));
- assertThat(string, equalTo("a = 42.0;"));
+ assertThat(string, equalTo("public a = 42.0;"));
}
@Test
public void classFieldDeclarationWithTypeAndInitialValue() throws IOException {
var typescript = TypescriptClassFieldDeclaration.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
.withName(id("a"))
.withType(ref("number"))
.withInitialValue(num(42))
@@ -238,7 +248,7 @@ public class TypescriptWriterTests {
var string = write(writer -> writer.writeClassElement(typescript));
- assertThat(string, equalTo("a: number = 42.0;"));
+ assertThat(string, equalTo("public a: number = 42.0;"));
}
private static TypescriptRef ref(String value) {
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java
index 7157675..5110453 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassConstructorMatcher.java
@@ -30,6 +30,12 @@ public final class TypescriptClassConstructorMatcher implements org.zwobble.prec
return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructor.class, this.submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher withVisibility(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptVisibility> visibility) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructor>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("visibility", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructor::visibility, (org.zwobble.precisely.Matcher) visibility));
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructorMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptParam>> params) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructor>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassConstructor::params, (org.zwobble.precisely.Matcher) params));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java
index 3942fb4..718e4ae 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java
@@ -36,6 +36,12 @@ public final class TypescriptClassFieldDeclarationMatcher implements org.zwobble
return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher withVisibility(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptVisibility> visibility) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("visibility", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration::visibility, (org.zwobble.precisely.Matcher) visibility));
+ return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclarationMatcher withType(org.zwobble.precisely.Matcher<? super java.util.Optional<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.TypescriptClassFieldDeclaration>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration::type, (org.zwobble.precisely.Matcher) type));