2
0

Make range helpers private

This commit is contained in:
Jack Christensen
2022-04-23 11:10:04 -05:00
parent 1f4b34f932
commit 126b582f19
3 changed files with 33 additions and 33 deletions
+6 -6
View File
@@ -19,15 +19,15 @@ func (bt BoundType) String() string {
return string(bt) return string(bt)
} }
type UntypedTextRange struct { type untypedTextRange struct {
Lower string Lower string
Upper string Upper string
LowerType BoundType LowerType BoundType
UpperType BoundType UpperType BoundType
} }
func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { func parseUntypedTextRange(src string) (*untypedTextRange, error) {
utr := &UntypedTextRange{} utr := &untypedTextRange{}
if src == "empty" { if src == "empty" {
utr.LowerType = Empty utr.LowerType = Empty
utr.UpperType = Empty utr.UpperType = Empty
@@ -173,7 +173,7 @@ func rangeParseQuotedValue(buf *bytes.Buffer) (string, error) {
} }
} }
type UntypedBinaryRange struct { type untypedBinaryRange struct {
Lower []byte Lower []byte
Upper []byte Upper []byte
LowerType BoundType LowerType BoundType
@@ -197,8 +197,8 @@ const upperInclusiveMask = 4
const lowerUnboundedMask = 8 const lowerUnboundedMask = 8
const upperUnboundedMask = 16 const upperUnboundedMask = 16
func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { func parseUntypedBinaryRange(src []byte) (*untypedBinaryRange, error) {
ubr := &UntypedBinaryRange{} ubr := &untypedBinaryRange{}
if len(src) == 0 { if len(src) == 0 {
return nil, fmt.Errorf("range too short: %v", len(src)) return nil, fmt.Errorf("range too short: %v", len(src))
+2 -2
View File
@@ -263,7 +263,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target any) erro
return rangeScanner.ScanNull() return rangeScanner.ScanNull()
} }
ubr, err := ParseUntypedBinaryRange(src) ubr, err := parseUntypedBinaryRange(src)
if err != nil { if err != nil {
return err return err
} }
@@ -313,7 +313,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target any) error
return rangeScanner.ScanNull() return rangeScanner.ScanNull()
} }
utr, err := ParseUntypedTextRange(string(src)) utr, err := parseUntypedTextRange(string(src))
if err != nil { if err != nil {
return err return err
} }
+25 -25
View File
@@ -8,68 +8,68 @@ import (
func TestParseUntypedTextRange(t *testing.T) { func TestParseUntypedTextRange(t *testing.T) {
tests := []struct { tests := []struct {
src string src string
result UntypedTextRange result untypedTextRange
err error err error
}{ }{
{ {
src: `[1,2)`, src: `[1,2)`,
result: UntypedTextRange{Lower: "1", Upper: "2", LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: "1", Upper: "2", LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `[1,2]`, src: `[1,2]`,
result: UntypedTextRange{Lower: "1", Upper: "2", LowerType: Inclusive, UpperType: Inclusive}, result: untypedTextRange{Lower: "1", Upper: "2", LowerType: Inclusive, UpperType: Inclusive},
err: nil, err: nil,
}, },
{ {
src: `(1,3)`, src: `(1,3)`,
result: UntypedTextRange{Lower: "1", Upper: "3", LowerType: Exclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: "1", Upper: "3", LowerType: Exclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: ` [1,2) `, src: ` [1,2) `,
result: UntypedTextRange{Lower: "1", Upper: "2", LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: "1", Upper: "2", LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `[ foo , bar )`, src: `[ foo , bar )`,
result: UntypedTextRange{Lower: " foo ", Upper: " bar ", LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: " foo ", Upper: " bar ", LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `["foo","bar")`, src: `["foo","bar")`,
result: UntypedTextRange{Lower: "foo", Upper: "bar", LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: "foo", Upper: "bar", LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `["f""oo","b""ar")`, src: `["f""oo","b""ar")`,
result: UntypedTextRange{Lower: `f"oo`, Upper: `b"ar`, LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: `f"oo`, Upper: `b"ar`, LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `["f""oo","b""ar")`, src: `["f""oo","b""ar")`,
result: UntypedTextRange{Lower: `f"oo`, Upper: `b"ar`, LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: `f"oo`, Upper: `b"ar`, LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `["","bar")`, src: `["","bar")`,
result: UntypedTextRange{Lower: ``, Upper: `bar`, LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: ``, Upper: `bar`, LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `[f\"oo\,,b\\ar\))`, src: `[f\"oo\,,b\\ar\))`,
result: UntypedTextRange{Lower: `f"oo,`, Upper: `b\ar)`, LowerType: Inclusive, UpperType: Exclusive}, result: untypedTextRange{Lower: `f"oo,`, Upper: `b\ar)`, LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: `empty`, src: `empty`,
result: UntypedTextRange{Lower: "", Upper: "", LowerType: Empty, UpperType: Empty}, result: untypedTextRange{Lower: "", Upper: "", LowerType: Empty, UpperType: Empty},
err: nil, err: nil,
}, },
} }
for i, tt := range tests { for i, tt := range tests {
r, err := ParseUntypedTextRange(tt.src) r, err := parseUntypedTextRange(tt.src)
if err != tt.err { if err != tt.err {
t.Errorf("%d. `%v`: expected err %v, got %v", i, tt.src, tt.err, err) t.Errorf("%d. `%v`: expected err %v, got %v", i, tt.src, tt.err, err)
continue continue
@@ -96,63 +96,63 @@ func TestParseUntypedTextRange(t *testing.T) {
func TestParseUntypedBinaryRange(t *testing.T) { func TestParseUntypedBinaryRange(t *testing.T) {
tests := []struct { tests := []struct {
src []byte src []byte
result UntypedBinaryRange result untypedBinaryRange
err error err error
}{ }{
{ {
src: []byte{0, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5}, src: []byte{0, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5},
result: UntypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Exclusive, UpperType: Exclusive}, result: untypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Exclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: []byte{1}, src: []byte{1},
result: UntypedBinaryRange{Lower: nil, Upper: nil, LowerType: Empty, UpperType: Empty}, result: untypedBinaryRange{Lower: nil, Upper: nil, LowerType: Empty, UpperType: Empty},
err: nil, err: nil,
}, },
{ {
src: []byte{2, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5}, src: []byte{2, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5},
result: UntypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Inclusive, UpperType: Exclusive}, result: untypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Inclusive, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: []byte{4, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5}, src: []byte{4, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5},
result: UntypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Exclusive, UpperType: Inclusive}, result: untypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Exclusive, UpperType: Inclusive},
err: nil, err: nil,
}, },
{ {
src: []byte{6, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5}, src: []byte{6, 0, 0, 0, 2, 0, 4, 0, 0, 0, 2, 0, 5},
result: UntypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Inclusive, UpperType: Inclusive}, result: untypedBinaryRange{Lower: []byte{0, 4}, Upper: []byte{0, 5}, LowerType: Inclusive, UpperType: Inclusive},
err: nil, err: nil,
}, },
{ {
src: []byte{8, 0, 0, 0, 2, 0, 5}, src: []byte{8, 0, 0, 0, 2, 0, 5},
result: UntypedBinaryRange{Lower: nil, Upper: []byte{0, 5}, LowerType: Unbounded, UpperType: Exclusive}, result: untypedBinaryRange{Lower: nil, Upper: []byte{0, 5}, LowerType: Unbounded, UpperType: Exclusive},
err: nil, err: nil,
}, },
{ {
src: []byte{12, 0, 0, 0, 2, 0, 5}, src: []byte{12, 0, 0, 0, 2, 0, 5},
result: UntypedBinaryRange{Lower: nil, Upper: []byte{0, 5}, LowerType: Unbounded, UpperType: Inclusive}, result: untypedBinaryRange{Lower: nil, Upper: []byte{0, 5}, LowerType: Unbounded, UpperType: Inclusive},
err: nil, err: nil,
}, },
{ {
src: []byte{16, 0, 0, 0, 2, 0, 4}, src: []byte{16, 0, 0, 0, 2, 0, 4},
result: UntypedBinaryRange{Lower: []byte{0, 4}, Upper: nil, LowerType: Exclusive, UpperType: Unbounded}, result: untypedBinaryRange{Lower: []byte{0, 4}, Upper: nil, LowerType: Exclusive, UpperType: Unbounded},
err: nil, err: nil,
}, },
{ {
src: []byte{18, 0, 0, 0, 2, 0, 4}, src: []byte{18, 0, 0, 0, 2, 0, 4},
result: UntypedBinaryRange{Lower: []byte{0, 4}, Upper: nil, LowerType: Inclusive, UpperType: Unbounded}, result: untypedBinaryRange{Lower: []byte{0, 4}, Upper: nil, LowerType: Inclusive, UpperType: Unbounded},
err: nil, err: nil,
}, },
{ {
src: []byte{24}, src: []byte{24},
result: UntypedBinaryRange{Lower: nil, Upper: nil, LowerType: Unbounded, UpperType: Unbounded}, result: untypedBinaryRange{Lower: nil, Upper: nil, LowerType: Unbounded, UpperType: Unbounded},
err: nil, err: nil,
}, },
} }
for i, tt := range tests { for i, tt := range tests {
r, err := ParseUntypedBinaryRange(tt.src) r, err := parseUntypedBinaryRange(tt.src)
if err != tt.err { if err != tt.err {
t.Errorf("%d. `%v`: expected err %v, got %v", i, tt.src, tt.err, err) t.Errorf("%d. `%v`: expected err %v, got %v", i, tt.src, tt.err, err)
continue continue