Skip to content

Commit ab2e3e9

Browse files
committed
wip
1 parent 87a0f5f commit ab2e3e9

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

and.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const (
88
ErrImpossibleInterval stringError = "impossible interval"
99
)
1010

11+
// And returns a [CeilingFloorConstrainter] instance representing the logical AND of
12+
// the given [Endless] instances; or return an error if the given [Endless] instances could never be
13+
// satisfied.
1114
func And(es ...Endless) (CeilingFloorConstrainter, error) {
1215
if len(es) == 0 {
1316
var c CeilingFloorConstrainter
@@ -60,8 +63,18 @@ func And(es ...Endless) (CeilingFloorConstrainter, error) {
6063
return NewExactConstraint(*floor.Floor().version), nil
6164
}
6265

63-
return Interval{
66+
return interval{
6467
ceiling: ceiling,
6568
floor: floor,
6669
}, nil
6770
}
71+
72+
// MustAnd is like [And] but panics if an error occurs.
73+
func MustAnd(es ...Endless) CeilingFloorConstrainter {
74+
c, err := And(es...)
75+
if err != nil {
76+
panic(err)
77+
}
78+
79+
return c
80+
}

and_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestAnd(t *testing.T) {
282282
NewLessThan(MustParse("4")),
283283
NewGreaterThan(MustParse("1")),
284284
},
285-
want: Interval{
285+
want: interval{
286286
ceiling: NewLessThan(MustParse("4")),
287287
floor: NewGreaterThan(MustParse("1")),
288288
},
@@ -297,7 +297,7 @@ func TestAnd(t *testing.T) {
297297
NewLessThan(MustParse("3")),
298298
NewGreaterThan(MustParse("1")),
299299
},
300-
want: Interval{
300+
want: interval{
301301
ceiling: NewLessThan(MustParse("3")),
302302
floor: NewGreaterThan(MustParse("1")),
303303
},
@@ -311,7 +311,7 @@ func TestAnd(t *testing.T) {
311311
NewLessThanOrEqualTo(MustParse("3")),
312312
NewGreaterThan(MustParse("1")),
313313
},
314-
want: Interval{
314+
want: interval{
315315
ceiling: NewLessThanOrEqualTo(MustParse("3")),
316316
floor: NewGreaterThan(MustParse("1")),
317317
},
@@ -326,7 +326,7 @@ func TestAnd(t *testing.T) {
326326
NewGreaterThan(MustParse("1")),
327327
NewGreaterThanOrEqualTo(MustParse("1")),
328328
},
329-
want: Interval{
329+
want: interval{
330330
ceiling: NewLessThan(MustParse("4")),
331331
floor: NewGreaterThan(MustParse("2")),
332332
},
@@ -340,7 +340,7 @@ func TestAnd(t *testing.T) {
340340
NewGreaterThan(MustParse("1")),
341341
NewGreaterThanOrEqualTo(MustParse("1")),
342342
},
343-
want: Interval{
343+
want: interval{
344344
ceiling: NewLessThan(MustParse("4")),
345345
floor: NewGreaterThanOrEqualTo(MustParse("2")),
346346
},
@@ -358,7 +358,7 @@ func TestAnd(t *testing.T) {
358358
NewGreaterThan(MustParse("1")),
359359
NewGreaterThanOrEqualTo(MustParse("1")),
360360
},
361-
want: Interval{
361+
want: interval{
362362
ceiling: NewLessThan(MustParse("3")),
363363
floor: NewGreaterThan(MustParse("2")),
364364
},
@@ -377,7 +377,7 @@ func TestAnd(t *testing.T) {
377377
NewGreaterThanOrEqualTo(MustParse("1")),
378378
NewWildcard(),
379379
},
380-
want: Interval{
380+
want: interval{
381381
ceiling: NewLessThan(MustParse("3")),
382382
floor: NewGreaterThan(MustParse("2")),
383383
},

interval.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
package comver
22

3-
// Interval represents a constraint that is both floor bounded and ceiling bounded.
3+
// interval represents a constraint that is both floor bounded and ceiling bounded.
44
// It must be initialized via [And].
5-
type Interval struct {
5+
type interval struct {
66
ceiling Endless
77
floor Endless
88
}
99

1010
// Check reports whether a [Version] satisfies the constraint.
11-
func (i Interval) Check(v Version) bool {
11+
func (i interval) Check(v Version) bool {
1212
return i.ceiling.Check(v) && i.floor.Check(v)
1313
}
1414

15-
func (i Interval) Ceiling() Endless {
15+
func (i interval) Ceiling() Endless {
1616
return i.ceiling
1717
}
1818

19-
func (i Interval) Floor() Endless {
19+
func (i interval) Floor() Endless {
2020
return i.floor
2121
}
2222

23-
func (i Interval) String() string {
23+
func (i interval) String() string {
2424
if i.ceiling.wildcard() {
2525
return i.floor.String()
2626
}

or.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (o Or) Check(v Version) bool {
4040
// cs = append(cs, tail)
4141
// }
4242
//
43-
// // TODO: Check whether Interval{head, tail} are wildcard.
43+
// // TODO: Check whether interval{head, tail} are wildcard.
4444
// // If yes, early return wildcard
4545
//
4646
// // important!
@@ -88,7 +88,7 @@ func compactTwoSCs(a, b CeilingFloorConstrainter) (CeilingFloorConstrainter, boo
8888
return a, true
8989
}
9090

91-
return Interval{a.Floor(), b.Ceiling()}, true
91+
return interval{a.Floor(), b.Ceiling()}, true
9292
}
9393

9494
func compareSimpleConstrainters(a, b CeilingFloorConstrainter) int {

0 commit comments

Comments
 (0)