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) } } }) } }