tests: add test for s.$method() with T.methods (#8451)

pull/8457/head
Nick Treleaven 2021-01-30 17:35:41 +00:00 committed by GitHub
parent c5e7956eb5
commit 9c2bd24b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 2 deletions

View File

@ -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'
}