mirror of
https://github.com/mickael-menu/zk
synced 2024-11-17 09:25:44 +00:00
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
|
package note
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/mickael-menu/zk/util/test/assert"
|
||
|
)
|
||
|
|
||
|
func TestSorterFromString(t *testing.T) {
|
||
|
test := func(str string, expectedField SortField, expectedAscending bool) {
|
||
|
actual, err := SorterFromString(str)
|
||
|
assert.Nil(t, err)
|
||
|
assert.Equal(t, actual, Sorter{Field: expectedField, Ascending: expectedAscending})
|
||
|
}
|
||
|
|
||
|
test("c", SortCreated, false)
|
||
|
test("c+", SortCreated, true)
|
||
|
test("created", SortCreated, false)
|
||
|
test("created-", SortCreated, false)
|
||
|
test("created+", SortCreated, true)
|
||
|
|
||
|
test("m", SortModified, false)
|
||
|
test("modified", SortModified, false)
|
||
|
test("modified+", SortModified, true)
|
||
|
|
||
|
test("p", SortPath, true)
|
||
|
test("path", SortPath, true)
|
||
|
test("path-", SortPath, false)
|
||
|
|
||
|
test("t", SortTitle, true)
|
||
|
test("title", SortTitle, true)
|
||
|
test("title-", SortTitle, false)
|
||
|
|
||
|
test("r", SortRandom, true)
|
||
|
test("random", SortRandom, true)
|
||
|
test("random-", SortRandom, false)
|
||
|
|
||
|
test("wc", SortWordCount, true)
|
||
|
test("word-count", SortWordCount, true)
|
||
|
test("word-count-", SortWordCount, false)
|
||
|
|
||
|
_, err := SorterFromString("foobar")
|
||
|
assert.Err(t, err, "foobar: unknown sorting term")
|
||
|
}
|
||
|
|
||
|
func TestSortersFromStrings(t *testing.T) {
|
||
|
test := func(strs []string, expected []Sorter) {
|
||
|
actual, err := SortersFromStrings(strs)
|
||
|
assert.Nil(t, err)
|
||
|
assert.Equal(t, actual, expected)
|
||
|
}
|
||
|
|
||
|
test([]string{}, []Sorter{})
|
||
|
|
||
|
test([]string{"created"}, []Sorter{
|
||
|
{Field: SortCreated, Ascending: false},
|
||
|
})
|
||
|
|
||
|
test([]string{"c+", "title"}, []Sorter{
|
||
|
{Field: SortCreated, Ascending: true},
|
||
|
{Field: SortTitle, Ascending: true},
|
||
|
})
|
||
|
|
||
|
_, err := SortersFromStrings([]string{"c", "foobar"})
|
||
|
assert.Err(t, err, "foobar: unknown sorting term")
|
||
|
}
|