summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-10-24 23:16:03 +0100
committerMichael Williamson <mike@zwobble.org>2026-10-24 23:16:03 +0100
commit52361b8938acd93894b0f3ec3d5992e602929400 (patch)
treead4dc9d8ad9f9ecf03c843d432b3de86f6e4a7a4 /src/test/java
parent5c83ab1e74bf8877433c085340f7bf25d2079f77 (diff)
Add strip command
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/CodeWriterTests.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/CodeWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/CodeWriterTests.java
index decea99..9e3f900 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/CodeWriterTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/CodeWriterTests.java
@@ -134,4 +134,81 @@ public class CodeWriterTests {
assertThat(stringWriter.toString(), equalTo(""));
assertThat(file.isWriterOpened(), equalTo(false));
}
+
+ @Test
+ public void strippingDoesNothingToFileWithoutHeader() {
+ var originalContents = """
+ Hello, world!
+ """;
+
+ var result = CodeWriter.stripFileContents(
+ originalContents,
+ new CodeWriter.CodeWriterConfig("//")
+ );
+
+ assertThat(result, equalTo(new CodeWriter.StripResult.Unchanged()));
+ }
+
+ @Test
+ public void whenFileHasNoCustomAreasThenFileIsDeleted() {
+ var originalContents = """
+ // Generated by hobgoblin.
+
+ Hello, world!
+ """;
+
+ var result = CodeWriter.stripFileContents(
+ originalContents,
+ new CodeWriter.CodeWriterConfig("//")
+ );
+
+ assertThat(result, equalTo(new CodeWriter.StripResult.Delete()));
+ }
+
+ @Test
+ public void whenCustomAreasAreAllEmptyThenFileIsDeleted() {
+ var originalContents = """
+ // Generated by hobgoblin.
+
+ Before
+ // Custom area start: body
+ // Custom area end: body
+ After
+ """;
+
+ var result = CodeWriter.stripFileContents(
+ originalContents,
+ new CodeWriter.CodeWriterConfig("//")
+ );
+
+ assertThat(result, equalTo(new CodeWriter.StripResult.Delete()));
+ }
+
+ @Test
+ public void nonEmptyCustomAreasArePreserved() {
+ var originalContents = """
+ // Generated by hobgoblin.
+
+ Before
+ // Custom area start: head
+ Custom head.
+ // Custom area end: head
+ // Custom area start: body
+ // Custom area end: body
+ After
+ """;
+
+ var result = CodeWriter.stripFileContents(
+ originalContents,
+ new CodeWriter.CodeWriterConfig("//")
+ );
+
+ assertThat(result, equalTo(new CodeWriter.StripResult.NewContent("""
+ // Generated by hobgoblin.
+
+ // Custom area start: head
+ Custom head.
+ // Custom area end: head
+ """)));
+ }
}