Skip to content

Commit

Permalink
add not found cases in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Oct 20, 2024
1 parent b2baa19 commit 12de959
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions vlib/builtin/fixed_array_index_test.v
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
fn test_index_of_ints() {
ia := [1, 2, 3]!
ii := ia.index(2)
mut ii := ia.index(2)
dump(ii)
assert ii == 1

ii = ia.index(5)
dump(ii)
assert ii == -1
}

fn test_index_of_strings() {
sa := ['a', 'b', 'c']!
si := sa.index('b')
mut si := sa.index('b')
dump(si)
assert si == 1

si = sa.index('v')
dump(si)
assert si == -1
}

fn test_index_of_voidptrs() {
pa := [voidptr(123), voidptr(45), voidptr(99)]!
pi := pa.index(voidptr(45))
mut pi := pa.index(voidptr(45))
dump(pi)
assert pi == 1
}

//////////
pi = pa.index(unsafe { nil })
dump(pi)
assert pi == -1
}

fn a() {}

fn b() {}

fn c() {}

fn v() {}

fn test_index_of_fns() {
fa := [a, b, c]!
fi := fa.index(b)
mut fi := fa.index(b)
dump(fi)
assert fi == 1

fi = fa.index(v)
dump(fi)
assert fi == -1
}

0 comments on commit 12de959

Please sign in to comment.