github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/src/net/http/http_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Tests of internal functions with no better homes. 6 7 package http 8 9 import ( 10 "reflect" 11 "testing" 12 ) 13 14 func TestForeachHeaderElement(t *testing.T) { 15 tests := []struct { 16 in string 17 want []string 18 }{ 19 {"Foo", []string{"Foo"}}, 20 {" Foo", []string{"Foo"}}, 21 {"Foo ", []string{"Foo"}}, 22 {" Foo ", []string{"Foo"}}, 23 24 {"foo", []string{"foo"}}, 25 {"anY-cAsE", []string{"anY-cAsE"}}, 26 27 {"", nil}, 28 {",,,, , ,, ,,, ,", nil}, 29 30 {" Foo,Bar, Baz,lower,,Quux ", []string{"Foo", "Bar", "Baz", "lower", "Quux"}}, 31 } 32 for _, tt := range tests { 33 var got []string 34 foreachHeaderElement(tt.in, func(v string) { 35 got = append(got, v) 36 }) 37 if !reflect.DeepEqual(got, tt.want) { 38 t.Errorf("foreachHeaderElement(%q) = %q; want %q", tt.in, got, tt.want) 39 } 40 } 41 }