cgen: fix double escaping \n in @VMOD_FILE expansion

pull/7152/head
Delyan Angelov 2020-12-05 20:13:30 +02:00
parent 7212b2eff2
commit 6e76d5d1db
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 9 additions and 4 deletions

View File

@ -110,7 +110,7 @@ fn cgen_attrs(attrs []table.Attr) []string {
fn (mut g Gen) comp_at(node ast.AtExpr) { fn (mut g Gen) comp_at(node ast.AtExpr) {
if node.kind == .vmod_file { if node.kind == .vmod_file {
val := cnewlines(node.val.replace('\r', '')).replace('\\', '\\\\') val := cnewlines(node.val.replace('\r', ''))
g.write('_SLIT("$val")') g.write('_SLIT("$val")')
} else { } else {
val := node.val.replace('\\', '\\\\') val := node.val.replace('\\', '\\\\')

View File

@ -3,9 +3,7 @@ import os
fn test_from_file() { fn test_from_file() {
os.chdir(os.dir(os.getenv('VEXE'))) os.chdir(os.dir(os.getenv('VEXE')))
data := vmod.from_file('./v.mod') or { data := vmod.from_file('./v.mod') or { panic(err) }
panic(err)
}
assert data.name == 'V' assert data.name == 'V'
assert data.description == 'The V programming language.' assert data.description == 'The V programming language.'
assert data.version == '0.1.30' assert data.version == '0.1.30'
@ -42,3 +40,10 @@ fn test_decode() {
exit(0) exit(0)
} }
} }
fn test_decode_with_comptime_vmod_file() {
mod := vmod.decode(@VMOD_FILE) or { panic('Error decoding v.mod') }
assert mod.name == 'V'
assert mod.repo_url == 'https://github.com/vlang/v'
assert mod.license == 'MIT'
}