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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)