aboutsummaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2016-03-19 17:57:11 +0000
committerTim-Philipp Müller <tim@centricular.com>2016-03-19 17:57:11 +0000
commit3eea1703ffb7559cc7d7454ced119aa45c167c9f (patch)
treec122e871e6db75250f0d4ad776cdfe3989e8ed27 /test cases
parentdc049660e7d5e7c4b4a9ded4acb02fe90860adfb (diff)
downloadmeson-3eea1703ffb7559cc7d7454ced119aa45c167c9f.zip
meson-3eea1703ffb7559cc7d7454ced119aa45c167c9f.tar.gz
meson-3eea1703ffb7559cc7d7454ced119aa45c167c9f.tar.bz2
Add bool to_string() and to_int() methods
bool to_int() will return 0 or 1, useful if one wants to set a define to 0 or 1 based on a boolean result instead of having it just defined or undefined. bool to_string() will return 'true' or 'false' by default same as when using it to format a string, but with the additional possibility to specify two extra string arguments to be returned as true/false values, e.g. to_string('yes', 'no'). This can be useful when outputting messages to be shown to the user.
Diffstat (limited to 'test cases')
-rw-r--r--test cases/common/42 string formatting/meson.build6
-rw-r--r--test cases/common/68 number arithmetic/meson.build3
2 files changed, 9 insertions, 0 deletions
diff --git a/test cases/common/42 string formatting/meson.build b/test cases/common/42 string formatting/meson.build
index 99855b3..c2ee151 100644
--- a/test cases/common/42 string formatting/meson.build
+++ b/test cases/common/42 string formatting/meson.build
@@ -45,3 +45,9 @@ assert('#include <foo/bar.h>'.underscorify() == '_include__foo_bar_h_', 'Broken
assert('Do SomeThing 09'.underscorify() == 'Do_SomeThing_09', 'Broken underscorify')
assert('3'.to_int() == 3, 'String int conversion does not work.')
+
+assert(true.to_string() == 'true', 'bool string conversion failed')
+assert(false.to_string() == 'false', 'bool string conversion failed')
+assert(true.to_string('yes', 'no') == 'yes', 'bool string conversion with args failed')
+assert(false.to_string('yes', 'no') == 'no', 'bool string conversion with args failed')
+assert('@0@'.format(true) == 'true', 'bool string formatting failed')
diff --git a/test cases/common/68 number arithmetic/meson.build b/test cases/common/68 number arithmetic/meson.build
index 3872a11..4b98d73 100644
--- a/test cases/common/68 number arithmetic/meson.build
+++ b/test cases/common/68 number arithmetic/meson.build
@@ -32,3 +32,6 @@ assert(not(3 > 4), 'Gt broken')
assert(4 >= 3, 'Gte broken')
assert(not(3 >= 4), 'Gte broken')
assert(3 >= 3, 'Gte broken')
+
+assert(true.to_int() == 1,'bool to_int() broken')
+assert(false.to_int() == 0,'bool to_int() broken')