mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
compiler: fix generation of default .str() methods in interpolation
This commit is contained in:
parent
09d9dd2607
commit
d2ab9d3e77
6 changed files with 136 additions and 14 deletions
21
vlib/compiler/tests/string_interpolation_struct_test.v
Normal file
21
vlib/compiler/tests/string_interpolation_struct_test.v
Normal file
|
@ -0,0 +1,21 @@
|
|||
// This file tests whether V can generate a convenience default .str() method
|
||||
// for a custom struct, when the developer has not defined one himself.
|
||||
// The .str() methods are used for string interpolation and for println() calls.
|
||||
|
||||
struct Man {
|
||||
name string
|
||||
age int
|
||||
interests []string
|
||||
}
|
||||
|
||||
fn test_default_struct_string_interpolation(){
|
||||
superman := Man{'Superman', 30, ['flying','fighting evil','being nice']}
|
||||
s := '$superman'
|
||||
assert s.contains('Man {')
|
||||
assert s.contains('name: Superman')
|
||||
assert s.contains('age: 30')
|
||||
assert s.contains('interests: [')
|
||||
assert s.contains('"being nice"')
|
||||
assert s.contains('}')
|
||||
//println(s)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue