File: bytes_content_range_test.go

package info (click to toggle)
golang-github-anacrolix-missinggo 2.1.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 872 kB
  • sloc: makefile: 4
file content (28 lines) | stat: -rw-r--r-- 650 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package httptoo

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestParseHTTPContentRange(t *testing.T) {
	for _, _case := range []struct {
		h  string
		cr *BytesContentRange
	}{
		{"", nil},
		{"1-2/*", nil},
		{"bytes=1-2/3", &BytesContentRange{1, 2, 3}},
		{"bytes=12-34/*", &BytesContentRange{12, 34, -1}},
		{" bytes=12-34/*", &BytesContentRange{12, 34, -1}},
		{"  bytes 12-34/56", &BytesContentRange{12, 34, 56}},
		{"  bytes=*/56", &BytesContentRange{-1, -1, 56}},
	} {
		ret, ok := ParseBytesContentRange(_case.h)
		assert.Equal(t, _case.cr != nil, ok)
		if _case.cr != nil {
			assert.Equal(t, *_case.cr, ret)
		}
	}
}