1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: encode newlines as \n in the assert meta information

This commit is contained in:
Delyan Angelov 2020-11-01 16:59:26 +02:00
parent e72d9c0f88
commit e2505479ee
2 changed files with 15 additions and 3 deletions

View File

@ -1313,6 +1313,10 @@ fn (mut g Gen) gen_assert_stmt(original_assert_statement ast.AssertStmt) {
g.writeln('}')
}
fn cnewlines(s string) string {
return s.replace('\n', r'\n')
}
fn (mut g Gen) gen_assert_metainfo(a ast.AssertStmt) string {
mod_path := cestring(g.file.path)
fn_name := g.fn_decl.name
@ -1324,12 +1328,12 @@ fn (mut g Gen) gen_assert_metainfo(a ast.AssertStmt) string {
g.writeln('\t${metaname}.fpath = ${ctoslit(mod_path)};')
g.writeln('\t${metaname}.line_nr = $line_nr;')
g.writeln('\t${metaname}.fn_name = ${ctoslit(fn_name)};')
g.writeln('\t${metaname}.src = ${ctoslit(src)};')
g.writeln('\t${metaname}.src = ${cnewlines(ctoslit(src))};')
match a.expr {
ast.InfixExpr {
g.writeln('\t${metaname}.op = ${ctoslit(it.op.str())};')
g.writeln('\t${metaname}.llabel = ${ctoslit(it.left.str())};')
g.writeln('\t${metaname}.rlabel = ${ctoslit(it.right.str())};')
g.writeln('\t${metaname}.llabel = ${cnewlines(ctoslit(it.left.str()))};')
g.writeln('\t${metaname}.rlabel = ${cnewlines(ctoslit(it.right.str()))};')
g.write('\t${metaname}.lvalue = ')
g.gen_assert_single_expr(it.left, it.left_type)
g.writeln(';')

View File

@ -0,0 +1,8 @@
fn test_assert_with_newlines_in_the_labels() {
println('start')
s := '123
456'
assert s == '123
456'
println('done')
}