From 6ce363bc00933d572534c61d2c4fbfdc399ab666 Mon Sep 17 00:00:00 2001 From: xificurC Date: Fri, 7 Oct 2022 10:44:55 +0200 Subject: [PATCH] fix expected vs. actual ordering We write (+ 2 3) := 5 , but clojure.test users write (t/is (= 5 (+ 2 3))) , i.e. the expected/actual ordering is the other way around. This commit reorders the arguments to match clojure.test convention, which is important for interop with the ecosystem. E.g. matcher-combinators match? creates a diff like (mismatch (expected 2) (actual 1)) and if we don't order expected/actual correctly the error will be confusing at best. --- src/hyperfiddle/rcf/impl.clj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hyperfiddle/rcf/impl.clj b/src/hyperfiddle/rcf/impl.clj index 16eb7d1..2b96dc8 100644 --- a/src/hyperfiddle/rcf/impl.clj +++ b/src/hyperfiddle/rcf/impl.clj @@ -167,10 +167,10 @@ (loop [ss (:statements do-ast) r []] (if (>= (count ss) 3) - (let [[a b c] ss] - (if (sigil? b) - (recur (drop 3 ss) (conj r (rewrite-infix env a b c))) - (recur (rest ss) (conj r a)))) + (let [[?actual ?op ?expected] ss] + (if (sigil? ?op) + (recur (drop 3 ss) (conj r (rewrite-infix env ?expected ?op ?actual))) + (recur (rest ss) (conj r ?actual)))) (into r ss)))))) ast)) @@ -382,7 +382,7 @@ ;; (is (thrown? c expr)) ;; Asserts that evaluating expr throws an exception of class c. ;; Returns the exception thrown. - (let [[body klass] (rest form)] + (let [[klass body] (rest form)] `(try ~body (do-report {:type :hyperfiddle.rcf/fail, :message ~msg, :expected '~form, :actual nil})