compiler: fix generation of default .str() methods in interpolation

This commit is contained in:
Delyan Angelov 2020-03-07 15:13:53 +02:00 committed by GitHub
parent 09d9dd2607
commit d2ab9d3e77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 14 deletions

View 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)
}