1 package httpaccept 2 3 import ( 4 "net/http" 5 "reflect" 6 "testing" 7 ) 8 9 type testMimes []string 10 11 func (t *testMimes) Handle(mime Mime) bool { 12 *t = append(*t, string(mime)) 13 14 return false 15 } 16 17 func TestOrder(t *testing.T) { 18 for n, test := range []struct { 19 AcceptEncoding string 20 Encodings testMimes 21 }{ 22 {"", testMimes{""}}, 23 {"a/b", testMimes{"a/b"}}, 24 {"a/b, c/d, e/f", testMimes{"a/b", "c/d", "e/f"}}, 25 {"a/b;q=0, c/d;q=0.5, e/f;q=1", testMimes{"e/f", "c/d"}}, 26 {"*/*, c/d;q=0, e/f;q=0", testMimes{"*/*;c/d;e/f"}}, 27 {"*/*;q=0.5, c/d;q=0, e/f;q=0, e/*, */d;q=0.001", testMimes{"e/*;e/f", "*/*;c/d;e/f", "*/d;c/d"}}, 28 } { 29 te := make(testMimes, 0, len(test.Encodings)) 30 31 HandleAccept(&http.Request{ 32 Header: http.Header{ 33 accept: []string{test.AcceptEncoding}, 34 }, 35 }, &te) 36 37 if !reflect.DeepEqual(te, test.Encodings) { 38 t.Errorf("test %d: expecting %v, got %v", n+1, test.Encodings, te) 39 } 40 } 41 } 42