From ed6c765bedca0a6928cd7543b397ce5081ece1aa Mon Sep 17 00:00:00 2001 From: Owen Date: Sat, 9 Sep 2023 13:24:45 +1000 Subject: [PATCH] [Issue #20] Add tests These tests don't pass in this commit --- test/clj/com/rpl/proxy_plus_test.clj | 34 ++++++++++++++++++++++++++++ test/java/com/rpl/TestBaseClass.java | 9 ++++++++ 2 files changed, 43 insertions(+) diff --git a/test/clj/com/rpl/proxy_plus_test.clj b/test/clj/com/rpl/proxy_plus_test.clj index 9261fef..f040fbf 100644 --- a/test/clj/com/rpl/proxy_plus_test.clj +++ b/test/clj/com/rpl/proxy_plus_test.clj @@ -233,3 +233,37 @@ (foo [_this ^SuperDuperMap m] "woo") )))) ) + +(deftest hard-primative-signature-test + (testing "There are complications from Clojure's compiler. It doesn't support +functions with certain primative type hints and only supports 4 args if any +primatives are present. Check such superclass methods can still be overridden. + +Issue #20" + + (let [o + (proxy+ [] TestBaseClass + ;; Hard to test, but this is a demo of what an illegal method + ;; override does. + #_(hardSignature [this ^char b s i l bo st] 11) + + ;; Note that seeing ^long or ^double in the type signature + ;; triggers special behaviour in the Clojure compiler. + ;; This code would work without those hints, but the test + ;; would not be thorough. + ^int (hardSignature [this ^byte b ^short s ^int i ^long l ^boolean bo ^String st] 12) + ^Integer (hardSignature [this ^java.lang.Byte b ^Short s ^Integer i ^Long l ^Boolean bo ^String st] (.intValue 13)))] + (is (= 12 (.hardSignature o + ^byte (.byteValue 1) + ^short (.shortValue 1) + ^int (.intValue 1) + ^long (identity 1) + ^boolean (identity true) + "Two"))) + (is (= 13 (.hardSignature o + ^Byte (.byteValue 1) + ^Short (.shortValue 1) + ^Integer (.intValue 1) + ^Long (identity 1) + ^Boolean (identity true) + "Two")))))) diff --git a/test/java/com/rpl/TestBaseClass.java b/test/java/com/rpl/TestBaseClass.java index 8c67b90..ffb327b 100644 --- a/test/java/com/rpl/TestBaseClass.java +++ b/test/java/com/rpl/TestBaseClass.java @@ -30,4 +30,13 @@ public String doSomething(char c, long l, short s, double d) { throw new RuntimeException(); } + // Having many arguments is significant; Clojure only supports 4 args when + // primative hints are present. See https://clojure.org/reference/java_interop + public int hardSignature(byte b, short s, int i, long l, boolean bo, String st){ + return 1; + } + + public Integer hardSignature(Byte b, Short s, Integer i, Long l, Boolean bo, String st){ + return 2; + } }