1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: handles printing of structures and arrays of structures

This commit is contained in:
Henrixounez
2019-08-22 06:56:29 +02:00
committed by Alexander Medvednikov
parent 232532ba3b
commit 780ddaf22b
3 changed files with 50 additions and 2 deletions

View File

@ -205,4 +205,38 @@ fn test_doubling() {
nums[i] *= 2
}
assert nums.str() == '[2, 4, 6, 8, 10]'
}
}
struct Test2 {
one int
two int
}
struct Test {
a string
b []Test2
}
fn (t Test2) str() string {
return '{$t.one $t.two}'
}
fn (t Test) str() string {
return '{$t.a $t.b}'
}
fn test_struct_print() {
mut a := Test {
a: 'Test',
b: []Test2
}
b := Test2 {
one: 1,
two: 2
}
a.b << b
a.b << b
assert a.str() == '{Test [{1 2}, {1 2}] }'
assert b.str() == '{1 2}'
assert a.b.str() == '[{1 2}, {1 2}]'
}