package gopher_test

import (
	"bytes"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"tildegit.org/tjp/gus/gopher"
)

func TestParseRequest(t *testing.T) {
	tests := []struct {
		requestLine string
		path        string
		query       string
	}{
		{
			requestLine: "\r\n",
			path:        "/",
		},
		{
			requestLine: "foo/bar\r\n",
			path:        "/foo/bar",
		},
		{
			requestLine: "search\tthis AND that\r\n",
			path:        "/search",
			query:       "this+AND+that",
		},
	}

	for _, test := range tests {
		t.Run(test.requestLine, func(t *testing.T) {
			request, err := gopher.ParseRequest(bytes.NewBufferString(test.requestLine))
			require.Nil(t, err)

			assert.Equal(t, test.path, request.Path)
			assert.Equal(t, test.query, request.RawQuery)
		})
	}
}