vfmt: handle comments right after interface fields
parent
9c508237bd
commit
61b99e1915
|
@ -1096,29 +1096,39 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||||
|
|
||||||
// TODO: alignment, comments, etc.
|
// TODO: alignment, comments, etc.
|
||||||
for field in immut_fields {
|
for field in immut_fields {
|
||||||
mut ft := f.no_cur_mod(f.table.type_to_str_using_aliases(field.typ, f.mod2alias))
|
f.interface_field(field)
|
||||||
f.writeln('\t$field.name $ft')
|
|
||||||
f.mark_types_import_as_used(field.typ)
|
|
||||||
}
|
}
|
||||||
for method in immut_methods {
|
for method in immut_methods {
|
||||||
f.write('\t')
|
f.interface_method(method)
|
||||||
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).after('fn '))
|
|
||||||
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
|
|
||||||
f.writeln('')
|
|
||||||
f.comments(method.next_comments, inline: false, has_nl: true, level: .indent)
|
|
||||||
for param in method.params {
|
|
||||||
f.mark_types_import_as_used(param.typ)
|
|
||||||
}
|
|
||||||
f.mark_types_import_as_used(method.return_type)
|
|
||||||
}
|
}
|
||||||
if mut_fields.len + mut_methods.len > 0 {
|
if mut_fields.len + mut_methods.len > 0 {
|
||||||
f.writeln('mut:')
|
f.writeln('mut:')
|
||||||
for field in mut_fields {
|
for field in mut_fields {
|
||||||
mut ft := f.no_cur_mod(f.table.type_to_str_using_aliases(field.typ, f.mod2alias))
|
f.interface_field(field)
|
||||||
f.writeln('\t$field.name $ft')
|
|
||||||
f.mark_types_import_as_used(field.typ)
|
|
||||||
}
|
}
|
||||||
for method in mut_methods {
|
for method in mut_methods {
|
||||||
|
f.interface_method(method)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.writeln('}\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut f Fmt) interface_field(field ast.StructField) {
|
||||||
|
mut ft := f.no_cur_mod(f.table.type_to_str_using_aliases(field.typ, f.mod2alias))
|
||||||
|
end_pos := field.pos.pos + field.pos.len
|
||||||
|
before_comments := field.comments.filter(it.pos.pos < field.pos.pos)
|
||||||
|
between_comments := field.comments[before_comments.len..].filter(it.pos.pos < end_pos)
|
||||||
|
after_type_comments := field.comments[(before_comments.len + between_comments.len)..]
|
||||||
|
f.write('\t$field.name $ft')
|
||||||
|
if after_type_comments.len > 0 {
|
||||||
|
f.comments(after_type_comments, level: .indent)
|
||||||
|
} else {
|
||||||
|
f.writeln('')
|
||||||
|
}
|
||||||
|
f.mark_types_import_as_used(field.typ)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut f Fmt) interface_method(method ast.FnDecl) {
|
||||||
f.write('\t')
|
f.write('\t')
|
||||||
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).after('fn '))
|
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).after('fn '))
|
||||||
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
|
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
|
||||||
|
@ -1129,9 +1139,6 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||||
}
|
}
|
||||||
f.mark_types_import_as_used(method.return_type)
|
f.mark_types_import_as_used(method.return_type)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
f.writeln('}\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut f Fmt) mod(mod ast.Module) {
|
pub fn (mut f Fmt) mod(mod ast.Module) {
|
||||||
f.set_current_module_name(mod.name)
|
f.set_current_module_name(mod.name)
|
||||||
|
|
|
@ -29,3 +29,22 @@ interface Bar {
|
||||||
// and between
|
// and between
|
||||||
foo2() string
|
foo2() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TestsRunner {
|
||||||
|
mut:
|
||||||
|
fn_passes u64
|
||||||
|
fn_fails u64
|
||||||
|
assert_passes u64
|
||||||
|
assert_fails u64
|
||||||
|
test_fn_info &TestFnMetaInfo // filled in by generated code, before .fn_start() is called.
|
||||||
|
start(ntests int) // called before all tests, you can initialise private data here. ntests is the number of test functions in the _test.v file.
|
||||||
|
finish() // called after all tests are finished, you should free all the private data here.
|
||||||
|
//
|
||||||
|
fn_start() // called at the start of each test_ function
|
||||||
|
fn_pass() // called at the end of each test_ function, with no failed assertion
|
||||||
|
fn_error(line_nr int, file string, mod string, fn_name string, errmsg string) // called only for `fn test_xyz() ? { return error('message') }`
|
||||||
|
fn_fail() // called at the end of each test_ function, with a failed assertion, *or* returning an error
|
||||||
|
//
|
||||||
|
assert_pass(i &AssertMetaInfo) // called for each `assert true`
|
||||||
|
assert_fail(i &AssertMetaInfo) // called for each `assert false`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue