Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / http / lex_test.go
blob5386f7534db51f92cb62a8ae1b549e7f7124e348
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.
5 package http
7 import (
8 "testing"
11 type lexTest struct {
12 Raw string
13 Parsed int // # of parsed characters
14 Result []string
17 var lexTests = []lexTest{
19 Raw: `"abc"def,:ghi`,
20 Parsed: 13,
21 Result: []string{"abcdef", "ghi"},
23 // My understanding of the RFC is that escape sequences outside of
24 // quotes are not interpreted?
26 Raw: `"\t"\t"\t"`,
27 Parsed: 10,
28 Result: []string{"\t", "t\t"},
31 Raw: `"\yab"\r\n`,
32 Parsed: 10,
33 Result: []string{"?ab", "r", "n"},
36 Raw: "ab\f",
37 Parsed: 3,
38 Result: []string{"ab?"},
41 Raw: "\"ab \" c,de f, gh, ij\n\t\r",
42 Parsed: 23,
43 Result: []string{"ab ", "c", "de", "f", "gh", "ij"},
47 func min(x, y int) int {
48 if x <= y {
49 return x
51 return y
54 func TestSplitFieldValue(t *testing.T) {
55 for k, l := range lexTests {
56 parsed, result := httpSplitFieldValue(l.Raw)
57 if parsed != l.Parsed {
58 t.Errorf("#%d: Parsed %d, expected %d", k, parsed, l.Parsed)
60 if len(result) != len(l.Result) {
61 t.Errorf("#%d: Result len %d, expected %d", k, len(result), len(l.Result))
63 for i := 0; i < min(len(result), len(l.Result)); i++ {
64 if result[i] != l.Result[i] {
65 t.Errorf("#%d: %d-th entry mismatch. Have {%s}, expect {%s}",
66 k, i, result[i], l.Result[i])