meson/test cases/common/42 string formatting/meson.build

58 lines
1.9 KiB
Meson
Raw Normal View History

2013-07-28 01:09:30 +08:00
project('string formatting', 'c')
templ = '@0@bar@1@'
2016-03-13 00:51:29 +08:00
assert(templ.format('foo', 'baz') == 'foobarbaz', 'Basic string formatting is broken.')
2013-07-28 01:09:30 +08:00
2016-03-13 00:51:29 +08:00
assert('@0@'.format(1) == '1', 'String number formatting is broken.')
2013-07-28 01:09:30 +08:00
2016-03-13 00:51:29 +08:00
assert('@0@'.format(true) == 'true', 'String boolean formatting is broken.')
2013-07-28 01:28:11 +08:00
templ2 = '@0@'
subs2 = '42'
2016-03-13 00:51:29 +08:00
assert(templ2.format(subs2) == '42', 'String formatting with variables is broken.')
long = 'abcde'
prefix = 'abc'
suffix = 'cde'
2016-03-13 00:51:29 +08:00
assert(long.startswith(prefix), 'Prefix.')
2016-03-13 00:51:29 +08:00
assert(not long.startswith(suffix), 'Not prefix.')
2016-03-13 00:51:29 +08:00
assert(long.endswith(suffix), 'Suffix.')
2016-03-13 00:51:29 +08:00
assert(not long.endswith(prefix), 'Not suffix.')
2016-01-26 03:51:41 +08:00
2016-03-13 00:51:29 +08:00
assert(long.contains(prefix), 'Does not contain prefix')
2016-03-13 00:51:29 +08:00
assert(long.contains(suffix), 'Does not contain suffix')
2016-03-13 00:51:29 +08:00
assert(long.contains('bcd'), 'Does not contain middle part')
2016-03-13 00:51:29 +08:00
assert(not long.contains('dc'), 'Broken contains')
2016-03-13 00:51:29 +08:00
assert(long.to_upper() == 'ABCDE', 'Broken to_upper')
2016-03-13 00:51:29 +08:00
assert(long.to_upper().to_lower() == long, 'Broken to_lower')
2016-03-13 00:51:29 +08:00
assert('struct stat.st_foo'.underscorify() == 'struct_stat_st_foo', 'Broken underscorify')
2016-03-13 00:51:29 +08:00
assert('#include <foo/bar.h>'.underscorify() == '_include__foo_bar_h_', 'Broken underscorify')
# case should not change, space should be replaced, numbers are ok too
2016-03-13 00:51:29 +08:00
assert('Do SomeThing 09'.underscorify() == 'Do_SomeThing_09', 'Broken underscorify')
2016-01-26 03:51:41 +08:00
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')
assert(' '.join(['a', 'b', 'c']) == 'a b c', 'join() array broken')
assert(''.join(['a', 'b', 'c']) == 'abc', 'empty join() broken')
assert(' '.join(['a']) == 'a', 'single join broken')