github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/pkg/net/http/lex_test.go (about) 1 // Copyright 2009 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 package http 6 7 import ( 8 "testing" 9 ) 10 11 func isChar(c rune) bool { return c <= 127 } 12 13 func isCtl(c rune) bool { return c <= 31 || c == 127 } 14 15 func isSeparator(c rune) bool { 16 switch c { 17 case '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', '\t': 18 return true 19 } 20 return false 21 } 22 23 func TestIsToken(t *testing.T) { 24 for i := 0; i <= 130; i++ { 25 r := rune(i) 26 expected := isChar(r) && !isCtl(r) && !isSeparator(r) 27 if isToken(r) != expected { 28 t.Errorf("isToken(0x%x) = %v", r, !expected) 29 } 30 } 31 }