summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-30 14:17:09 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-30 14:17:09 +0100
commit5a15eaebcad9fe95772d7391bb2cc5b1b2a8c0d2 (patch)
tree5cc435408a4039156245b65c9d00ef82df1a5666 /src/test/java
parentf6bdaa0381cfe762a0723085d666dce8eaf4434a (diff)
Mark fields as readonly in typescript-types
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java15
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptClassFieldDeclarationMatcher.java6
2 files changed, 20 insertions, 1 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 718f6e4..7ca267a 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
@@ -212,7 +212,7 @@ public class TypescriptWriterTests {
}
@Test
- public void staticClassFieldDeclarationWithoutInitialValue() throws IOException {
+ public void staticClassFieldDeclaration() throws IOException {
var typescript = TypescriptClassFieldDeclaration.arbitrary()
.withVisibility(TypescriptVisibility.PUBLIC)
.withName(id("a"))
@@ -225,6 +225,19 @@ public class TypescriptWriterTests {
}
@Test
+ public void readOnlyClassFieldDeclaration() throws IOException {
+ var typescript = TypescriptClassFieldDeclaration.arbitrary()
+ .withVisibility(TypescriptVisibility.PUBLIC)
+ .withName(id("a"))
+ .withIsReadOnly(true)
+ .build();
+
+ var string = write(writer -> writer.writeClassElement(typescript));
+
+ assertThat(string, equalTo("public readonly a;"));
+ }
+
+ @Test
public void classFieldDeclarationWithExplicitType() throws IOException {
var typescript = TypescriptClassFieldDeclaration.arbitrary()
.withVisibility(TypescriptVisibility.PUBLIC)
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 62a3f9e..f4afcc8 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
@@ -48,6 +48,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 withIsReadOnly(org.zwobble.precisely.Matcher<? super java.lang.Boolean> isReadOnly) {
+ 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("isReadOnly", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptClassFieldDeclaration::isReadOnly, (org.zwobble.precisely.Matcher) isReadOnly));
+ 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));