Skip to content
Browse files

formatting

  • Loading branch information...
1 parent f076308 commit f8492e09493aa13623f0a705f1447d1e59ac16b8 @swannodette swannodette committed May 5, 2013
Showing with 148 additions and 148 deletions.
  1. +5 −5 src/main/clojure/clojure/core/match.clj
  2. +143 −143 src/test/clojure/clojure/core/match/test/core.clj
View
10 src/main/clojure/clojure/core/match.clj
@@ -32,8 +32,8 @@
(comment
(match [x y]
- [1 2] :a0
- [3 4] :a1))
+ [1 2] :a0
+ [3 4] :a1))
;; ============================================
;; # Debugging tools
@@ -1759,9 +1759,9 @@
Example:
(let [x 1
y 2]
- (match [x y 3]
- [1 2 3] :answer1
- :else :default-answer))"
+ (match [x y 3]
+ [1 2 3] :answer1
+ :else :default-answer))"
[vars & clauses]
(let [[vars clauses] (if (vector? vars)
[vars clauses]
View
286 src/test/clojure/clojure/core/match/test/core.clj
@@ -15,7 +15,7 @@
[_ _ false] 3
[_ _ true] 4
:else 5))
- 4)))
+ 4)))
(deftest pattern-match-recur-1
(is (= ((fn [x y z done]
@@ -27,23 +27,23 @@
[_ _ true] (recur x y z 4)
:else 5)
done)) true true true false)
- 4)))
+ 4)))
(deftest pattern-match-bind-1
(is (= (let [x 1 y 2 z 4]
(match [x y z]
[1 2 b] [:a0 b]
[a 2 4] [:a1 a]
:else []))
- [:a0 4])))
+ [:a0 4])))
(deftest seq-pattern-match-1
(is (= (let [x [1]]
(match [x]
[1] 1
[([1] :seq)] 2
:else []))
- 2)))
+ 2)))
(deftest seq-pattern-match-2
(is (= (let [x [1 2 nil nil nil]]
@@ -52,7 +52,7 @@
[([1 2] :seq)] :a1
[([1 2 nil nil nil] :seq)] :a2
:else []))
- :a2)))
+ :a2)))
(deftest seq-pattern-match-bind-1
(is (= (let [x '(1 2 4)
@@ -62,7 +62,7 @@
[([1 2 b] :seq) _ _] [:a0 b]
[([a 2 4] :seq) _ _] [:a1 a]
:else []))
- [:a0 4])))
+ [:a0 4])))
(deftest seq-pattern-match-wildcard-row
(is (= (let [x '(1 2 3)]
@@ -79,7 +79,7 @@
[{:a 1 :b 1}] :a1
[{:c 3 :d _ :e 4}] :a2
:else []))
- :a1)))
+ :a1)))
(deftest map-pattern-match-2
(is (= (let [x {:a 1 :b 1}]
@@ -88,7 +88,7 @@
[{:a 1 :b _}] :a1
[{:c 3 :d _ :e 4}] :a2
:else []))
- :a0)))
+ :a0)))
(deftest map-pattern-match-3
(is (= (let [x {:a 1 :b 1 :c 1}]
@@ -97,7 +97,7 @@
[{:a 1 :b _}] :a1
[{:c 3 :d _ :e 4}] :a2
:else []))
- :a1)))
+ :a1)))
(deftest map-pattern-match-4
(is (= (let [x {:a 1 :b 1}]
@@ -106,7 +106,7 @@
[{:a _ :b _}] :a1
[{:c 3 :d _ :e 4}] :a2
:else []))
- :a1)))
+ :a1)))
(deftest map-pattern-match-5
(is (= (let [x {:a 1}]
@@ -115,7 +115,7 @@
[{:a _ :b _}] :a1
[{:c 3 :d _ :e 4}] :a2
:else []))
- [])))
+ [])))
(deftest map-pattern-match-6
(is (= (let [x {:a 1 :b 1}]
@@ -124,7 +124,7 @@
[{:a _ :b _}] :a1
[{:a _ :b _}] :a2
:else []))
- :a0)))
+ :a0)))
(deftest map-pattern-match-7
(is (= (let [x {:a 1 :b 1}]
@@ -133,7 +133,7 @@
[{:a _ :b _}] :a1
[{:a 1 :b 1}] :a2
:else []))
- :a0)))
+ :a0)))
(deftest map-pattern-match-8
(is (= (let [x {:a 1 :b 1}]
@@ -142,47 +142,47 @@
[{:a _ :b _}] :a1
[{:a 1 :b 1}] :a2
:else []))
- :a1)))
+ :a1)))
(deftest map-pattern-match-only-1
(is (= (let [x {:a 1 :b 2}]
(match [x]
- [({:a _ :b 2} :only [:a :b])] :a0
- [{:a 1 :c _}] :a1
- [{:c 3 :d _ :e 4}] :a2
- :else []))
- :a0))
+ [({:a _ :b 2} :only [:a :b])] :a0
+ [{:a 1 :c _}] :a1
+ [{:c 3 :d _ :e 4}] :a2
+ :else []))
+ :a0))
(is (= (let [x {:a 1 :b 2 :c 3}]
(match [x]
- [({:a _ :b 2} :only [:a :b])] :a0
- [{:a 1 :c _}] :a1
- [{:c 3 :d _ :e 4}] :a2
- :else []))
- :a1)))
+ [({:a _ :b 2} :only [:a :b])] :a0
+ [{:a 1 :c _}] :a1
+ [{:c 3 :d _ :e 4}] :a2
+ :else []))
+ :a1)))
(deftest map-pattern-match-bind-1
(is (= (let [x {:a 1 :b 2}]
(match [x]
[{:a a :b b}] [:a0 a b]
:else []))
- [:a0 1 2])))
+ [:a0 1 2])))
(deftest seq-pattern-match-empty-1
(is (= (let [x '()]
(match [x]
[([] :seq)] :a0
[([1 & r] :seq)] [:a1 r]
:else []))
- :a0)))
+ :a0)))
(deftest seq-pattern-match-rest-1
(is (= (let [x '(1 2)]
(match [x]
[([1] :seq)] :a0
[([1 & r] :seq)] [:a1 r]
:else []))
- [:a1 '(2)])))
+ [:a1 '(2)])))
;; FIXME: stack overflow if vector pattern - David
@@ -192,15 +192,15 @@
[([1] :seq)] :a0
[([_ 2 & ([a & b] :seq)] :seq)] [:a1 a b]
:else []))
- [:a1 3 '(4)])))
+ [:a1 3 '(4)])))
(deftest or-pattern-match-1
(is (= (let [x 4 y 6 z 9]
(match [x y z]
[(:or 1 2 3) _ _] :a0
[4 (:or 5 6 7) _] :a1
:else []))
- :a1)))
+ :a1)))
(deftest or-pattern-match-seq-1
(is (= (let [x '(1 2 3)
@@ -210,7 +210,7 @@
[([1 (:or 3 4) 3] :seq) _ _] :a0
[([1 (:or 2 3) 3] :seq) _ _] :a1
:else []))
- :a1)))
+ :a1)))
(deftest or-pattern-match-map-2
(is (= (let [x {:a 3}
@@ -220,10 +220,10 @@
[{:a (:or 1 2)} _ _] :a0
[{:a (:or 3 4)} _ _] :a1
:else []))
- :a1)))
+ :a1)))
(defn div3? [n]
- (= (mod n 3) 0))
+ (= (mod n 3) 0))
(defpred even?)
(defpred odd?)
@@ -235,7 +235,7 @@
[([_ (a :when even?) _ _] :seq)] :a0
[([_ (b :when [odd? div3?]) _ _] :seq)] :a1
:else []))
- :a1)))
+ :a1)))
;; like guard-pattern-match-1 but uses 'flattened' syntax for guard
(deftest guard-pattern-match-2
@@ -244,7 +244,7 @@
[([_ a :when even? _ _] :seq)] :a0
[([_ b :when [odd? div3?] _ _] :seq)] :a1
:else []))
- :a1)))
+ :a1)))
;; uses 'flattened' syntax for guard
(deftest guard-pattern-match-3
@@ -253,45 +253,45 @@
[a :when even? _ [b c] :as d] (+ (first d) c)
[_ b :when [odd? div3?] _] :a1
:else []))
- 9)))
+ 9)))
(deftest guard-pattern-match-4
(is (= (match [1 2]
[(a :guard #(odd? %)) (b :when odd?)] :a1
- [(a :guard #(odd? %)) _] :a2
- [_ (b :when even?)] :a3
- :else :a4)
- :a2)))
+ [(a :guard #(odd? %)) _] :a2
+ [_ (b :when even?)] :a3
+ :else :a4)
+ :a2)))
(deftest guard-pattern-match-5
(is (=
- (let [oddp odd?]
- (match [1 2]
- [a :guard odd? b :when odd?] :a1
- [a :guard oddp _] :a2
- [_ b :when even?] :a3
- :else :a4))
- :a2)))
+ (let [oddp odd?]
+ (match [1 2]
+ [a :guard odd? b :when odd?] :a1
+ [a :guard oddp _] :a2
+ [_ b :when even?] :a3
+ :else :a4))
+ :a2)))
(deftest unequal-equal-tests
(is (=
- (match ["foo" "bar"]
- [#".*" #"baz"] :a1
- [#"foo" _] :a2
- [_ "bar"] :a3
- :else :a4)
- :a2)))
+ (match ["foo" "bar"]
+ [#".*" #"baz"] :a1
+ [#"foo" _] :a2
+ [_ "bar"] :a3
+ :else :a4)
+ :a2)))
(deftest unequal-equal-tests-2
(is (=
- (let [a 1 b 1]
- (match [1 2]
- [a 3] :a1
- [1 2] :a2
- [2 _] :a5
- [_ 3] :a4
- :else :a3))
- :a2)))
+ (let [a 1 b 1]
+ (match [1 2]
+ [a 3] :a1
+ [1 2] :a2
+ [2 _] :a5
+ [_ 3] :a4
+ :else :a3))
+ :a2)))
;; use ':when pattern to match literal :when (as opposed to guard syntax)
(deftest literal-when-match-1
@@ -300,35 +300,35 @@
[a ':when 1] :success
[:as _ 2] :fail
:else :fail))
- :success)))
+ :success)))
(deftest same-symbol-using-guards
(is (= (let [e '(+ 1 (+ 2 3))
op (first e)
op? #(= % op)]
(match [e]
- [([p :guard op? x ([p2 :guard op? y z] :seq)] :seq)] (list p x y z)))
- '(+ 1 2 3))))
+ [([p :guard op? x ([p2 :guard op? y z] :seq)] :seq)] (list p x y z)))
+ '(+ 1 2 3))))
(deftest quoted-symbol
(is (= (let [e '(+ 1 (+ 2 3))]
(match [e]
- [(['+ x (['+ y z] :seq)] :seq)] (list '+ x y z)))
- '(+ 1 2 3))))
+ [(['+ x (['+ y z] :seq)] :seq)] (list '+ x y z)))
+ '(+ 1 2 3))))
(deftest literal-quote
(is (= (let [e 'quote
f 10]
(match [e f]
- ['quote quote] quote))
- 10)))
+ ['quote quote] quote))
+ 10)))
(deftest literal-quote-seq
(is (= (let [e '(:a (quote 10))]
(match [e]
- [([quote (['quote 10] :seq)] :seq)] quote))
- :a)))
+ [([quote (['quote 10] :seq)] :seq)] quote))
+ :a)))
@@ -349,84 +349,84 @@
[{:year 2009 :month a}] [:a0 a]
[{:year (:or 2010 2011) :month b}] [:a1 b]
:else []))
- [:a1 10])))
+ [:a1 10])))
(deftest map-pattern-ocr-order-1
(is (= (let [v [{:a 1} 2]]
(match [v]
[[{:a 2} 2]] :a0
[[{:a _} 2]] :a1
:else []))
- :a1)))
+ :a1)))
(deftest as-pattern-match-1
(is (= (let [v [[1 2]]]
(match [v]
[([3 1] :seq)] :a0
[([(([1 a] :seq) :as b)] :seq)] [:a1 a b]
:else []))
- [:a1 2 [1 2]])))
+ [:a1 2 [1 2]])))
(deftest else-clause-1
(is (= (let [v [1]]
(match [v]
- [2] 1
- :else 21))
- 21)))
+ [2] 1
+ :else 21))
+ 21)))
(deftest else-clause-seq-pattern-1
(is (= (let [v [[1 2]]]
(match [v]
- [([1 3] :seq)] 1
- :else 21))
- 21)))
+ [([1 3] :seq)] 1
+ :else 21))
+ 21)))
(deftest else-clause-map-pattern-1
(is (= (let [v {:a 1}]
(match [v]
- [{:a a}] 1
- :else 21))
- 1)))
+ [{:a a}] 1
+ :else 21))
+ 1)))
(deftest else-clause-guard-pattern-1
(is (= (let [v 1]
(match [v]
- [(_ :when even?)] 1
- :else 21))
- 21)))
+ [(_ :when even?)] 1
+ :else 21))
+ 21)))
(deftest else-clause-or-pattern-1
(is (= (let [v 3]
(match [v]
- [(:or 1 2)] :a0
- :else :a1))
- :a1)))
+ [(:or 1 2)] :a0
+ :else :a1))
+ :a1)))
(deftest match-expr-1
(is (= (->> (range 1 16)
- (map (fn [x]
- (match [(mod x 3) (mod x 5)]
- [0 0] "FizzBuzz"
- [0 _] "Fizz"
- [_ 0] "Buzz"
- :else (str x)))))
- '("1" "2" "Fizz" "4" "Buzz" "Fizz" "7" "8" "Fizz" "Buzz" "11" "Fizz" "13" "14" "FizzBuzz"))))
+ (map (fn [x]
+ (match [(mod x 3) (mod x 5)]
+ [0 0] "FizzBuzz"
+ [0 _] "Fizz"
+ [_ 0] "Buzz"
+ :else (str x)))))
+ '("1" "2" "Fizz" "4" "Buzz" "Fizz" "7" "8" "Fizz" "Buzz" "11" "Fizz" "13" "14" "FizzBuzz"))))
(deftest match-single-1
(is (= (let [x 3]
(match x
1 :a0
2 :a1
:else :a2))
- :a2)))
+ :a2)))
(deftest match-single-2
(is (= (let [x 3]
(match (mod x 2)
1 :a0
2 :a1
:else :a2))
- :a0)))
+ :a0)))
;; TODO: this needs to wait for backtracking. GuardPatterns need to be grouped w/
;; whatever pattern they actually contain - David
@@ -437,7 +437,7 @@
[2 1] :a0
(_ :when #(= (count %) 2)) :a1
:else :a2))
- :a1)))
+ :a1)))
)
(deftest match-local-1
@@ -448,7 +448,7 @@
[1] :a1
[y] :a2
:else :a3))
- :a2)))
+ :a2)))
(deftest match-local-2
(is (= (let [x 2]
@@ -457,35 +457,35 @@
[1] :a1
[2] :a2
:else :a3))
- :a2)))
+ :a2)))
(deftest match-local-3
(is (= (let [a 1]
(match [1 2]
[1 3] :a0
[a 2] :a1
:else :a2))
- :a1)))
+ :a1)))
(deftest basic-regex
- (is (= (match ["asdf"]
- [#"asdf"] 1
- :else 2)
- 1)))
+ (is (= (match ["asdf"]
+ [#"asdf"] 1
+ :else 2)
+ 1)))
(deftest test-false-expr-works-1
(is (= (match [true false]
[true false] 1
[false true] 2
:else (throw (Exception. "Shouldn't be here")))
- 1)))
+ 1)))
(deftest test-lazy-source-case-1
(is (= (let [x [1 2]]
(match [x]
- [(:or [1 2] [3 4] [5 6] [7 8] [9 10])] :a0
- :else (throw (Exception. "Shouldn't be here"))))
- :a0)))
+ [(:or [1 2] [3 4] [5 6] [7 8] [9 10])] :a0
+ :else (throw (Exception. "Shouldn't be here"))))
+ :a0)))
(deftest test-wildcard-local-1
(is (= (let [_ 1
@@ -496,7 +496,7 @@
[_ 2] :a1
[2 3] :a2
:else :a3))
- :a2)))
+ :a2)))
(deftest vector-pattern-match-1
(is (= (let [x [1 2 3]]
@@ -505,7 +505,7 @@
[([1 1 3] ::clojure.core.match/vector)] :a1
[([1 2 3] ::clojure.core.match/vector)] :a2
:else :a3))
- :a2)))
+ :a2)))
(deftest red-black-tree-pattern-1
(is (= (let [n [:black [:red [:red 1 2 3] 3 4] 5 6]]
@@ -515,7 +515,7 @@
[:black a x [:red [:red b y c] z d]]
[:black a x [:red b y [:red c z d]]])] :balance
:else :valid))
- :balance)))
+ :balance)))
(deftest vector-pattern-rest-1
(is (= (let [v [1 2 3 4]]
@@ -524,7 +524,7 @@
[([1 2 4 & r] ::clojure.core.match/vector)] :a1
[([1 2 3 & r] ::clojure.core.match/vector)] :a2
:else :a3))
- :a2)))
+ :a2)))
(deftest vector-pattern-rest-2
(is (= (let [v [1 2 3 4]]
@@ -533,64 +533,64 @@
[([1 1 3 & r] ::clojure.core.match/vector)] :a0
[([1 2 & r] ::clojure.core.match/vector)] :a1
:else :a3)))
- :a1)))
+ :a1)))
(deftest vector-bind-1
(is (= (let [node 1]
(match [node]
[[1]] :a0
[a] a
:else :a1))
- 1)))
+ 1)))
(deftest empty-vector-1
(is (= (let [v []]
(match [v]
[[]] 1
:else 2))
- 1)))
+ 1)))
(deftest empty-vector-2
(is (= (let [v [1 2]]
(match [v]
[[]] :a0
[[x & r]] :a1
:else :a2))
- :a1)))
+ :a1)))
(deftest vector-pattern-length-1
(is (= (let [v [[1 2]]]
(match [v]
[[3 1]] :a0
[[([1 a] :as b)]] [:a1 a b]
:else :a2))
- [:a1 2 [1 2]])))
+ [:a1 2 [1 2]])))
(deftest seq-infer-rest-1
(is (= (let [l '(1 2 3)]
- (match [l]
- [([a & [b & [c]]] :seq)] :a0
- :else :a1))
- :a0)))
+ (match [l]
+ [([a & [b & [c]]] :seq)] :a0
+ :else :a1))
+ :a0)))
(deftest vector-offset-1
(is (= (match [[:pow :x 2]]
[[:pow arg pow]] 0
[[:mult & args]] 1
:else 2)
- 0)))
+ 0)))
(deftest match-expr-2
(is (= (match [false]
[false] true)
- true)))
+ true)))
(deftest vector-rest-pattern-1
(is (= (match [[:plus 1 2 3]]
[[:pow arg pow]] 0
[[:plus & args]] 1
:else 2))
- 1))
+ 1))
(deftest map-pattern-match-only-2
(is (= (let [x {:a 1 :b 2 :c 10 :d 30}]
@@ -600,33 +600,33 @@
[{:a 1 :c _}] :a1
[{:c 3 :d _ :e 4}] :a2
:else []))
- :a-1)))
+ :a-1)))
(deftest map-pattern-match-only-3
(is (and (= (let [m {:a 1}]
(match [m]
[({:a 1} :only [:a])] :a0
:else :a1))
- :a0)
- (= (let [m {:a 1 :b 2}]
- (match [m]
- [({:a 1} :only [:a])] :a0
- :else :a1))
- :a1))))
+ :a0)
+ (= (let [m {:a 1 :b 2}]
+ (match [m]
+ [({:a 1} :only [:a])] :a0
+ :else :a1))
+ :a1))))
(deftest map-pattern-heterogenous-keys-1
(is (= (let [m {:foo 1 "bar" 2}]
(match [m]
[{:foo 1 "bar" 2}] :a0
:else :a1))
- :a0)))
+ :a0)))
(deftest exception-1
(is (= (try
(match :a :a (throw (Exception.)) :else :c)
(catch Exception e
:d))
- :d)))
+ :d)))
(deftest match-order-1
(is (= (let [x '(1 2) y 1]
@@ -636,7 +636,7 @@
[([1 2] :seq) _] :a2
[_ 2] :a3
:else :a4))
- :a1)))
+ :a1)))
(deftest match-order-2
(is (= (let [x '(1 2) y 3]
@@ -646,7 +646,7 @@
[([1 2] :seq) _] :a2
[_ 2] :a3
:else :a4))
- :a2)))
+ :a2)))
(deftest match-order-3
(is (= (let [x '(1) y 3]
@@ -656,7 +656,7 @@
[([1 2] :seq) _] :a2
[_ 2] :a3
:else :a4))
- :a0)))
+ :a0)))
(deftest match-order-4
(is (= (let [x '(1 2 3) y 2]
@@ -666,7 +666,7 @@
[([1 2] :seq) _] :a2
[_ 2] :a3
:else :a4))
- :a3)))
+ :a3)))
(deftest match-order-5
(is (= (match [["foo"]]
@@ -675,16 +675,16 @@
[["baz"]] :a2
[["baz" a b]] :a3
:else :a4)
- :a0)))
+ :a0)))
(deftest match-order-6
- (is (= (match [[2]]
+ (is (= (match [[2]]
[[1]] :a0
[1] :a1
[[2]] :a2
[2] :a3
:else :a4)
- :a2)))
+ :a2)))
(deftest match-order-6-recur
(is (= ((fn [x done]
@@ -696,16 +696,16 @@
[[2]] (recur x :a2)
[2] (recur x :a3)
:else :a4))) [2] false)
- :a2)))
+ :a2)))
(deftest match-order-7
- (is (= (match [[2]]
+ (is (= (match [[2]]
[1] :a0
[[1]] :a1
[2] :a2
[[2]] :a3
:else :a4)
- :a3)))
+ :a3)))
(deftest match-order-8
(is (= (let [xs [:c]]

0 comments on commit f8492e0

Please sign in to comment.
Something went wrong with that request. Please try again.