Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Renamed things in destructuring.

  • Loading branch information...
commit 4d87dfc1ffc0c2d3516a6af0405493930086c18f 1 parent d18914b
@tcrayford tcrayford authored
View
2  TODO.markdown
@@ -8,7 +8,7 @@ Fix multiple defn bodies problem (map over defn bodies)
Watch files for reloading (using something like lazytest's watcher)
-0.5
+0.5 DONE
---
Rename not to rename shadowed var names.
View
18 src/clojure_refactoring/destructuring.clj
@@ -6,22 +6,22 @@
[clojure-refactoring.ast :only [defparsed-fn]])
(:require [clojure-refactoring.ast :as ast]))
-(defn parsley-map-lookup? [ast]
+(defn map-lookup? [ast]
(let [content (ast/relevant-content ast)]
(and (ast/tag= :list ast)
(count= (filter ast/keyword? content) 1)
(count= content 2))))
-(defn parsley-key->sym [kw-node]
+(defn key->sym [kw-node]
(ast/replace-content kw-node
(list
(str-join ""
(drop 1 (first (:content kw-node)))))))
-(defn parsley-find-lookups [node]
+(defn find-lookups [node]
"Returns all the map lookups in a node as a set of parsley asts"
(->> (ast/sub-nodes node)
- (filter parsley-map-lookup?)
+ (filter map-lookup?)
set))
(defn- swap-first-with-last [ast]
@@ -34,7 +34,7 @@
(ast/replace-content ast
(swap-first-with-last ast)))
-(defn parsley-lookup-to-canoninical-form [lookup-ast]
+(defn lookup->canoninical-form [lookup-ast]
(let [[maybe-keyword] (ast/relevant-content lookup-ast)]
(if (ast/keyword? maybe-keyword)
lookup-ast
@@ -52,7 +52,7 @@
~@(drop 1 (:content m)))))
(def relevant-content-from-canoninical-form
- (comp ast/relevant-content parsley-lookup-to-canoninical-form))
+ (comp ast/relevant-content lookup->canoninical-form))
(defn- add-lookup-to-binding-map [binding-map lookup]
"Adds a lookup (a node of the form (:a a)) to a binding map."
@@ -60,7 +60,7 @@
(assoc binding-map m
(add-to-parsley-map
(get binding-map m ast/empty-map)
- (parsley-key->sym key) key))))
+ (key->sym key) key))))
(defn lookups-to-binding-map [lookups]
"Turns a set of lookups to a map of map-symbols to lookups"
@@ -80,7 +80,7 @@
(fn [new-ast lookup]
(ast/tree-replace
lookup
- (parsley-key->sym (first (ast/relevant-content (parsley-lookup-to-canoninical-form lookup))))
+ (key->sym (first (ast/relevant-content (lookup->canoninical-form lookup))))
new-ast))
ast
lookups))
@@ -92,7 +92,7 @@
(defparsed-fn destructure-map [root-ast]
"Destructures all calls to maps"
- (let [lookups (parsley-find-lookups root-ast)]
+ (let [lookups (find-lookups root-ast)]
(ast/ast->string
(replace-lookups-with-destructured-symbols
lookups
View
12 test/clojure_refactoring/destructuring_test.clj
@@ -12,27 +12,27 @@
(deftest parsley_map_lookup
(testing "map lookups"
- (are [s] (parsley-map-lookup? (first (parser/parse s)))
+ (are [s] (map-lookup? (first (parser/parse s)))
"(:a a)"
"(b :foo)"))
- (are [s] (not (parsley-map-lookup? (first (parser/parse s))))
+ (are [s] (not (map-lookup? (first (parser/parse s))))
"(a (:a a))"
"(:a a a)"
"(:foo :bar)"
"(:foo a :bar b)"))
(deftest parsley_key_to_sym
- (is (= (parsley-key->sym '{:tag :atom :content (":a")})
+ (is (= (key->sym '{:tag :atom :content (":a")})
'{:tag :atom :content ("a")})))
(deftest parsley_find_map_lookups
(is (= (map ast/ast->string
- (parsley-find-lookups (parser/parse "(defn a [b] (:a b))")))
+ (find-lookups (parser/parse "(defn a [b] (:a b))")))
'("(:a b)"))))
(deftest parsley_lookup_to_proper_form
- (is (= (ast/ast->string (parsley-lookup-to-canoninical-form
+ (is (= (ast/ast->string (lookup->canoninical-form
(first (parser/parse "(a :a)"))))
"(:a a)")))
@@ -43,7 +43,7 @@
'{:tag :atom :content ("b")})))))
(deftest parsley_lookups_to_binding_map
- (is ((lookups-to-binding-map (parsley-find-lookups (parser/parse "(defn a [b] (:a b))")))
+ (is ((lookups-to-binding-map (find-lookups (parser/parse "(defn a [b] (:a b))")))
'{:tag :atom :content ("b")})))
;;Integration level tests below here.
Please sign in to comment.
Something went wrong with that request. Please try again.