repos_files_test.go
⎇
Raw
1package web
2
3import "testing"
4
5func TestParseRange(t *testing.T) {
6 tests := []struct {
7 header string
8 start, length int64
9 partial bool
10 }{
11 {"", 0, 0, false},
12 {"bytes=0-99", 0, 100, true},
13 {"bytes=100-", 100, 900, true},
14 {"bytes=900-5000", 900, 100, true},
15 {"bytes=-500", 500, 500, true},
16 {"bytes=-5000", 0, 1000, true},
17 {"bytes=-0", 0, 0, false},
18 {"bytes=-", 0, 0, false},
19 {"bytes=--5", 0, 0, false},
20 {"bytes=1000-", 0, 0, false},
21 {"bytes=5-2", 0, 0, false},
22 }
23 for _, tt := range tests {
24 start, length, partial := parseRange(tt.header, 1000)
25 if start != tt.start || length != tt.length || partial != tt.partial {
26 t.Errorf("%q: got %d,%d,%v want %d,%d,%v", tt.header,
27 start, length, partial, tt.start, tt.length, tt.partial)
28 }
29 }
30}
31