aboutsummaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorMartin Dørum <dorum@noisolation.com>2023-06-19 16:55:16 +0200
committerXavier Claessens <xclaesse@gmail.com>2023-06-20 08:28:47 -0400
commite869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9 (patch)
tree88f235010db650cef6d475225acf7e7d157c6c2c /test cases
parent8c766f5b5bd33c93deabff41e2152d7f7e368492 (diff)
downloadmeson-e869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9.zip
meson-e869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9.tar.gz
meson-e869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9.tar.bz2
add str.splitlines method
The new splitlines method on str is intended to replace usage of fs.read('whatever').strip().split('\n'). The problem with the .strip().split() approach is that it doesn't have a way to represent empty lists (an empty string becomes a list with one empty string, not an empty list), and it doesn't handle Windows-style line endings.
Diffstat (limited to 'test cases')
-rw-r--r--test cases/common/35 string operations/meson.build12
1 files changed, 12 insertions, 0 deletions
diff --git a/test cases/common/35 string operations/meson.build b/test cases/common/35 string operations/meson.build
index 116fe0b..27cc0d8 100644
--- a/test cases/common/35 string operations/meson.build
+++ b/test cases/common/35 string operations/meson.build
@@ -125,3 +125,15 @@ assert(mysubstring.substring(10, -25) == '', 'substring is broken')
assert(mysubstring.substring(-4, 2) == '', 'substring is broken')
assert(mysubstring.substring(10, 9) == '', 'substring is broken')
assert(mysubstring.substring(8, 10) == 'z', 'substring is broken')
+
+# str.splitlines()
+assert('foo\nbar\nbaz'.splitlines() == ['foo', 'bar', 'baz'], 'splitlines is broken')
+assert(''.splitlines() == [], 'splitlines with empty string is broken')
+assert('foo\rbar\nbaz\n'.splitlines() == ['foo', 'bar', 'baz'], 'splitlines trailing newline is broken')
+assert('hello\r\nworld'.splitlines() == ['hello', 'world'])
+assert(
+ ' leading ws\nand trailing\t'.splitlines() == [' leading ws', 'and trailing\t'],
+ 'splitlines leading/trailing whitespace is broken',
+)
+assert('\n\r\n\r'.splitlines() == ['', '', ''], 'splitlines is broken')
+assert('foo'.splitlines() == ['foo'], 'splitlines is broken')