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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 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
var ParseRangeTests = []struct {
12
        s      string
13
        length int64
14
        r      []httpRange
15
}{
16
        {"", 0, nil},
17
        {"foo", 0, nil},
18
        {"bytes=", 0, nil},
19
        {"bytes=5-4", 10, nil},
20
        {"bytes=0-2,5-4", 10, nil},
21
        {"bytes=0-9", 10, []httpRange{{0, 10}}},
22
        {"bytes=0-", 10, []httpRange{{0, 10}}},
23
        {"bytes=5-", 10, []httpRange{{5, 5}}},
24
        {"bytes=0-20", 10, []httpRange{{0, 10}}},
25
        {"bytes=15-,0-5", 10, nil},
26
        {"bytes=-5", 10, []httpRange{{5, 5}}},
27
        {"bytes=-15", 10, []httpRange{{0, 10}}},
28
        {"bytes=0-499", 10000, []httpRange{{0, 500}}},
29
        {"bytes=500-999", 10000, []httpRange{{500, 500}}},
30
        {"bytes=-500", 10000, []httpRange{{9500, 500}}},
31
        {"bytes=9500-", 10000, []httpRange{{9500, 500}}},
32
        {"bytes=0-0,-1", 10000, []httpRange{{0, 1}, {9999, 1}}},
33
        {"bytes=500-600,601-999", 10000, []httpRange{{500, 101}, {601, 399}}},
34
        {"bytes=500-700,601-999", 10000, []httpRange{{500, 201}, {601, 399}}},
35
}
36
 
37
func TestParseRange(t *testing.T) {
38
        for _, test := range ParseRangeTests {
39
                r := test.r
40
                ranges, err := parseRange(test.s, test.length)
41
                if err != nil && r != nil {
42
                        t.Errorf("parseRange(%q) returned error %q", test.s, err)
43
                }
44
                if len(ranges) != len(r) {
45
                        t.Errorf("len(parseRange(%q)) = %d, want %d", test.s, len(ranges), len(r))
46
                        continue
47
                }
48
                for i := range r {
49
                        if ranges[i].start != r[i].start {
50
                                t.Errorf("parseRange(%q)[%d].start = %d, want %d", test.s, i, ranges[i].start, r[i].start)
51
                        }
52
                        if ranges[i].length != r[i].length {
53
                                t.Errorf("parseRange(%q)[%d].length = %d, want %d", test.s, i, ranges[i].length, r[i].length)
54
                        }
55
                }
56
        }
57
}

powered by: WebSVN 2.1.0

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