From 85ae94f62b75372943a8ffdd705ce932a7849a8d Mon Sep 17 00:00:00 2001 From: Shulhan Date: Mon, 6 Jan 2025 02:54:52 +0700 Subject: 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. --- watcher_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'watcher_test.go') 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) + } +} -- cgit v1.3