From 66a1b1f39a1e1d5499b548b36d18c8daa872d7da Mon Sep 17 00:00:00 2001 From: tjpcc Date: Sat, 28 Jan 2023 14:52:35 -0700 Subject: 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. --- gopher/gophermap/parse_test.go | 96 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 gopher/gophermap/parse_test.go (limited to 'gopher/gophermap/parse_test.go') 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) + } + } + }) + } +} -- cgit v1.2.3