vfmt: fix struct init; run on struct_test.v
parent
9b2511133d
commit
d5fb68e3d6
|
@ -653,7 +653,7 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
||||||
f.write('$name{}')
|
f.write('$name{}')
|
||||||
} else if it.fields.len == 0 {
|
} else if it.fields.len == 0 {
|
||||||
// `Foo{1,2,3}` (short syntax )
|
// `Foo{1,2,3}` (short syntax )
|
||||||
f.write('{')
|
f.write('$name{')
|
||||||
for i, expr in it.exprs {
|
for i, expr in it.exprs {
|
||||||
f.expr(expr)
|
f.expr(expr)
|
||||||
if i < it.exprs.len - 1 {
|
if i < it.exprs.len - 1 {
|
||||||
|
|
|
@ -32,8 +32,8 @@ fn (p mut Parser) hash() ast.HashStmt {
|
||||||
p.cur_tok_index() - 1)
|
p.cur_tok_index() - 1)
|
||||||
}
|
}
|
||||||
flag = flag.replace('@VROOT', vmod_file_location.vmod_folder )
|
flag = flag.replace('@VROOT', vmod_file_location.vmod_folder )
|
||||||
*/
|
|
||||||
flag = flag.replace('@VROOT', '/Users/alex/code/v/')
|
flag = flag.replace('@VROOT', '/Users/alex/code/v/')
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
for deprecated in ['@VMOD', '@VMODULE', '@VPATH', '@VLIB_PATH'] {
|
for deprecated in ['@VMOD', '@VMODULE', '@VPATH', '@VLIB_PATH'] {
|
||||||
if flag.contains(deprecated) {
|
if flag.contains(deprecated) {
|
||||||
|
|
|
@ -65,10 +65,7 @@ fn test_empty_struct() {
|
||||||
println(d) // != voidptr(0)
|
println(d) // != voidptr(0)
|
||||||
println('empty:')
|
println('empty:')
|
||||||
println(d2) // empty struct print
|
println(d2) // empty struct print
|
||||||
println(sizeof(
|
println(sizeof(Empty)) // == 0
|
||||||
Empty
|
|
||||||
)
|
|
||||||
) // == 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_struct_levels() {
|
fn test_struct_levels() {
|
||||||
|
@ -102,22 +99,22 @@ fn test_struct_levels() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_struct_str() {
|
fn test_struct_str() {
|
||||||
u := User{'Bob',30}
|
u := User{'Bob', 30}
|
||||||
println(u) // make sure the struct is printable
|
println(u) // make sure the struct is printable
|
||||||
// assert u.str() == '{name:"Bob", age:30}' // QTODO
|
// assert u.str() == '{name:"Bob", age:30}' // QTODO
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_at() {
|
fn test_at() {
|
||||||
foo := Foo{
|
foo := Foo{
|
||||||
typ: 'test' // QTODO @type
|
typ: 'test'
|
||||||
//type: 'test'
|
|
||||||
}
|
}
|
||||||
|
// type: 'test'
|
||||||
println(foo.typ)
|
println(foo.typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_reserved_keywords() {
|
fn test_reserved_keywords() {
|
||||||
// Make sure we can initialize them correctly using full syntax.
|
// Make sure we can initialize them correctly using full syntax.
|
||||||
rk_holder := ReservedKeywords{0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3}
|
rk_holder := ReservedKeywords{0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3}
|
||||||
// Test a few as it'll take too long to test all. If it's initialized
|
// Test a few as it'll take too long to test all. If it's initialized
|
||||||
// correctly, other fields are also probably valid.
|
// correctly, other fields are also probably valid.
|
||||||
assert rk_holder.unix == 5
|
assert rk_holder.unix == 5
|
||||||
|
@ -152,7 +149,7 @@ fn test_default_vals() {
|
||||||
d := Def{}
|
d := Def{}
|
||||||
assert d.a == 0
|
assert d.a == 0
|
||||||
assert d.b == 7
|
assert d.b == 7
|
||||||
d2 := Def{10,20}
|
d2 := Def{10, 20}
|
||||||
assert d2.a == 10
|
assert d2.a == 10
|
||||||
assert d2.b == 20
|
assert d2.b == 20
|
||||||
}
|
}
|
||||||
|
@ -202,7 +199,7 @@ pub mut:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fooo() {
|
fn fooo() {
|
||||||
a := AttrTest{1,2,3,4,5,6}
|
a := AttrTest{1, 2, 3, 4, 5, 6}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -229,7 +226,7 @@ fn test_fixed_field() {
|
||||||
*/
|
*/
|
||||||
struct Config {
|
struct Config {
|
||||||
n int
|
n int
|
||||||
def int=10
|
def int = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo_config(c Config) {
|
fn foo_config(c Config) {
|
||||||
|
@ -255,8 +252,16 @@ struct City {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Country {
|
struct Country {
|
||||||
|
name string
|
||||||
capital City
|
capital City
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_levels() {
|
fn test_levels() {
|
||||||
|
c := Country{
|
||||||
|
name: 'UK'
|
||||||
|
capital: {
|
||||||
|
name: 'London'
|
||||||
|
population: 10
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue