The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.8 KiB
104 lines
3.8 KiB
11 years ago
|
project('string formatting', 'c')
|
||
|
|
||
|
templ = '@0@bar@1@'
|
||
|
|
||
9 years ago
|
assert(templ.format('foo', 'baz') == 'foobarbaz', 'Basic string formatting is broken.')
|
||
11 years ago
|
|
||
9 years ago
|
assert('@0@'.format(1) == '1', 'String number formatting is broken.')
|
||
11 years ago
|
|
||
9 years ago
|
assert('@0@'.format(true) == 'true', 'String boolean formatting is broken.')
|
||
11 years ago
|
|
||
|
templ2 = '@0@'
|
||
|
subs2 = '42'
|
||
|
|
||
9 years ago
|
assert(templ2.format(subs2) == '42', 'String formatting with variables is broken.')
|
||
9 years ago
|
|
||
7 years ago
|
assert('@@0@@ @@1@@'.format(1, 2) == '@1@ @2@', 'String format is recursive.')
|
||
|
|
||
9 years ago
|
long = 'abcde'
|
||
|
prefix = 'abc'
|
||
|
suffix = 'cde'
|
||
|
|
||
9 years ago
|
assert(long.startswith(prefix), 'Prefix.')
|
||
9 years ago
|
|
||
9 years ago
|
assert(not long.startswith(suffix), 'Not prefix.')
|
||
9 years ago
|
|
||
9 years ago
|
assert(long.endswith(suffix), 'Suffix.')
|
||
9 years ago
|
|
||
9 years ago
|
assert(not long.endswith(prefix), 'Not suffix.')
|
||
9 years ago
|
|
||
9 years ago
|
assert(long.contains(prefix), 'Does not contain prefix')
|
||
9 years ago
|
|
||
9 years ago
|
assert(long.contains(suffix), 'Does not contain suffix')
|
||
9 years ago
|
|
||
9 years ago
|
assert(long.contains('bcd'), 'Does not contain middle part')
|
||
9 years ago
|
|
||
9 years ago
|
assert(not long.contains('dc'), 'Broken contains')
|
||
9 years ago
|
|
||
9 years ago
|
assert(long.to_upper() == 'ABCDE', 'Broken to_upper')
|
||
9 years ago
|
|
||
9 years ago
|
assert(long.to_upper().to_lower() == long, 'Broken to_lower')
|
||
9 years ago
|
|
||
9 years ago
|
assert('struct stat.st_foo'.underscorify() == 'struct_stat_st_foo', 'Broken underscorify')
|
||
9 years ago
|
|
||
9 years ago
|
assert('#include <foo/bar.h>'.underscorify() == '_include__foo_bar_h_', 'Broken underscorify')
|
||
9 years ago
|
|
||
|
# case should not change, space should be replaced, numbers are ok too
|
||
9 years ago
|
assert('Do SomeThing 09'.underscorify() == 'Do_SomeThing_09', 'Broken underscorify')
|
||
9 years ago
|
|
||
9 years ago
|
assert('3'.to_int() == 3, 'String int conversion does not work.')
|
||
9 years ago
|
|
||
|
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')
|
||
9 years ago
|
|
||
|
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')
|
||
9 years ago
|
|
||
|
version_number = '1.2.8'
|
||
|
|
||
|
assert(version_number.version_compare('>=1.2.8'), 'Version_compare gt broken')
|
||
|
assert(not version_number.version_compare('>1.2.8'), 'Version_compare greater broken')
|
||
|
assert(not version_number.version_compare('<1.2.8'), 'Version_compare less broken')
|
||
|
assert(version_number.version_compare('<=1.2.8'), 'Version_compare le broken')
|
||
|
assert(version_number.version_compare('==1.2.8'), 'Version_compare eq broken')
|
||
|
assert(not version_number.version_compare('!=1.2.8'), 'Version_compare neq broken')
|
||
|
|
||
|
assert(version_number.version_compare('<2.0'), 'Version_compare major less broken')
|
||
|
assert(version_number.version_compare('>0.9'), 'Version_compare major greater broken')
|
||
7 years ago
|
|
||
|
assert(' spaces tabs '.strip() == 'spaces tabs', 'Spaces and tabs badly stripped')
|
||
|
assert('''
|
||
|
multiline string '''.strip() == '''multiline string''', 'Newlines badly stripped')
|
||
|
assert('"1.1.20"'.strip('"') == '1.1.20', '" badly stripped')
|
||
|
assert('"1.1.20"'.strip('".') == '1.1.20', '". badly stripped')
|
||
|
assert('"1.1.20" '.strip('" ') == '1.1.20', '". badly stripped')
|
||
7 years ago
|
|
||
7 years ago
|
bs_c = '''\c'''
|
||
7 years ago
|
bs_bs_c = '''\\c'''
|
||
7 years ago
|
nl = '''
|
||
|
'''
|
||
7 years ago
|
bs_n = '''\n'''
|
||
7 years ago
|
bs_nl = '''\
|
||
|
'''
|
||
7 years ago
|
bs_bs_n = '''\\n'''
|
||
|
bs_bs_nl = '''\\
|
||
7 years ago
|
'''
|
||
7 years ago
|
bs_bs = '''\\'''
|
||
|
bs = '''\'''
|
||
7 years ago
|
|
||
7 years ago
|
assert('\c' == bs_c, 'Single backslash broken')
|
||
|
assert('\\c' == bs_c, 'Double backslash broken')
|
||
|
assert('\\\c' == bs_bs_c, 'Three backslash broken')
|
||
|
assert('\\\\c' == bs_bs_c, 'Four backslash broken')
|
||
7 years ago
|
assert('\n' == nl, 'Newline escape broken')
|
||
|
assert('\\n' == bs_n, 'Double backslash broken before n')
|
||
|
assert('\\\n' == bs_nl, 'Three backslash broken before n')
|
||
|
assert('\\\\n' == bs_bs_n, 'Four backslash broken before n')
|
||
7 years ago
|
assert('\\\\\n' == bs_bs_nl, 'Five backslash broken before n')
|
||
7 years ago
|
assert('\\\\' == bs_bs, 'Double-backslash broken')
|
||
|
assert('\\' == bs, 'Backslash broken')
|