mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +03:00
checker: allow for const source = $embed_file(@FILE).to_string()
This commit is contained in:
parent
ae5b4bbd17
commit
ced5f213ef
2 changed files with 13 additions and 0 deletions
|
@ -71,6 +71,11 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type {
|
||||||
if node.args.len == 1 {
|
if node.args.len == 1 {
|
||||||
embed_arg := node.args[0]
|
embed_arg := node.args[0]
|
||||||
mut raw_path := ''
|
mut raw_path := ''
|
||||||
|
if embed_arg.expr is ast.AtExpr {
|
||||||
|
mut expr := embed_arg.expr
|
||||||
|
c.at_expr(mut expr)
|
||||||
|
raw_path = expr.val
|
||||||
|
}
|
||||||
if embed_arg.expr is ast.StringLiteral {
|
if embed_arg.expr is ast.StringLiteral {
|
||||||
raw_path = embed_arg.expr.val
|
raw_path = embed_arg.expr.val
|
||||||
} else if embed_arg.expr is ast.Ident {
|
} else if embed_arg.expr is ast.Ident {
|
||||||
|
|
8
vlib/v/embed_file/tests/embed_file_self_test.v
Normal file
8
vlib/v/embed_file/tests/embed_file_self_test.v
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
const self_file = $embed_file(@FILE)
|
||||||
|
|
||||||
|
fn test_self_file() {
|
||||||
|
source := self_file.to_string()
|
||||||
|
assert source.contains('self_file.to_string')
|
||||||
|
assert source.contains('fn test_self_file() {')
|
||||||
|
assert source.split_into_lines().len > @LINE.int()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue