Skip to content

Commit

Permalink
builtin: improve fixed_array_any_all_test.v (vlang#22746)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Nov 3, 2024
1 parent abb4057 commit 335bb63
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions vlib/builtin/fixed_array_any_all_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,51 @@ fn test_any_all_of_ints() {

assert ia.any(it > 2)
assert ia.any(|x| x > 2)
assert [1, 2, 3]!.any(it > 2)
assert [1, 2, 3]!.any(|x| x > 2)

assert !ia.all(it > 1)
assert !ia.all(|x| x > 1)
assert ![1, 2, 3]!.all(it > 1)
assert ![1, 2, 3]!.all(|x| x > 1)

assert ia.any(it == 2)
assert ia.any(|x| x == 2)
assert [1, 2, 3]!.any(it == 2)
assert [1, 2, 3]!.any(|x| x == 2)

assert !ia.all(it == 3)
assert !ia.all(|x| x == 3)
assert ![1, 2, 3]!.all(it == 3)
assert ![1, 2, 3]!.all(|x| x == 3)
}

fn test_any_all_of_strings() {
sa := ['a', 'b', 'c']!

assert sa.any(it == 'b')
assert sa.any(|x| x == 'b')
assert ['a', 'b', 'c']!.any(it == 'b')
assert ['a', 'b', 'c']!.any(|x| x == 'b')

assert !sa.all(it == 'c')
assert !sa.all(|x| x == 'c')
assert !['a', 'b', 'c']!.all(it == 'c')
assert !['a', 'b', 'c']!.all(|x| x == 'c')
}

fn test_any_all_of_voidptrs() {
pa := [voidptr(123), voidptr(45), voidptr(99)]!

assert pa.any(it == voidptr(45))
assert pa.any(|x| x == voidptr(45))
assert [voidptr(123), voidptr(45), voidptr(99)]!.any(it == voidptr(45))
assert [voidptr(123), voidptr(45), voidptr(99)]!.any(|x| x == voidptr(45))

assert !pa.all(it == voidptr(123))
assert !pa.all(|x| x == voidptr(123))
assert ![voidptr(123), voidptr(45), voidptr(99)]!.all(it == voidptr(123))
assert ![voidptr(123), voidptr(45), voidptr(99)]!.all(|x| x == voidptr(123))
}

fn a() {}
Expand All @@ -47,7 +63,11 @@ fn test_any_all_of_fns() {

assert fa.any(it == b)
assert fa.any(|x| x == b)
assert [a, b, c]!.any(it == b)
assert [a, b, c]!.any(|x| x == b)

assert !fa.all(it == v)
assert !fa.all(|x| x == v)
assert ![a, b, c]!.all(it == v)
assert ![a, b, c]!.all(|x| x == v)
}

0 comments on commit 335bb63

Please sign in to comment.