Skip to content

Commit

Permalink
pkg/list: simply template for Ascending
Browse files Browse the repository at this point in the history
The parentheses are a holdover of old school CUE which
used <a>: b for pattern constraints, instead of [a]: b.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ia39110623c779a56e6dce6928c7d816e75f86855
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/549088
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mpvl committed Feb 9, 2023
1 parent 9f538a6 commit 9dbb373
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/list/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions pkg/list/sort.cue
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ Comparer: {
// list.Sort(a, list.Ascending)
Ascending: {
Comparer
T: number | string
x: T
y: T
// TODO: the following will be fixed when removing old-school templating.
less: true && (x < y)
T: number | string
x: T
y: T
less: x < y
}

// Descending defines a Comparer to sort comparable values in decreasing order.
Expand All @@ -44,5 +43,5 @@ Descending: {
T: number | string
x: T
y: T
less: (x > y)
less: x > y
}
4 changes: 2 additions & 2 deletions pkg/list/testdata/gen.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ t36: error in call to list.Slice: slice bounds out of range:
./in.cue:38:6
t40: error in call to list.Sort: 2 errors in empty disjunction::
./in.cue:46:6
list:13:17
list:13:9
t42: invalid list element 0 in argument 0 to call: cannot use value 1 (int) as string:
./in.cue:48:6
./in.cue:48:24
Expand All @@ -110,7 +110,7 @@ t49: error in call to list.Take: negative index:
./in.cue:55:6
t54: error in call to list.Sort: 2 errors in empty disjunction::
./in.cue:60:6
list:13:17
list:13:9

Result:
t1: 2.5
Expand Down

0 comments on commit 9dbb373

Please sign in to comment.