summaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2025-07-24 14:17:55 +0200
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-11-28 12:41:01 +0200
commit0fb9c5a6839205cc32c2632dd20f723f00dc165b (patch)
tree0dab116976dbf400ed9f95860ac683435466d321 /test cases
parent5e399434f2c3bb791f0c16f01fa85680c3f90fb7 (diff)
downloadmeson-0fb9c5a6839205cc32c2632dd20f723f00dc165b.tar.gz
interpreter: Add a slice() method to arrays
This can come in handy for instance when a custom target creates both headers and sources. Slicing the output of a `to_list()` call provides convenient access to just the headers or just the sources.
Diffstat (limited to 'test cases')
-rw-r--r--test cases/common/56 array methods/meson.build10
1 files changed, 10 insertions, 0 deletions
diff --git a/test cases/common/56 array methods/meson.build b/test cases/common/56 array methods/meson.build
index 3707775ec..3cc1067b9 100644
--- a/test cases/common/56 array methods/meson.build
+++ b/test cases/common/56 array methods/meson.build
@@ -69,6 +69,16 @@ if not combined.contains('ghi')
error('Combined claims not to contain ghi.')
endif
+# test array slicing
+assert(['a', 'b', 'c'].slice() == ['a', 'b', 'c'])
+assert(['a', 'b', 'c'].slice(step : 2) == ['a', 'c'])
+assert(['a', 'b', 'c'].slice(step : -1) == ['c', 'b', 'a'])
+assert(['a', 'b', 'c'].slice(step : -2) == ['c', 'a'])
+assert(['a', 'b', 'c'].slice(1, 2) == ['b'])
+assert(['a', 'b', 'c'].slice(2, -2) == [])
+assert(['a', 'b', 'c'].slice(-9876543, 2) == ['a', 'b'])
+assert(['a', 'b', 'c', 'd', 'e'].slice(1, 12, step : 2) == ['b', 'd'])
+
# test array flattening
x = ['a', ['b'], [[[[[[['c'], 'd']]], 'e']]]]
assert(x.length() == 3)