From c7a4412f8ae0edef821fa5d7e64cb200eb4a9830 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Mon, 10 Jun 2013 19:14:36 +0200 Subject: Adds skMethod example to idetools api test. --- tests/caas/idetools_api.nim | 20 ++++++++++++++++++++ tests/caas/idetools_api.txt | 3 +++ 2 files changed, 23 insertions(+) (limited to 'tests/caas') diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim index 930d26429..6327f4c22 100644 --- a/tests/caas/idetools_api.nim +++ b/tests/caas/idetools_api.nim @@ -21,3 +21,23 @@ type proc adder(a, b: int): int = result = a + b + +type + PExpr = ref object of TObject ## abstract base class for an expression + PLiteral = ref object of PExpr + x: int + PPlusExpr = ref object of PExpr + a, b: PExpr + +# watch out: 'eval' relies on dynamic binding +method eval(e: PExpr): int = + # override this base method + quit "to override!" + +method eval(e: PLiteral): int = e.x +method eval(e: PPlusExpr): int = eval(e.a) + eval(e.b) + +proc newLit(x: int): PLiteral = PLiteral(x: x) +proc newPlus(a, b: PExpr): PPlusExpr = PPlusExpr(a: a, b: b) + +echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) diff --git a/tests/caas/idetools_api.txt b/tests/caas/idetools_api.txt index eaa91cd5f..f2b513481 100644 --- a/tests/caas/idetools_api.txt +++ b/tests/caas/idetools_api.txt @@ -39,3 +39,6 @@ def\tskResult\tidetools_api.adder.result\tint # ProcRun mode will fail the next line, because the type is returned empty. def\tskField\tidetools_api.TPerson.name\tbad_string\t + +> idetools --track:idetools_api.nim,43,7 --def +def\tskMethod\tidetools_api.eval\tproc \(PPlusExpr\): int\t -- cgit 1.4.1-2-gfad0