From 9c2bd24b4f1ab3242779ac8060c5799941e38cda Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 30 Jan 2021 17:35:41 +0000 Subject: [PATCH] tests: add test for s.$method() with T.methods (#8451) --- vlib/v/tests/comptime_call_test.v | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/vlib/v/tests/comptime_call_test.v b/vlib/v/tests/comptime_call_test.v index 6ad96e6797..9ca461c9de 100644 --- a/vlib/v/tests/comptime_call_test.v +++ b/vlib/v/tests/comptime_call_test.v @@ -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' +}