(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…