Skip to content

Commit

Permalink
checker: allow for const source = $embed_file(@file).to_string()
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Sep 30, 2023
1 parent ae5b4bb commit ced5f21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vlib/v/checker/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type {
if node.args.len == 1 {
embed_arg := node.args[0]
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 {
raw_path = embed_arg.expr.val
} else if embed_arg.expr is ast.Ident {
Expand Down
8 changes: 8 additions & 0 deletions vlib/v/embed_file/tests/embed_file_self_test.v
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit ced5f21

Please sign in to comment.