MCPcopy
hub / github.com/pocketbase/pocketbase / TestParseSortFromString

Function TestParseSortFromString

tools/search/sort_test.go:53–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestParseSortFromString(t *testing.T) {
54 scenarios := []struct {
55 value string
56 expected string
57 }{
58 {"", `[{"name":"","direction":"ASC"}]`},
59 {"test", `[{"name":"test","direction":"ASC"}]`},
60 {"+test", `[{"name":"test","direction":"ASC"}]`},
61 {"-test", `[{"name":"test","direction":"DESC"}]`},
62 {"test1,-test2,+test3", `[{"name":"test1","direction":"ASC"},{"name":"test2","direction":"DESC"},{"name":"test3","direction":"ASC"}]`},
63 {"@random,-test", `[{"name":"@random","direction":"ASC"},{"name":"test","direction":"DESC"}]`},
64 {"-@rowid,-test", `[{"name":"@rowid","direction":"DESC"},{"name":"test","direction":"DESC"}]`},
65 }
66
67 for _, s := range scenarios {
68 t.Run(s.value, func(t *testing.T) {
69 result := search.ParseSortFromString(s.value)
70 encoded, _ := json.Marshal(result)
71 encodedStr := string(encoded)
72
73 if encodedStr != s.expected {
74 t.Fatalf("Expected expression %s, got %s", s.expected, encodedStr)
75 }
76 })
77 }
78}

Callers

nothing calls this directly

Calls 2

ParseSortFromStringFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…