diff --git a/tests/valid/src/for_stmt.ri b/tests/valid/src/for_stmt.ri index adf6ef590..8367c3027 100644 --- a/tests/valid/src/for_stmt.ri +++ b/tests/valid/src/for_stmt.ri @@ -14,6 +14,14 @@ test "`for` statement with dynamic array" { @assert(sum == 55); } +test "`for` statement with slice" { + mut sum := 0; + for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10][:] { + sum += i; + } + @assert(sum == 55); +} + test "`for` statement with `string.as_bytes()`" { mut sum := 0; for b in "Hello World!".as_bytes() { diff --git a/tests/valid/src/slices.ri b/tests/valid/src/slices.ri new file mode 100644 index 000000000..ad2e5a6e3 --- /dev/null +++ b/tests/valid/src/slices.ri @@ -0,0 +1,17 @@ +test "creating slices from arrays" { + arr := [1, 2, 3, 4]; + slice := arr[:]; + @assert(slice[0] == 1); + @assert(slice[1] == 2); + @assert(slice[2] == 3); + @assert(slice[3] == 4); +} + +test "creating slices from dynamic arrays" { + arr := +[1, 2, 3, 4]; + slice := arr[:]; + @assert(slice[0] == 1); + @assert(slice[1] == 2); + @assert(slice[2] == 3); + @assert(slice[3] == 4); +}