Skip to content

Commit

Permalink
Rename Wildcard to MatchAll
Browse files Browse the repository at this point in the history
  • Loading branch information
tangrufus committed Dec 6, 2024
1 parent 95a6a73 commit 72fff8c
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 136 deletions.
6 changes: 3 additions & 3 deletions and.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func And(es ...Endless) (CeilingFloorConstrainter, error) { //nolint:cyclop,iret
}

es = slices.Clone(es)
es = slices.DeleteFunc(es, Endless.wildcard)
es = slices.DeleteFunc(es, Endless.matchAll)

if len(es) == 0 {
return NewWildcard(), nil
return NewMatchAll(), nil
}
if len(es) == 1 {
return es[0], nil
Expand Down Expand Up @@ -94,7 +94,7 @@ func maxBoundedFloor(es ...Endless) (Endless, bool) {
es = slices.Clone(es)

bfs := slices.DeleteFunc(es, func(c Endless) bool {
return c.floor().wildcard()
return c.floor().matchAll()
})

if len(bfs) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions and_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func ExampleAnd() {
// Output: >=2 <3
}

func ExampleAnd_wildcard() {
func ExampleAnd_matchAll() {
a, _ := comver.And(
comver.NewGreaterThanOrEqualTo(comver.MustParse("2")),
comver.NewLessThan(comver.MustParse("3")),
comver.NewWildcard(),
comver.NewMatchAll(),
)

fmt.Println(a)
Expand Down
114 changes: 57 additions & 57 deletions and_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ func TestAnd(t *testing.T) {
wantErr: nil,
},
{
name: "single_wildcard",
es: []Endless{NewWildcard()},
want: NewWildcard(),
name: "single_match_all",
es: []Endless{NewMatchAll()},
want: NewMatchAll(),
wantErr: nil,
},
{
name: "multiple_wildcards",
es: []Endless{NewWildcard(), NewWildcard()},
want: NewWildcard(),
name: "multiple_match_alls",
es: []Endless{NewMatchAll(), NewMatchAll()},
want: NewMatchAll(),
wantErr: nil,
},
{
Expand Down Expand Up @@ -114,17 +114,17 @@ func TestAnd(t *testing.T) {
wantErr: errImpossibleInterval,
},
{
name: "impossible_interval_wildcard",
name: "impossible_interval_match_all",
es: []Endless{
NewLessThan(MustParse("1")),
NewGreaterThan(MustParse("4")),
NewWildcard(),
NewMatchAll(),
},
want: nilC,
wantErr: errImpossibleInterval,
},
{
name: "multiple_wildcards_multiple_endlesses",
name: "multiple_match_alls_multiple_endlesses",
es: []Endless{
NewLessThan(MustParse("1")),
NewLessThanOrEqualTo(MustParse("1")),
Expand All @@ -134,8 +134,8 @@ func TestAnd(t *testing.T) {
NewGreaterThan(MustParse("3")),
NewGreaterThanOrEqualTo(MustParse("4")),
NewGreaterThan(MustParse("4")),
NewWildcard(),
NewWildcard(),
NewMatchAll(),
NewMatchAll(),
},
want: nilC,
wantErr: errImpossibleInterval,
Expand Down Expand Up @@ -178,11 +178,11 @@ func TestAnd(t *testing.T) {
wantErr: nil,
},
{
name: "exact_version_wildcard",
name: "exact_version_match_all",
es: []Endless{
NewLessThanOrEqualTo(MustParse("1")),
NewGreaterThanOrEqualTo(MustParse("1")),
NewWildcard(),
NewMatchAll(),
},
want: NewExactConstraint(MustParse("1")),
wantErr: nil,
Expand All @@ -198,8 +198,8 @@ func TestAnd(t *testing.T) {
NewGreaterThanOrEqualTo(MustParse("1")),
NewGreaterThan(MustParse("1")),
NewGreaterThan(MustParse("1")),
NewWildcard(),
NewWildcard(),
NewMatchAll(),
NewMatchAll(),
},
want: nilC,
wantErr: errImpossibleInterval,
Expand All @@ -213,8 +213,8 @@ func TestAnd(t *testing.T) {
NewGreaterThanOrEqualTo(MustParse("1")),
NewGreaterThan(MustParse("1")),
NewGreaterThan(MustParse("1")),
NewWildcard(),
NewWildcard(),
NewMatchAll(),
NewMatchAll(),
},
want: nilC,
wantErr: errImpossibleInterval,
Expand All @@ -226,8 +226,8 @@ func TestAnd(t *testing.T) {
NewLessThanOrEqualTo(MustParse("1")),
NewGreaterThanOrEqualTo(MustParse("1")),
NewGreaterThanOrEqualTo(MustParse("1")),
NewWildcard(),
NewWildcard(),
NewMatchAll(),
NewMatchAll(),
},
want: NewExactConstraint(MustParse("1")),
wantErr: nil,
Expand All @@ -239,8 +239,8 @@ func TestAnd(t *testing.T) {
NewLessThanOrEqualTo(MustParse("1")),
NewLessThan(MustParse("1")),
NewLessThan(MustParse("1")),
NewWildcard(),
NewWildcard(),
NewMatchAll(),
NewMatchAll(),
NewGreaterThan(MustParse("1")),
},
want: nilC,
Expand All @@ -253,8 +253,8 @@ func TestAnd(t *testing.T) {
NewGreaterThanOrEqualTo(MustParse("1")),
NewGreaterThan(MustParse("1")),
NewGreaterThan(MustParse("1")),
NewWildcard(),
NewWildcard(),
NewMatchAll(),
NewMatchAll(),
NewLessThan(MustParse("1")),
},
want: nilC,
Expand All @@ -267,8 +267,8 @@ func TestAnd(t *testing.T) {
NewLessThanOrEqualTo(MustParse("1")),
NewLessThan(MustParse("1")),
NewLessThan(MustParse("1")),
NewWildcard(),
NewWildcard(),
NewMatchAll(),
NewMatchAll(),
NewGreaterThanOrEqualTo(MustParse("1")),
NewGreaterThanOrEqualTo(MustParse("1")),
NewGreaterThan(MustParse("1")),
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestAnd(t *testing.T) {
wantErr: nil,
},
{
name: "compact_ceiling_floor_wildcard",
name: "compact_ceiling_floor_match_all",
es: []Endless{
NewLessThanOrEqualTo(MustParse("4")),
NewLessThan(MustParse("4")),
Expand All @@ -391,7 +391,7 @@ func TestAnd(t *testing.T) {
NewGreaterThanOrEqualTo(MustParse("2")),
NewGreaterThan(MustParse("1")),
NewGreaterThanOrEqualTo(MustParse("1")),
NewWildcard(),
NewMatchAll(),
},
want: interval{
upper: NewLessThan(MustParse("3")),
Expand Down Expand Up @@ -450,13 +450,13 @@ func Test_minBoundedCeiling(t *testing.T) {
{
name: "empty",
cs: []Endless{},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "nil",
cs: nil,
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
Expand All @@ -474,19 +474,19 @@ func Test_minBoundedCeiling(t *testing.T) {
{
name: "single_greaterThan",
cs: []Endless{NewGreaterThan(MustParse("3"))},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "single_greaterThanOrEqualTo",
cs: []Endless{NewGreaterThanOrEqualTo(MustParse("4"))},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "single_wildcard",
cs: []Endless{NewWildcard()},
want: NewWildcard(),
name: "single_match_all",
cs: []Endless{NewMatchAll()},
want: NewMatchAll(),
wantOk: false,
},
{
Expand All @@ -497,19 +497,19 @@ func Test_minBoundedCeiling(t *testing.T) {
NewGreaterThanOrEqualTo(MustParse("4")),
NewGreaterThan(MustParse("4")),
},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "multiple_no_ceiling_wildcard",
name: "multiple_no_ceiling_match_all",
cs: []Endless{
NewGreaterThanOrEqualTo(MustParse("3")),
NewGreaterThan(MustParse("3")),
NewGreaterThanOrEqualTo(MustParse("4")),
NewGreaterThan(MustParse("4")),
NewWildcard(),
NewMatchAll(),
},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
Expand Down Expand Up @@ -542,7 +542,7 @@ func Test_minBoundedCeiling(t *testing.T) {
wantOk: true,
},
{
name: "multiple_ceilings_wildcard",
name: "multiple_ceilings_match_all",
cs: []Endless{
NewLessThan(MustParse("1")),
NewLessThanOrEqualTo(MustParse("1")),
Expand All @@ -552,7 +552,7 @@ func Test_minBoundedCeiling(t *testing.T) {
NewGreaterThan(MustParse("3")),
NewGreaterThanOrEqualTo(MustParse("4")),
NewGreaterThan(MustParse("4")),
NewWildcard(),
NewMatchAll(),
},
want: NewLessThan(MustParse("1")),
wantOk: true,
Expand All @@ -570,14 +570,14 @@ func Test_minBoundedCeiling(t *testing.T) {
wantOk: true,
},
{
name: "single_ceiling_wildcard",
name: "single_ceiling_match_all",
cs: []Endless{
NewLessThanOrEqualTo(MustParse("2")),
NewGreaterThanOrEqualTo(MustParse("3")),
NewGreaterThan(MustParse("3")),
NewGreaterThanOrEqualTo(MustParse("4")),
NewGreaterThan(MustParse("4")),
NewWildcard(),
NewMatchAll(),
},
want: NewLessThanOrEqualTo(MustParse("2")),
wantOk: true,
Expand Down Expand Up @@ -627,25 +627,25 @@ func Test_maxBoundedFloor(t *testing.T) {
{
name: "empty",
fs: []Endless{},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "nil",
fs: nil,
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "single_lessThan",
fs: []Endless{NewLessThan(MustParse("1"))},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "single_lessThanOrEqualTo",
fs: []Endless{NewLessThanOrEqualTo(MustParse("2"))},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
Expand All @@ -661,9 +661,9 @@ func Test_maxBoundedFloor(t *testing.T) {
wantOk: true,
},
{
name: "single_wildcard",
fs: []Endless{NewWildcard()},
want: NewWildcard(),
name: "single_match_all",
fs: []Endless{NewMatchAll()},
want: NewMatchAll(),
wantOk: false,
},
{
Expand All @@ -674,19 +674,19 @@ func Test_maxBoundedFloor(t *testing.T) {
NewLessThan(MustParse("2")),
NewLessThanOrEqualTo(MustParse("2")),
},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
name: "multiple_no_floor_wildcard",
name: "multiple_no_floor_match_all",
fs: []Endless{
NewLessThan(MustParse("1")),
NewLessThanOrEqualTo(MustParse("1")),
NewLessThan(MustParse("2")),
NewLessThanOrEqualTo(MustParse("2")),
NewWildcard(),
NewMatchAll(),
},
want: NewWildcard(),
want: NewMatchAll(),
wantOk: false,
},
{
Expand Down Expand Up @@ -719,7 +719,7 @@ func Test_maxBoundedFloor(t *testing.T) {
wantOk: true,
},
{
name: "multiple_floors_wildcard",
name: "multiple_floors_match_all",
fs: []Endless{
NewLessThan(MustParse("1")),
NewLessThanOrEqualTo(MustParse("1")),
Expand All @@ -729,7 +729,7 @@ func Test_maxBoundedFloor(t *testing.T) {
NewGreaterThan(MustParse("3")),
NewGreaterThanOrEqualTo(MustParse("4")),
NewGreaterThan(MustParse("4")),
NewWildcard(),
NewMatchAll(),
},
want: NewGreaterThan(MustParse("4")),
wantOk: true,
Expand All @@ -747,14 +747,14 @@ func Test_maxBoundedFloor(t *testing.T) {
wantOk: true,
},
{
name: "single_floor_wildcard",
name: "single_floor_match_all",
fs: []Endless{
NewLessThan(MustParse("1")),
NewLessThanOrEqualTo(MustParse("1")),
NewLessThan(MustParse("2")),
NewLessThanOrEqualTo(MustParse("2")),
NewGreaterThan(MustParse("3")),
NewWildcard(),
NewMatchAll(),
},
want: NewGreaterThan(MustParse("3")),
wantOk: true,
Expand Down
Loading

0 comments on commit 72fff8c

Please sign in to comment.