OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [http/] [lex_test.go] - Blame information for rev 775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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
type lexTest struct {
12
        Raw    string
13
        Parsed int // # of parsed characters
14
        Result []string
15
}
16
 
17
var lexTests = []lexTest{
18
        {
19
                Raw:    `"abc"def,:ghi`,
20
                Parsed: 13,
21
                Result: []string{"abcdef", "ghi"},
22
        },
23
        // My understanding of the RFC is that escape sequences outside of
24
        // quotes are not interpreted?
25
        {
26
                Raw:    `"\t"\t"\t"`,
27
                Parsed: 10,
28
                Result: []string{"\t", "t\t"},
29
        },
30
        {
31
                Raw:    `"\yab"\r\n`,
32
                Parsed: 10,
33
                Result: []string{"?ab", "r", "n"},
34
        },
35
        {
36
                Raw:    "ab\f",
37
                Parsed: 3,
38
                Result: []string{"ab?"},
39
        },
40
        {
41
                Raw:    "\"ab \" c,de f, gh, ij\n\t\r",
42
                Parsed: 23,
43
                Result: []string{"ab ", "c", "de", "f", "gh", "ij"},
44
        },
45
}
46
 
47
func min(x, y int) int {
48
        if x <= y {
49
                return x
50
        }
51
        return y
52
}
53
 
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)
59
                }
60
                if len(result) != len(l.Result) {
61
                        t.Errorf("#%d: Result len  %d, expected %d", k, len(result), len(l.Result))
62
                }
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])
67
                        }
68
                }
69
        }
70
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.