Monorepo for Tangled
0
fork

Configure Feed

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

at fix/knot-version-string 35 lines 918 B view raw
1package state 2 3import "testing" 4 5func 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}