1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix rune array sort (#9561)

This commit is contained in:
yuyi
2021-04-02 22:28:27 +08:00
committed by GitHub
parent 9ba8d02a5a
commit 3637bac716
2 changed files with 69 additions and 38 deletions

View File

@ -807,6 +807,21 @@ fn test_sort() {
// assert users.map(it.name).join(' ') == 'Alice Bob Peter'
}
fn test_rune_sort() {
mut bs := [`f`, `e`, `d`, `b`, `c`, `a`]
bs.sort()
println(bs)
assert '$bs' == '[`a`, `b`, `c`, `d`, `e`, `f`]'
bs.sort(a > b)
println(bs)
assert '$bs' == '[`f`, `e`, `d`, `c`, `b`, `a`]'
bs.sort(a < b)
println(bs)
assert '$bs' == '[`a`, `b`, `c`, `d`, `e`, `f`]'
}
fn test_sort_by_different_order_of_a_b() {
mut x := [1, 2, 3]
x.sort(a < b)