Jacek Laskowski
Jacek Laskowski

Reputation: 74679

How to validate refactoring in Clojure?

I found the following code in enlive:

net.cgrand.enlive-html=> (source node-selector?)
(defn node-selector? [selector]
  (not (fragment-selector? selector)))

and thought about refactoring it to the following code:

(def node-selector? (complement fragment-selector?))

How can I validate the completeness of the refactoring so all cases are properly handled with the change?

Upvotes: 1

Views: 123

Answers (1)

cgrand
cgrand

Reputation: 7949

cough tests cough and thinking hard. You have to ensure that the arguments and results domains haven't changed (special care when dealing with truthy values). In this case the change seems innocuous BUT you lose something: doc doesn't document the arglist anymore. Another subtle consequence: when you redefine fragment-selector?, node-selector? still refers to the old fragment-selector?.

Upvotes: 7

Related Questions