aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-11-10 22:49:39 -0500
committerMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-11-17 00:17:03 -0500
commit1a0b4ddf340130d270a4c96a36f915eb5b0399f3 (patch)
tree42b2fa47767f6868c166fa201f54029b5484fce4
parent4340f76a7aad400da51362e19c8af792ad6469fb (diff)
downloadmeson-1a0b4ddf340130d270a4c96a36f915eb5b0399f3.zip
meson-1a0b4ddf340130d270a4c96a36f915eb5b0399f3.tar.gz
meson-1a0b4ddf340130d270a4c96a36f915eb5b0399f3.tar.bz2
fs: further document and test behavior
-rw-r--r--docs/markdown/Fs-module.md30
-rw-r--r--test cases/common/227 fs module/meson.build12
2 files changed, 39 insertions, 3 deletions
diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md
index 3332b1e..7c2925f 100644
--- a/docs/markdown/Fs-module.md
+++ b/docs/markdown/Fs-module.md
@@ -36,11 +36,35 @@ by the string is a symbolic link.
### with_suffix
-The `with_suffix` method allows changing the filename suffix
+The `with_suffix` method is a *string manipulation* convenient for filename modifications.
+It allows changing the filename suffix like:
+
+## swap suffix
```meson
original = '/opt/foo.ini'
-new = fs.with_suffix('.txt')
+new = fs.with_suffix('.txt') # /opt/foo.txt
+```
+
+#### add suffix
+
+```meson
+original = '/opt/foo'
+new = fs.with_suffix('.txt') # /opt/foo.txt
+```
+
+#### compound suffix swap
+
+```meson
+original = '/opt/foo.dll.a'
+new = fs.with_suffix('.so') # /opt/foo.dll.so
+```
+
+#### delete suffix
+
+```meson
+original = '/opt/foo.dll.a'
+new = fs.with_suffix('') # /opt/foo.dll
```
-The files need not actually exist yet for this method. \ No newline at end of file
+The files need not actually exist yet for this method, as it's just string manipulation. \ No newline at end of file
diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build
index 75f4a99..f111d46 100644
--- a/test cases/common/227 fs module/meson.build
+++ b/test cases/common/227 fs module/meson.build
@@ -27,6 +27,18 @@ original = 'foo.txt'
new = fs.with_suffix(original, '.ini')
assert(new.endswith('foo.ini') and not new.contains('.txt'), 'with_suffix failed')
+original = 'foo'
+new = fs.with_suffix(original, '.ini')
+assert(new.endswith('foo.ini'), 'with_suffix did not add suffix to suffixless file')
+
+original = 'foo.dll.a'
+new = fs.with_suffix(original, '.so')
+assert(new.endswith('foo.dll.so'), 'with_suffix did not only modify last suffix')
+
+original = 'foo.dll'
+new = fs.with_suffix(original, '')
+assert(new.endswith('foo'), 'with_suffix did not only delete last suffix')
+
# `/` on windows is interpreted like `.drive` which in general may not be `c:/`
# the files need not exist for fs.with_suffix()
original = is_windows ? 'j:/foo/bar.txt' : '/foo/bar.txt'