Browse files

fix extract-method and relevant tests

  • Loading branch information...
1 parent 634d8d0 commit 54c97d0d1478eeb2dd44a0b1e65c617bf07238ca @joodie committed Nov 7, 2011
Showing with 17 additions and 13 deletions.
  1. +9 −8 src/clojure_refactoring/extract_method.clj
  2. +8 −5 test/clojure_refactoring/extract_method_test.clj
View
17 src/clojure_refactoring/extract_method.clj
@@ -1,4 +1,5 @@
;; Copyright (c) 2010 Tom Crayford,
+;; (c) 2011 Joost Diepenmaat
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
@@ -51,14 +52,14 @@
(defn- make-fn-node [name args body]
"Creates an ast representing the new function"
- (ast/list
- [(ast/symbol 'defn)
- ast/whitespace
- name
- (ast/make-node :whitespace ["\n "])
- (ast/vector args)
- (ast/make-node :whitespace ["\n "])
- body]))
+ (ast/list-without-whitespace
+ (ast/symbol 'defn)
+ ast/whitespace
+ name
+ (ast/make-node :whitespace ["\n "])
+ (ast/vector args)
+ (ast/make-node :whitespace ["\n "])
+ body))
(defn call-extracted [body toplevel extracted]
(ast/tree-replace
View
13 test/clojure_refactoring/extract_method_test.clj
@@ -38,7 +38,8 @@
(is (= (extract-method
"(defn add [s]
(let [a 1] (+ a 1)))" "(+ a 1)" "add-number")
-"(defn add-number [a]
+"(defn add-number
+ [a]
(+ a 1))
(defn add [s]
@@ -51,7 +52,8 @@
(for [x (re-split #\",\" s)] (Integer. x)))"
"(Integer. x)"
"to-i")
-"(defn to-i [x]
+"(defn to-i
+ [x]
(Integer. x))
(defn add [s]
@@ -62,7 +64,8 @@
(for [x (re-split #\",\" s)] (Integer. x)))"
"(re-split #\",\" s)"
"split-string")
-"(defn split-string [s]
+"(defn split-string
+ [s]
(re-split #\",\" s))
(defn add [s]
@@ -73,5 +76,5 @@
(is (= (extract-method
"(defn a [s] (if (.contains s \",\") 1 s))"
"(if (.contains s \",\") 1 s)"
- "b")
-"(defn b [s]\n (if (.contains s \",\") 1 s))\n\n(defn a [s] (b s))")))
+ "b")
+ "(defn b\n [s]\n (if (.contains s \",\") 1 s))\n\n(defn a [s] (b s))")))

0 comments on commit 54c97d0

Please sign in to comment.