Permalink
Browse files

Parse code formatting.

  • Loading branch information...
1 parent 69f69e9 commit f660a42ecd29515151bfbd75306f5914a53f5ed4 @mmcgrana mmcgrana committed Mar 7, 2010
Showing with 54 additions and 67 deletions.
  1. +23 −33 src/clj/cascading/clojure/parse.clj
  2. +31 −34 test/cascading/clojure/parse_test.clj
View
56 src/clj/cascading/clojure/parse.clj
@@ -49,37 +49,27 @@
(first (find-first #(pred (last %)) (indexed aseq))))
(defn parse-args
- "
- arr => func-spec in-fields? :fn> func-fields :> out-fields
-
- returns [in-fields func-fields spec out-fields]
- "
- ([arr] (parse-args arr Fields/RESULTS))
+ "arr => [func-spec in-fields? :fn> func-fields :> out-fields]
+ Returns [in-fields func-fields spec out-fields]"
+ ([arr]
+ (parse-args arr Fields/RESULTS))
([arr defaultout]
- (let
- [func-args (first arr)
- varargs (rest arr)
- spec (fn-spec func-args)
- func-var (if (var? func-args)
- func-args
- (first func-args))
- defaults {:fn> (or
- (:fields (meta func-var))
- Fields/ARGS)
- :fn spec
- :> defaultout}
- first-elem (first varargs)
- keyargs (if (or (nil? first-elem)
- (keyword? first-elem))
- (apply hash-map
- (concat [:in Fields/ALL]
- varargs))
- (apply hash-map
- (concat [:in (first varargs)]
- (rest varargs))))
- options (merge defaults keyargs)
- fieldsized (into {} (for [[k v] options]
- (if (= k :fn)
- [k v]
- [k (fields v)])))]
- (vals fieldsized))))
+ (let [func-args (first arr)
+ varargs (rest arr)
+ spec (fn-spec func-args)
+ func-var (if (var? func-args)
+ func-args
+ (first func-args))
+ defaults {:fn> (or (:fields (meta func-var)) Fields/ARGS)
+ :fn spec
+ :> defaultout}
+ first-elem (first varargs)
+ keyargs (if (or (nil? first-elem) (keyword? first-elem))
+ (apply hash-map (concat [:in Fields/ALL] varargs))
+ (apply hash-map (concat [:in (first varargs)] (rest varargs))))
+ options (merge defaults keyargs)
+ fieldsized (into {} (for [[k v] options]
+ (if (= k :fn)
+ [k v]
+ [k (fields v)])))]
+ (vals fieldsized))))
View
65 test/cascading/clojure/parse_test.clj
@@ -1,56 +1,53 @@
(ns cascading.clojure.parse-test
- (:use clojure.test)
- (:import (cascading.tuple Fields))
- (:use [cascading.clojure parse testing]))
+ (:use clojure.test
+ (cascading.clojure parse testing))
+ (:import cascading.tuple.Fields))
(defn example [x] x)
(def obj-array-class (class (into-array Object [])))
-(defn extract-obj-array [x]
+(defn extract-obj-array [parse-results]
(map (fn [e]
- (if (instance? obj-array-class e)
- (seq e)
- e))
- x))
+ (if (instance? obj-array-class e) (seq e) e))
+ parse-results))
(deftest parse-everything
(is (= [(fields ["foo"])
- (fields ["bar"])
- ["cascading.clojure.parse-test" "example"]
- (fields ["baz"])]
- (extract-obj-array
- (parse-args [#'example "foo" :fn> "bar" :> "baz"])))))
+ (fields ["bar"])
+ ["cascading.clojure.parse-test" "example"]
+ (fields ["baz"])]
+ (extract-obj-array
+ (parse-args [#'example "foo" :fn> "bar" :> "baz"])))))
(deftest parse-everything-multiple-ins
(is (= [(fields ["foo" "bat"])
- (fields ["bar"])
- ["cascading.clojure.parse-test" "example"]
- (fields ["baz"])]
- (extract-obj-array
- (parse-args [#'example ["foo" "bat"]
- :fn> "bar" :> "baz"])))))
+ (fields ["bar"])
+ ["cascading.clojure.parse-test" "example"]
+ (fields ["baz"])]
+ (extract-obj-array
+ (parse-args [#'example ["foo" "bat"] :fn> "bar" :> "baz"])))))
(deftest parse-no-input-selectors
(is (= [Fields/ALL
- (fields ["bar"])
- ["cascading.clojure.parse-test" "example"]
- (fields ["baz"])]
- (extract-obj-array
- (parse-args [#'example :fn> "bar" :> "baz"])))))
+ (fields ["bar"])
+ ["cascading.clojure.parse-test" "example"]
+ (fields ["baz"])]
+ (extract-obj-array
+ (parse-args [#'example :fn> "bar" :> "baz"])))))
(deftest parse-no-input-or-output-selectors
(is (= [Fields/ALL
- (fields ["bar"])
- ["cascading.clojure.parse-test" "example"]
- Fields/RESULTS]
- (extract-obj-array
- (parse-args [#'example :fn> "bar"])))))
+ (fields ["bar"])
+ ["cascading.clojure.parse-test" "example"]
+ Fields/RESULTS]
+ (extract-obj-array
+ (parse-args [#'example :fn> "bar"])))))
(deftest parse-no-input-or-output-or-fn-selectors
(is (= [Fields/ALL
- Fields/ARGS
- ["cascading.clojure.parse-test" "example"]
- Fields/RESULTS]
- (extract-obj-array
- (parse-args [#'example])))))
+ Fields/ARGS
+ ["cascading.clojure.parse-test" "example"]
+ Fields/RESULTS]
+ (extract-obj-array
+ (parse-args [#'example])))))

0 comments on commit f660a42

Please sign in to comment.