summaryrefslogtreecommitdiff
path: root/gopher/gophermap/parse_test.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-01-28 14:52:35 -0700
committertjpcc <tjp@ctrl-c.club>2023-01-28 15:01:41 -0700
commit66a1b1f39a1e1d5499b548b36d18c8daa872d7da (patch)
tree96471dbd5486ede1a908790ac23e0c55b226dfad /gopher/gophermap/parse_test.go
parenta27b879accb191b6a6c6e76a6251ed751967f73a (diff)
gopher support.
Some of the contrib packages were originally built gemini-specific and had to be refactored into generic core functionality and thin protocol-specific wrappers for each of gemini and gopher.
Diffstat (limited to 'gopher/gophermap/parse_test.go')
-rw-r--r--gopher/gophermap/parse_test.go96
1 files changed, 96 insertions, 0 deletions
diff --git a/gopher/gophermap/parse_test.go b/gopher/gophermap/parse_test.go
new file mode 100644
index 0000000..0e5c09e
--- /dev/null
+++ b/gopher/gophermap/parse_test.go
@@ -0,0 +1,96 @@
+package gophermap_test
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
+ "tildegit.org/tjp/gus/gopher"
+ "tildegit.org/tjp/gus/gopher/gophermap"
+)
+
+func TestParse(t *testing.T) {
+ tests := []struct {
+ doc string
+ lines gopher.MapDocument
+ }{
+ {
+ doc: `
+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:],
+ lines: gopher.MapDocument{
+ gopher.MapItem{
+ Type: gopher.InfoMessageType,
+ Display: "I am informational text",
+ Selector: "",
+ Hostname: "localhost",
+ Port: "70",
+ },
+ gopher.MapItem{
+ Type: gopher.InfoMessageType,
+ Display: "continued on this line",
+ Selector: "",
+ Hostname: "localhost",
+ Port: "70",
+ },
+ gopher.MapItem{
+ Type: gopher.InfoMessageType,
+ Display: "",
+ Selector: "",
+ Hostname: "localhost",
+ Port: "70",
+ },
+ gopher.MapItem{
+ Type: gopher.TextFileType,
+ Display: "this is my text file",
+ Selector: "/file.txt",
+ Hostname: "localhost",
+ Port: "70",
+ },
+ gopher.MapItem{
+ Type: gopher.InfoMessageType,
+ Display: "",
+ Selector: "",
+ Hostname: "localhost",
+ Port: "70",
+ },
+ gopher.MapItem{
+ Type: gopher.MenuType,
+ Display: "here's a sub-menu",
+ Selector: "/sub/",
+ Hostname: "localhost",
+ Port: "70",
+ },
+ },
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.lines[0].Display, func(t *testing.T) {
+ text := strings.ReplaceAll(test.doc, "\n", "\r\n")
+ doc, err := gophermap.Parse(bytes.NewBufferString(text))
+ require.Nil(t, err)
+
+ if assert.Equal(t, len(test.lines), len(doc)) {
+ for i, line := range doc {
+ expect := test.lines[i]
+
+ assert.Equal(t, expect.Type, line.Type)
+ assert.Equal(t, expect.Display, line.Display)
+ assert.Equal(t, expect.Selector, line.Selector)
+ assert.Equal(t, expect.Hostname, line.Hostname)
+ assert.Equal(t, expect.Port, line.Port)
+ }
+ }
+ })
+ }
+}