aboutsummaryrefslogtreecommitdiff
path: root/formatter/formatter_test.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-04-18 10:46:14 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-04-18 10:50:46 +0200
commite3740eb9075594d8a2e6e026c542b27f01fe8e9b (patch)
tree4a2dce9e21992d144cd6e3036c6de1d2b221b411 /formatter/formatter_test.go
parentbdcef09b529024e616e9400b110ee5b712db29ed (diff)
Add support for commentsv3.1.0
Diffstat (limited to 'formatter/formatter_test.go')
-rw-r--r--formatter/formatter_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/formatter/formatter_test.go b/formatter/formatter_test.go
index 4fe8035..870b904 100644
--- a/formatter/formatter_test.go
+++ b/formatter/formatter_test.go
@@ -252,3 +252,30 @@ func TestTrimRightSpaces(t *testing.T) {
t.Fatalf("trimRightSpaces() returned ā€˜%sā€™", sy)
}
}
+
+func TestPrintAstWithComments(t *testing.T) {
+ s := `
+ html lang="en" {
+ body {
+ / p {= Hello, Sailor!}
+ p {= Hello, World!}
+ }
+ }`
+ result := `<html lang="en"><body><p>Hello, World!</p></body></html>`
+
+ // Write the source to a temp file
+ r := strings.NewReader(s)
+ f, _ := os.CreateTemp("", "tmp*")
+ defer f.Close()
+ io.Copy(f, r)
+ f.Seek(0, 0)
+ ast, _ := parser.ParseFile(f)
+
+ redirectStdout()
+ PrintAst(ast)
+
+ out := restoreAndCapture()
+ if out != result {
+ t.Fatalf("PrintAst() printed unexpected string ā€˜%sā€™", out)
+ }
+}