Skip to content

Commit

Permalink
Merge pull request #40 from duelinmarkers/test-coverage-for-rules
Browse files Browse the repository at this point in the history
Test coverage for rules
  • Loading branch information
jonase committed Jun 11, 2012
2 parents 75b4091 + d7dc246 commit af21ab3
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 12 deletions.
12 changes: 12 additions & 0 deletions test/kibit/test/arithmetic.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns kibit.test.arithmetic
(:require [kibit.check :as kibit])
(:use [clojure.test]))

(deftest arithmetic-are
(are [expected-alt-form test-form]
(= expected-alt-form (:alt (kibit/check-expr test-form)))
'(inc num) '(+ num 1)
'(inc num) '(+ 1 num)
'(dec num) '(- num 1)
'(* x y z) '(* x (* y z))
'(+ x y z) '(+ x (+ y z))))
11 changes: 11 additions & 0 deletions test/kibit/test/collections.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns kibit.test.collections
(:require [kibit.check :as kibit])
(:use [clojure.test]))

(deftest collections-are
(are [expected-alt-form test-form]
(= expected-alt-form (:alt (kibit/check-expr test-form)))
'(vector a) '(conj [] a)
'(vector a b) '(conj [] a b)
'(vec coll) '(into [] coll)
'(set coll) '(into #{} coll)))
23 changes: 11 additions & 12 deletions test/kibit/test/control_structures.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
(:require [kibit.check :as kibit])
(:use [clojure.test]))

;; ==========
;; NOTE
;; ==============
;; YOU SHOULD ALWAYS CHECK WITH ALL RULES
;;
;; Please ensure that new rules generate fully expected results across all
;; rule sets.

(deftest control-structures-are
(are [expected-alt-form test-form]
(are [expected-alt-form test-form]
(= expected-alt-form (:alt (kibit/check-expr test-form)))
'(when test then) '(if test then nil)
'(when-not test else) '(if test nil else)
'(when test body) '(if test (do body))
'(if-not test then else) '(if (not test) then else)
'(when-not test then) '(when (not test) then)
'(println "X") '(if true (println "X") nil)
'(println "X") '(if true (println "X"))
'(when-not test else) '(if test nil else)
'(when test then) '(if test then nil)))

'(do body-1 body-2) '(when true body-1 body-2)
'single-expression '(do single-expression)
'_ '(when-not true anything)
'_ '(when false anything)
'(when-let [a test] expr) '(if-let [a test] expr nil)))
19 changes: 19 additions & 0 deletions test/kibit/test/equality.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns kibit.test.equality
(:require [kibit.check :as kibit])
(:use [clojure.test]))

(deftest equality-are
(are [expected-alt-form test-form]
(= expected-alt-form (:alt (kibit/check-expr test-form)))
'(not= x b) '(not (= x b))
'(zero? x) '(= 0 x)
'(zero? x) '(= x 0)
'(zero? x) '(== 0 x)
'(zero? x) '(== x 0)
'(pos? x) '(< 0 x)
'(pos? x) '(> x 0)
'(pos? x) '(<= 1 x)
'(neg? x) '(< x 0)
true '(= x x)
true '(== x x)
true '(zero? 0)))
29 changes: 29 additions & 0 deletions test/kibit/test/misc.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(ns kibit.test.misc
(:require [kibit.check :as kibit])
(:use [clojure.test]))

(deftest misc-are
(are [expected-alt-form test-form]
(= expected-alt-form (:alt (kibit/check-expr test-form)))
'(clojure.string/join x y) '(apply str (interpose x y))
'(clojure.string/reverse x) '(apply str (reverse x))
'(mapcat x y) '(apply concat (apply map x y))
'(mapcat x y) '(apply concat (map x y))
'(remove pred coll) '(filter (complement pred) coll)
;'(remove pred coll) '(filter #(not (pred %)) coll) -- Expanded form of anonymous fn literal not matching.
'(ffirst coll) '(first (first coll))
'(fnext coll) '(first (next coll))
'(nnext coll) '(next (next coll))
'(nfirst coll) '(next (first coll))
'fun '(fn [args] (fun args))
'fun '(fn* [args] (fun args))
'(str x) '(.toString x)
'(.method obj args) '(. obj method args)
'(Klass/staticMethod args) '(. Klass staticMethod args)
'(form arg) '(-> arg form)
'(:form arg) '(-> arg :form)
'(first-of-form arg rest-of-form) '(-> arg (first-of-form rest-of-form))
'(form arg) '(->> arg form)
'(:form arg) '(->> arg :form)
'(first-of-form rest-of-form arg) '(->> arg (first-of-form rest-of-form))
'(not-any? pred coll) '(not (some pred coll))))
8 changes: 8 additions & 0 deletions test/kibit/test/performance.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns kibit.test.performance
(:require [kibit.check :as kibit])
(:use [clojure.test]))

(deftest performance-are
(are [expected-alt-form test-form]
(= expected-alt-form (:alt (kibit/check-expr test-form)))
'(apply + coll) '(reduce + coll)))

0 comments on commit af21ab3

Please sign in to comment.