tests: add test for s.$method() with T.methods (#8451)
parent
c5e7956eb5
commit
9c2bd24b4f
|
@ -1,7 +1,7 @@
|
|||
struct Test {}
|
||||
|
||||
fn (test Test) v() {
|
||||
println('in v()')
|
||||
println('Test.v()')
|
||||
}
|
||||
fn (test Test) i() int {
|
||||
return 4
|
||||
|
@ -13,7 +13,7 @@ fn (test Test) s2() string {
|
|||
return 'Two'
|
||||
}
|
||||
|
||||
fn test_call() {
|
||||
fn test_string_identifier() {
|
||||
test := Test{}
|
||||
sv := 'v'
|
||||
test.$sv()
|
||||
|
@ -24,3 +24,29 @@ fn test_call() {
|
|||
rs := test.$ss()
|
||||
assert rs == 'test'
|
||||
}
|
||||
|
||||
fn test_for_methods() {
|
||||
test := Test{}
|
||||
mut r := ''
|
||||
$for method in Test.methods {
|
||||
// currently the checker thinks all $method calls return string
|
||||
$if method.return_type is string {
|
||||
//~ $if method.name == 's' {println('yes')}
|
||||
v := test.$method()
|
||||
r += v.str()
|
||||
}
|
||||
$else $if method.return_type is int {
|
||||
// TODO
|
||||
//v := test.$method()
|
||||
v := '?'
|
||||
r += v.str()
|
||||
assert method.name == 'i'
|
||||
}
|
||||
$else {
|
||||
// no return type
|
||||
test.$method()
|
||||
assert method.name == 'v'
|
||||
}
|
||||
}
|
||||
assert r == '?testTwo'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue