diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-05-09 11:21:53 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-07-19 18:36:40 -0700 |
| commit | 6e379f0090b606786d540001b4a2de52f57e5e47 (patch) | |
| tree | ce0d303801a5a82b885f4690bbb6004b25258b96 /test cases | |
| parent | c3531971abca0d0987e919f452227b61b392f969 (diff) | |
| download | meson-6e379f0090b606786d540001b4a2de52f57e5e47.tar.gz | |
interpreter: Add a flatten() method to arrays
This allows users to do two things, flatten potentially nested arrays
themselves, and, to safely convert types that may be an array to not an
array.
```meson
x = [meson.get_external_property('may_be_array)].flatten()
```
```meson
x = ['a', ['b', 'c']]
assert(x.flatten() == ['a', 'b', 'c'])
```
Diffstat (limited to 'test cases')
| -rw-r--r-- | test cases/common/56 array methods/meson.build | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/test cases/common/56 array methods/meson.build b/test cases/common/56 array methods/meson.build index e9e4969c7..3707775ec 100644 --- a/test cases/common/56 array methods/meson.build +++ b/test cases/common/56 array methods/meson.build @@ -1,4 +1,4 @@ -project('array methods') +project('array methods', meson_version : '>= 1.9') empty = [] one = ['abc'] @@ -68,3 +68,10 @@ endif if not combined.contains('ghi') error('Combined claims not to contain ghi.') endif + +# test array flattening +x = ['a', ['b'], [[[[[[['c'], 'd']]], 'e']]]] +assert(x.length() == 3) +assert(x.flatten().length() == 5) +assert(x.flatten() == ['a', 'b', 'c', 'd', 'e']) +assert(['a', ['b', 'c']].flatten() == ['a', 'b', 'c']) |
