1
0
mirror of https://gitea.com/jolheiser/sip synced 2024-11-22 11:41:59 +01:00
sip/qualify/qualify_test.go
John Olheiser 894a641ef8 Refactor (#29)
Clean up docs

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Add generated docs

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Update go.sum

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Fix remote parsing

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Refactor and clean up

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/sip/pulls/29
2020-09-17 16:25:09 +00:00

52 lines
1.2 KiB
Go

package qualify
import (
"fmt"
"os"
"sort"
"strconv"
"strings"
"testing"
)
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
func TestParse(t *testing.T) {
tt := []struct {
Query string
Result string
Qualifiers []string
}{
{"test", "query->test", nil},
{`"test"`, "query->test", nil},
{"author:jolheiser", "author->jolheiser", nil},
{`"this is a test" author:"jolheiser"`, "author->jolheiser,query->this is a test", nil},
{`"this is" "a test" query`, "query->this is|a test|query", nil},
{`label:"a bug" label:"a" label:"bug"`, "label->a bug|a|bug", nil},
{`author:"jolheiser""`, `author->jolheiser"`, nil},
{`author:""jolheiser""`, `author->"jolheiser"`, nil},
{"test:testing", "query->test:testing", []string{"label"}},
}
for idx, tc := range tt {
t.Run(strconv.Itoa(idx+1), func(t *testing.T) {
parsed := result(Parse(tc.Query, tc.Qualifiers...))
if parsed != tc.Result {
t.Logf("\nwant: %s\n got: %s", tc.Result, parsed)
t.Fail()
}
})
}
}
func result(parsed Query) string {
res := make([]string, 0, len(parsed))
for key, values := range parsed {
res = append(res, fmt.Sprintf("%s->%s", key, strings.Join(values, "|")))
}
sort.Strings(res)
return strings.Join(res, ",")
}