vfmt: skip skipped modules; add module test
parent
b95a47b5a7
commit
8fbae86bb3
|
@ -96,6 +96,7 @@ pub:
|
|||
name string
|
||||
path string
|
||||
expr Expr
|
||||
is_skipped bool // module main can be skipped in single file programs
|
||||
}
|
||||
|
||||
pub struct StructField {
|
||||
|
|
|
@ -61,7 +61,7 @@ pub fn (c mut Checker) check_files(ast_files []ast.File) {
|
|||
c.check(file)
|
||||
}
|
||||
// Make sure fn main is defined in non lib builds
|
||||
if c.pref.build_mode == .build_module {
|
||||
if c.pref.build_mode == .build_module || c.pref.is_test {
|
||||
return
|
||||
}
|
||||
for i, f in c.table.fns {
|
||||
|
|
|
@ -74,8 +74,11 @@ pub fn (f mut Fmt) writeln(s string) {
|
|||
}
|
||||
|
||||
fn (f mut Fmt) mod(mod ast.Module) {
|
||||
f.writeln('module $mod.name\n')
|
||||
f.cur_mod = mod.name
|
||||
if mod.is_skipped {
|
||||
return
|
||||
}
|
||||
f.writeln('module $mod.name\n')
|
||||
}
|
||||
|
||||
fn (f mut Fmt) imports(imports []ast.Import) {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
module module_fmt
|
||||
|
||||
pub struct MyStruct {
|
||||
mut:
|
||||
value int
|
||||
}
|
||||
|
||||
pub fn (m MyStruct) foo() bool {
|
||||
return true
|
||||
}
|
|
@ -254,10 +254,6 @@ fn (p mut Parser) check_name() string {
|
|||
}
|
||||
|
||||
pub fn (p mut Parser) top_stmt() ast.Stmt {
|
||||
if p.fileis('mmm.v') {
|
||||
print('!!stmt()')
|
||||
println(p.tok.kind.str())
|
||||
}
|
||||
match p.tok.kind {
|
||||
.key_pub {
|
||||
match p.peek_tok.kind {
|
||||
|
@ -518,7 +514,6 @@ fn (p mut Parser) range_expr(low ast.Expr) ast.Expr {
|
|||
return node
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn (p &Parser) error(s string) {
|
||||
p.error_with_pos(s, p.tok.position())
|
||||
}
|
||||
|
@ -1409,7 +1404,8 @@ fn (p mut Parser) parse_number_literal() ast.Expr {
|
|||
|
||||
fn (p mut Parser) module_decl() ast.Module {
|
||||
mut name := 'main'
|
||||
if p.tok.kind == .key_module {
|
||||
is_skipped := p.tok.kind != .key_module
|
||||
if !is_skipped {
|
||||
p.check(.key_module)
|
||||
name = p.check_name()
|
||||
}
|
||||
|
@ -1418,6 +1414,7 @@ fn (p mut Parser) module_decl() ast.Module {
|
|||
p.builtin_mod = p.mod == 'builtin'
|
||||
return ast.Module{
|
||||
name: full_mod
|
||||
is_skipped: is_skipped
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue