Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/state: add test for parseSortParam

Signed-off-by: Matías Insaurralde <matias@insaurral.de>

authored by

Matías Insaurralde and committed by tangled.org 0f576540 2e0c84ec

+35
+35
appview/state/search_test.go
··· 1 + package state 2 + 3 + import "testing" 4 + 5 + func TestParseSortParam(t *testing.T) { 6 + tests := []struct { 7 + input string 8 + wantField string 9 + wantDesc bool 10 + }{ 11 + {"", "relevance", true}, 12 + {"stars-desc", "stars", true}, 13 + {"stars-asc", "stars", false}, 14 + {"created-desc", "created", true}, 15 + {"created-asc", "created", false}, 16 + {"relevance-asc", "relevance", false}, 17 + {"issues-desc", "issues", true}, 18 + {"pulls-asc", "pulls", false}, 19 + // invalid field → default 20 + {"forks-desc", "relevance", true}, 21 + {"unknown-asc", "relevance", true}, 22 + // malformed → default 23 + {"nodash", "relevance", true}, 24 + {"too-many-parts-here", "relevance", true}, 25 + {"-", "relevance", true}, 26 + } 27 + 28 + for _, tt := range tests { 29 + field, desc := parseSortParam(tt.input) 30 + if field != tt.wantField || desc != tt.wantDesc { 31 + t.Errorf("parseSortParam(%q) = (%q, %v), want (%q, %v)", 32 + tt.input, field, desc, tt.wantField, tt.wantDesc) 33 + } 34 + } 35 + }