diff options
-rw-r--r-- | mesonbuild/interpreter.py | 5 | ||||
-rw-r--r-- | test cases/common/42 string formatting/meson.build | 2 | ||||
-rw-r--r-- | test cases/failing/25 int conversion/meson.build | 3 |
3 files changed, 10 insertions, 0 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 4894ac7..0a321a2 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2019,6 +2019,11 @@ class Interpreter(): if method_name == 'startswith': return obj.startswith(s) return obj.endswith(s) + elif method_name == 'to_int': + try: + return int(obj) + except Exception: + raise InterpreterException('String can not be converted to int: ' + obj) raise InterpreterException('Unknown method "%s" for a string.' % method_name) def to_native(self, arg): diff --git a/test cases/common/42 string formatting/meson.build b/test cases/common/42 string formatting/meson.build index 81f5268..39737f7 100644 --- a/test cases/common/42 string formatting/meson.build +++ b/test cases/common/42 string formatting/meson.build @@ -40,3 +40,5 @@ endif if long.endswith(prefix) error('Not suffix.') endif + +assert('3'.to_int() == 3, 'String int conversion does not work.') diff --git a/test cases/failing/25 int conversion/meson.build b/test cases/failing/25 int conversion/meson.build new file mode 100644 index 0000000..51f6c7e --- /dev/null +++ b/test cases/failing/25 int conversion/meson.build @@ -0,0 +1,3 @@ +project('int conversion', 'c') + +'notanumber'.to_int() |