Skip to content

Commit

Permalink
tests: add tests for checking fixed array .sort() errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Oct 26, 2024
1 parent 419645a commit c8d2f8f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
45 changes: 45 additions & 0 deletions vlib/v/checker/tests/fixed_array_sort_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
vlib/v/checker/tests/fixed_array_sort_err.vv:3:6: error: expected 0 or 1 argument, but got 2
1 | fn main() {
2 | mut arr := [3, 2, 1]!
3 | arr.sort(a < b, a)
| ~~~~~~~~~~~~~~
4 | arr.sort(a == b)
5 | arr.sort(a > a)
vlib/v/checker/tests/fixed_array_sort_err.vv:4:6: error: `.sort()` can only use `<` or `>` comparison
2 | mut arr := [3, 2, 1]!
3 | arr.sort(a < b, a)
4 | arr.sort(a == b)
| ~~~~~~~~~~~~
5 | arr.sort(a > a)
6 | arr.sort(c > d)
vlib/v/checker/tests/fixed_array_sort_err.vv:5:6: error: `.sort()` cannot use same argument
3 | arr.sort(a < b, a)
4 | arr.sort(a == b)
5 | arr.sort(a > a)
| ~~~~~~~~~~~
6 | arr.sort(c > d)
7 | }
vlib/v/checker/tests/fixed_array_sort_err.vv:6:11: error: can not access external variable `c`
4 | arr.sort(a == b)
5 | arr.sort(a > a)
6 | arr.sort(c > d)
| ^
7 | }
vlib/v/checker/tests/fixed_array_sort_err.vv:6:6: error: `.sort()` can only use `a` or `b` as argument, e.g. `arr.sort(a < b)`
4 | arr.sort(a == b)
5 | arr.sort(a > a)
6 | arr.sort(c > d)
| ~~~~~~~~~~~
7 | }
vlib/v/checker/tests/fixed_array_sort_err.vv:6:11: error: undefined ident: `c`
4 | arr.sort(a == b)
5 | arr.sort(a > a)
6 | arr.sort(c > d)
| ^
7 | }
vlib/v/checker/tests/fixed_array_sort_err.vv:6:15: error: undefined ident: `d`
4 | arr.sort(a == b)
5 | arr.sort(a > a)
6 | arr.sort(c > d)
| ^
7 | }
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/fixed_array_sort_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
mut arr := [3, 2, 1]!
arr.sort(a < b, a)
arr.sort(a == b)
arr.sort(a > a)
arr.sort(c > d)
}
12 changes: 12 additions & 0 deletions vlib/v/checker/tests/fn_return_fixed_array_sort_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
vlib/v/checker/tests/fn_return_fixed_array_sort_err.vv:6:14: error: the `sort()` method can be called only on mutable receivers, but `ret_array()` is a call expression
4 |
5 | fn main() {
6 | ret_array().sort()
| ~~~~~~
7 | }
vlib/v/checker/tests/fn_return_fixed_array_sort_err.vv:6:2: error: cannot pass expression as `mut`
4 |
5 | fn main() {
6 | ret_array().sort()
| ~~~~~~~~~~~
7 | }
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/fn_return_fixed_array_sort_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn ret_array() [3]int {
return [1, 3, 2]!
}

fn main() {
ret_array().sort()
}

0 comments on commit c8d2f8f

Please sign in to comment.