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,34 @@
// This file tests whether V can generate a convenience default .str() method
// for var args of a custom type, when the developer has NOT defined one.
// Although similar to string_interpolation_struct_test.v, they should not be
// merged.
struct Man {
name string
age int
interests []string
}
fn my_variadic_function(x ...Man) string {
return '$x' // this interpolation should generate .str() methods for Man
}
fn test_vargs_string_interpolation(){
man := Man{'Me', 38, ['programming', 'reading', 'hiking']}
superman := Man{'Superman', 30, ['flying','fighting evil','being nice']}
results := my_variadic_function(superman, man)
assert results.contains('Man {')
//
assert results.contains('name: Superman')
assert results.contains('age: 30')
assert results.contains('}, Man {')
//
assert results.contains('interests: ["programming"')
assert results.contains('name: Me')
//
assert results.contains('}]')
//
println(results)
}