package web import "testing" func TestParseRange(t *testing.T) { tests := []struct { header string start, length int64 partial bool }{ {"", 0, 0, false}, {"bytes=0-99", 0, 100, true}, {"bytes=100-", 100, 900, true}, {"bytes=900-5000", 900, 100, true}, {"bytes=-500", 500, 500, true}, {"bytes=-5000", 0, 1000, true}, {"bytes=-0", 0, 0, false}, {"bytes=-", 0, 0, false}, {"bytes=--5", 0, 0, false}, {"bytes=1000-", 0, 0, false}, {"bytes=5-2", 0, 0, false}, } for _, tt := range tests { start, length, partial := parseRange(tt.header, 1000) if start != tt.start || length != tt.length || partial != tt.partial { t.Errorf("%q: got %d,%d,%v want %d,%d,%v", tt.header, start, length, partial, tt.start, tt.length, tt.partial) } } }