Merge pull request #40 from duelinmarkers/test-coverage-for-rules

Test coverage for rules
This commit is contained in:
Jonas Enlund 2012-06-10 21:20:06 -07:00
commit af21ab3e81
6 changed files with 90 additions and 12 deletions

View file

@ -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))))

View file

@ -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)))

View file

@ -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)))

View file

@ -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
test/kibit/test/misc.clj Normal file
View file

@ -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))))

View file

@ -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)))