| 1 |
project('string arithmetic', meson_version: '>=0.62.0') |
| 2 |
|
| 3 |
assert('foo' + 'bar' == 'foobar') |
| 4 |
assert('foo' + 'bar' + 'baz' == 'foobarbaz') |
| 5 |
|
| 6 |
a = 'a' |
| 7 |
b = 'b' |
| 8 |
assert(a + b + 'c' == 'abc') |
| 9 |
|
| 10 |
# ------------------------------------------------------------------------------ |
| 11 |
# format strings: |
| 12 |
# ------------------------------------------------------------------------------ |
| 13 |
sub1 = 'the' |
| 14 |
sub2 = ' quick\n' |
| 15 |
sub3 = ' brown' |
| 16 |
sub4 = '\nfox' |
| 17 |
x = f'@sub1@@sub2@@sub3@@sub4@' |
| 18 |
|
| 19 |
assert(x == sub1 + sub2 + sub3 + sub4) |
| 20 |
assert(x == 'the quick\n brown\nfox') |
| 21 |
|
| 22 |
# ------------------------------------------------------------------------------ |
| 23 |
# multi-line format strings |
| 24 |
# ------------------------------------------------------------------------------ |
| 25 |
y_actual = f'''This is a multi-line comment with string substitution: |
| 26 |
"@sub1@@sub2@@sub3@@sub4@" |
| 27 |
|
| 28 |
And I can even substitute the entry multiple times! |
| 29 |
|
| 30 |
@sub1@ |
| 31 |
@sub2@ |
| 32 |
@sub3@ |
| 33 |
''' |
| 34 |
|
| 35 |
y_expect = '''This is a multi-line comment with string substitution: |
| 36 |
"the quick |
| 37 |
brown |
| 38 |
fox" |
| 39 |
|
| 40 |
And I can even substitute the entry multiple times! |
| 41 |
|
| 42 |
the |
| 43 |
quick |
| 44 |
|
| 45 |
brown |
| 46 |
''' |
| 47 |
message('actual=' + y_actual) |
| 48 |
message('expect=' + y_expect) |
| 49 |
assert(y_actual == y_expect) |