Home | History | Annotate | Download | only in http
      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 }
     42 
     43 func TestCleanHost(t *testing.T) {
     44 	tests := []struct {
     45 		in, want string
     46 	}{
     47 		{"www.google.com", "www.google.com"},
     48 		{"www.google.com foo", "www.google.com"},
     49 		{"www.google.com/foo", "www.google.com"},
     50 		{" first character is a space", ""},
     51 	}
     52 	for _, tt := range tests {
     53 		got := cleanHost(tt.in)
     54 		if tt.want != got {
     55 			t.Errorf("cleanHost(%q) = %q, want %q", tt.in, got, tt.want)
     56 		}
     57 	}
     58 }
     59