mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +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
34
vlib/compiler/tests/string_interpolation_variadic_test.v
Normal file
34
vlib/compiler/tests/string_interpolation_variadic_test.v
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue