diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-09-01 08:14:13 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-09-01 08:14:13 -0600 |
commit | b8f1e92bfc9e690a318c9adc96370d60bbcdedd7 (patch) | |
tree | e239afb0cdfbe9a6c4004faa0c753c00407a483f /gopher/gophermap/htmlconv/convert_test.go | |
parent | 7bb8b79221740dd4a6d9a63c035e46087f4680fb (diff) |
gophermap->html conversion with overridable templates
Diffstat (limited to 'gopher/gophermap/htmlconv/convert_test.go')
-rw-r--r-- | gopher/gophermap/htmlconv/convert_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/gopher/gophermap/htmlconv/convert_test.go b/gopher/gophermap/htmlconv/convert_test.go new file mode 100644 index 0000000..1cdc8e2 --- /dev/null +++ b/gopher/gophermap/htmlconv/convert_test.go @@ -0,0 +1,59 @@ +package htmlconv + +import ( + "bytes" + "fmt" + "strings" + "testing" + + "tildegit.org/tjp/sliderule/gopher/gophermap" +) + +func TestConvert(t *testing.T) { + tests := []struct { + name string + input string + output string + }{ + { + name: "basic doc", + input: strings.ReplaceAll(` +iI am informational text localhost 70 +icontinued on this line localhost 70 +i localhost 70 +0this is my text file /file.txt localhost 70 +i localhost 70 +1here's a sub-menu /sub/ localhost 70 +. +`[1:], "\n", "\r\n"), + output: ` +<!DOCTYPE html> +<html><body class="gophermap"><pre class="gophermap">I am informational text +continued on this line + +</pre><p class="gophermap"><a class="gophermap" href="/file.txt">this is my text file</a></p><pre class="gophermap"> +</pre><p class="gophermap"><a class="gophermap" href="/sub/">here's a sub-menu</a></p></body></html> +`[1:], + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + doc, err := gophermap.Parse(bytes.NewBufferString(test.input)) + if err != nil { + t.Fatal(err) + } + + buf := &bytes.Buffer{} + if err := Convert(buf, doc, nil); err != nil { + t.Fatal(err) + } + + if buf.String() != test.output { + fmt.Println(test.output) + fmt.Println(buf.String()) + t.Fatal("html body mismatch") + } + }) + } +} |