mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-23 04:12:00 +01:00
dac69ffbd0
Update drone Signed-off-by: jolheiser <john.olheiser@gmail.com> Sort test output for predictability Signed-off-by: jolheiser <john.olheiser@gmail.com> Update modules Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/jolheiser/sip/pulls/20
52 lines
1.2 KiB
Go
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, ",")
|
|
}
|