mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-08-13 14:27:27 +00:00
parseRange split the spec on '-' and required BOTH bounds to parse as
integers. For a valid open-ended range like '5-' (RFC 3977 6.2.3 / RFC 2980
XOVER: article 5 through the last) strconv.ParseInt('') fails, so parseRange
returned (0, 0) and handleOver asked the backend for articles in [0, 0] —
zero rows. '-10' (first..10) was likewise broken.
Treat an empty bound as the extreme (low 0 / high MaxInt64) while still
returning an empty range for genuinely malformed specs. Add table-driven
tests for the open-ended and malformed forms.
37 lines
757 B
Go
37 lines
757 B
Go
package nntpd
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseRangeSingleArticle(t *testing.T) {
|
|
low, high := parseRange("5")
|
|
if low != 5 || high != 5 {
|
|
t.Fatalf(`parseRange("5") = %d, %d; want 5, 5`, low, high)
|
|
}
|
|
}
|
|
|
|
func TestParseRange(t *testing.T) {
|
|
// spec -> (low, high). Empty bounds mean the extreme; malformed -> (0, 0).
|
|
cases := []struct {
|
|
spec string
|
|
low int64
|
|
high int64
|
|
}{
|
|
{"5", 5, 5},
|
|
{"5-10", 5, 10},
|
|
{"5-", 5, math.MaxInt64},
|
|
{"-10", 0, 10},
|
|
{"", 0, math.MaxInt64},
|
|
{"abc", 0, 0},
|
|
{"5-abc", 0, 0},
|
|
{"abc-10", 0, 0},
|
|
}
|
|
for _, c := range cases {
|
|
low, high := parseRange(c.spec)
|
|
if low != c.low || high != c.high {
|
|
t.Errorf("parseRange(%q) = %d, %d; want %d, %d", c.spec, low, high, c.low, c.high)
|
|
}
|
|
}
|
|
}
|