pkg/list: fix MinItems
Closes #141
https://github.com/cuelang/cue/pull/141
GitOrigin-RevId: c1cf4de97091f8bd12e80a95ca8d9192cb7c7b71
Change-Id: Idaad1e6480696dd97fc6fd4effec76f2754e70bc
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3784
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/builtin_test.go b/cue/builtin_test.go
index 1331006..56c044f 100644
--- a/cue/builtin_test.go
+++ b/cue/builtin_test.go
@@ -249,6 +249,18 @@
test("list", `list.Take([1, 2, 3, 4], -1)`),
`_|_(error in call to list.Take: negative index)`,
}, {
+ test("list", `list.MinItems([1, 2, 3, 4], 2)`),
+ `true`,
+ }, {
+ test("list", `list.MinItems([1, 2, 3, 4], 5)`),
+ `false`,
+ }, {
+ test("list", `list.MaxItems([1, 2, 3, 4], 5)`),
+ `true`,
+ }, {
+ test("list", `list.MaxItems([1, 2, 3, 4], 2)`),
+ `false`,
+ }, {
// Panics
test("math", `math.Jacobi(1000, 2000)`),
`_|_(error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000)`,
diff --git a/cue/builtins.go b/cue/builtins.go
index e47225d..e5f9044 100644
--- a/cue/builtins.go
+++ b/cue/builtins.go
@@ -767,7 +767,7 @@
Func: func(c *callCtxt) {
a, n := c.list(0), c.int(1)
c.ret = func() interface{} {
- return len(a) <= n
+ return len(a) >= n
}()
},
}, {
diff --git a/pkg/list/list.go b/pkg/list/list.go
index fa8c869..e6b0dff 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -136,7 +136,7 @@
// MinItems reports whether a has at least n items.
func MinItems(a []cue.Value, n int) bool {
- return len(a) <= n
+ return len(a) >= n
}
// MaxItems reports whether a has at most n items.