Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ formatters:
- gofmt
- gofumpt
- goimports
- golines
- swaggo
3 changes: 3 additions & 0 deletions and.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func And(es ...Endless) (CeilingFloorConstrainter, error) { //nolint:cyclop,iret
if len(es) == 0 {
return NewMatchAll(), nil
}

if len(es) == 1 {
return es[0], nil
}
Expand All @@ -35,9 +36,11 @@ func And(es ...Endless) (CeilingFloorConstrainter, error) { //nolint:cyclop,iret
// logic error! This should never happen
return nilC, errUnexpectedAndLogic
}

if ceilingOk && !floorOk {
return ceiling, nil
}

if !ceilingOk { // floorOk is always true here
return floor, nil
}
Expand Down
2 changes: 2 additions & 0 deletions and_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ func Test_minBoundedCeiling(t *testing.T) {
want Endless
wantOk bool
}

tests := []testCase{
{
name: "empty",
Expand Down Expand Up @@ -627,6 +628,7 @@ func Test_maxBoundedFloor(t *testing.T) {
want Endless
wantOk bool
}

tests := []testCase{
{
name: "empty",
Expand Down
3 changes: 3 additions & 0 deletions compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ func Compact(o Or) Constrainter { //nolint:cyclop,ireturn
if len(o) == 0 {
return Or{}
}

if len(o) == 1 {
return o[0]
}

if slices.ContainsFunc(o, matchAll) {
return NewMatchAll()
}
Expand Down Expand Up @@ -45,6 +47,7 @@ func Compact(o Or) Constrainter { //nolint:cyclop,ireturn
if floorOk {
r = append(r, floor)
}

if ceilingOk {
r = append(r, ceiling)
}
Expand Down
1 change: 1 addition & 0 deletions doc_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func Example_version() {

continue
}

fmt.Printf("%-21q => %v\n", s, v)
}

Expand Down
4 changes: 2 additions & 2 deletions op.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const (
greaterThan
lessThan
lessThanOrEqualTo

errUnexpectedOp stringError = "unexpected op"
)

const errUnexpectedOp stringError = "unexpected op"

type op int8

func (o op) String() string {
Expand Down
1 change: 1 addition & 0 deletions or.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (o Or) String() string {
if i > 0 {
s += " || "
}

s += o[i].String()
}

Expand Down
16 changes: 8 additions & 8 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,37 @@ func Parse(v string) (Version, error) { //nolint:cyclop,funlen
} else if dm := dateOnlyVersioningRegexp.FindStringSubmatch(v); dm != nil {
match = dm
}

if match == nil || len(match) != 7 {
return Version{}, &ParseError{original, errInvalidVersionString}
}

var err error

if cv.major, err = strconv.ParseUint(match[1], 10, 64); err != nil {
if cv.major, err = strconv.ParseUint(match[1], 10, 64); err != nil { //nolint:noinlineerr
return Version{}, &ParseError{original, err}
}
// CalVer (as MAJOR) must be in YYYYMMDDhhmm or YYYYMMDD formats
if s := strconv.FormatUint(cv.major, 10); len(s) > 12 || len(s) == 11 || len(s) == 9 ||
len(s) == 7 {
if s := strconv.FormatUint(cv.major, 10); len(s) > 12 || len(s) == 11 || len(s) == 9 || len(s) == 7 {
return Version{}, &ParseError{original, errInvalidVersionString}
}

if cv.minor, err = strconv.ParseUint(match[2], 10, 64); match[2] != "" && err != nil {
if cv.minor, err = strconv.ParseUint(match[2], 10, 64); match[2] != "" && err != nil { //nolint:noinlineerr
return Version{}, &ParseError{original, err}
}

if cv.patch, err = strconv.ParseUint(match[3], 10, 64); match[3] != "" && err != nil {
if cv.patch, err = strconv.ParseUint(match[3], 10, 64); match[3] != "" && err != nil { //nolint:noinlineerr
return Version{}, &ParseError{original, err}
}

if cv.major >= 1000_00 && match[4] != "" {
return Version{}, &ParseError{original, errDateVersionWithFourBits}
}
if cv.tweak, err = strconv.ParseUint(match[4], 10, 64); match[4] != "" && err != nil {

if cv.tweak, err = strconv.ParseUint(match[4], 10, 64); match[4] != "" && err != nil { //nolint:noinlineerr
return Version{}, &ParseError{original, err}
}

if cv.modifier, err = newModifier(match[5]); err != nil {
if cv.modifier, err = newModifier(match[5]); err != nil { //nolint:noinlineerr
return Version{}, &ParseError{original, err}
}

Expand Down
4 changes: 4 additions & 0 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ func TestParse(t *testing.T) {
if err != nil {
t.Fatalf("Parse() error = %v, wantErr %v", err, nil)
}

if gotString := got.String(); gotString != tt.want {
t.Errorf("Parse().String() got = %q, want %v", gotString, tt.want)
}

if gotOriginal := got.Original(); gotOriginal != tt.v {
t.Errorf("Parse().Original() got = %q, want %v", gotOriginal, tt.v)
}
Expand All @@ -118,6 +120,7 @@ func TestMustParse(t *testing.T) {
if gotString := got.String(); gotString != tt.want {
t.Errorf("MustParse().String() got = %q, want %v", gotString, tt.want)
}

if gotOriginal := got.Original(); gotOriginal != tt.v {
t.Errorf("MustParse().Original() got = %q, want %v", gotOriginal, tt.v)
}
Expand Down Expand Up @@ -353,6 +356,7 @@ func TestVersion_Compare(t *testing.T) {
if err != nil {
t.Fatalf("Parse(%q) error = %v, wantErr %v", tt.v, err, nil)
}

w, err := Parse(tt.w)
if err != nil {
t.Fatalf("Parse(%q) error = %v, wantErr %v", tt.w, err, nil)
Expand Down
Loading