aboutsummaryrefslogtreecommitdiff
path: root/watcher_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-01-06 02:54:52 +0700
committerShulhan <ms@kilabit.info>2025-01-07 00:13:55 +0700
commit85ae94f62b75372943a8ffdd705ce932a7849a8d (patch)
treeff55363d9e47729ce5d3c0be9fafa54d2cbd2e30 /watcher_test.go
parent6593f4d2069790c73595f14b3312a8d83e61760e (diff)
downloadciigo-85ae94f62b75372943a8ffdd705ce932a7849a8d.tar.xz
all: auto convert markup when HTTP client request GET to HTML file
In development mode, where [ServeOptions.IsDevelopment] is set to true or when running "ciigo serve", the ciigo HTTP server will check if the new markup file is newer than HTML file when user press refresh or reload on the browser. If its newer, it will convert the markup file and return the new content of HTML file.
Diffstat (limited to 'watcher_test.go')
-rw-r--r--watcher_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/watcher_test.go b/watcher_test.go
index 9067d57..1b9f3fa 100644
--- a/watcher_test.go
+++ b/watcher_test.go
@@ -255,3 +255,43 @@ func removeFooter(in []byte, nlast int) (out []byte) {
out = bytes.Join(lines, []byte("\n"))
return out
}
+
+func TestWatcherGetFileMarkupByHTML(t *testing.T) {
+ var w = watcher{
+ fileMarkups: map[string]*FileMarkup{
+ `/markup/with/adoc/file.adoc`: &FileMarkup{
+ kind: markupKindAdoc,
+ },
+ `/markup/with/md/file.md`: &FileMarkup{
+ kind: markupKindMarkdown,
+ },
+ },
+ }
+
+ var listCase = []struct {
+ expFileMarkup *FileMarkup
+ fileHTML string
+ expIsNew bool
+ }{{
+ fileHTML: `/notexist.html`,
+ }, {
+ fileHTML: `/markup/with/adoc/file.html`,
+ expFileMarkup: w.fileMarkups[`/markup/with/adoc/file.adoc`],
+ }, {
+ fileHTML: `/markup/with/adoc/file.HTML`,
+ expFileMarkup: w.fileMarkups[`/markup/with/adoc/file.adoc`],
+ }, {
+ fileHTML: `/markup/with/md/file.HTML`,
+ expFileMarkup: w.fileMarkups[`/markup/with/md/file.md`],
+ }}
+
+ var (
+ gotFileMarkup *FileMarkup
+ gotIsNew bool
+ )
+ for _, tcase := range listCase {
+ gotFileMarkup, gotIsNew = w.getFileMarkupByHTML(tcase.fileHTML)
+ test.Assert(t, tcase.fileHTML, tcase.expFileMarkup, gotFileMarkup)
+ test.Assert(t, tcase.fileHTML+` isNew`, tcase.expIsNew, gotIsNew)
+ }
+}