From d5bab726200dca5ddc59ccccd6af76faaf4ea012 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 7 Jan 2019 14:54:39 -0500 Subject: [PATCH] Add a test for making method calls --- test/suite3.janet | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/suite3.janet b/test/suite3.janet index f53a1538..963ec251 100644 --- a/test/suite3.janet +++ b/test/suite3.janet @@ -106,10 +106,20 @@ # Calling non functions (assert (= 1 ({:ok 1} :ok)) "calling struct") -(assert (= 1 (:ok {:ok 1})) "calling keyword") (assert (= 2 (@{:ok 2} :ok)) "calling table") (assert (= :bad (try (@{:ok 2} :ok :no) ([err] :bad))) "calling table too many arguments") (assert (= :bad (try (:ok @{:ok 2} :no) ([err] :bad))) "calling keyword too many arguments") (assert (= :oops (try (1 1) ([err] :oops))) "calling number fails") +# Method test + +(def Dog @{:bark (fn bark [self what] (string (self :name) " says " what "!"))}) +(defn make-dog + [name] + (table/setproto @{:name name} Dog)) + +(assert (= "fido" ((make-dog "fido") :name)) "oo 1") +(def spot (make-dog "spot")) +(assert (= "spot says hi!" (:bark spot "hi")) "oo 2") + (end-suite)