Skip to content
Browse files

Combined extended-equality and extended-falsehood into checking.core

  • Loading branch information...
1 parent 65aef4f commit 43985f33141bbf3cc0bbe7974ef7babeb66833a3 @marick committed Jan 27, 2013
View
4 src/midje/checking/checkers/chatty.clj
@@ -1,10 +1,8 @@
(ns ^{:doc "Checkers that explain more about a failure."}
midje.checking.checkers.chatty
(:use midje.clojure.core
+ midje.checking.core
[midje.checking.checkers.util :only [named-as-call]]
- [midje.checking.extended-falsehood :only [data-laden-falsehood?
- as-data-laden-falsehood
- extended-false?]]
[midje.checking.checkers.defining :only [as-checker]]
[midje.parsing.util.core :only [quoted?]]))
View
3 src/midje/checking/checkers/collection.clj
@@ -3,9 +3,8 @@
(ns ^{:doc "Checkers for collections and strings."}
midje.checking.checkers.collection
(:use midje.clojure.core
+ midje.checking.core
[midje.checking.checkers collection-util util chatty defining collection-comparison]
- midje.checking.extended-equality
- [midje.checking.extended-falsehood :only [extended-true?]]
[midje.error-handling.exceptions :only [user-error]])
(:require [midje.util.pile :as pile]))
View
4 src/midje/checking/checkers/collection_comparison.clj
@@ -3,9 +3,9 @@
(ns ^{:doc "Code to use to compare collections."}
midje.checking.checkers.collection-comparison
(:use midje.clojure.core
+ midje.checking.core
[clojure.math.combinatorics :only [permutations]]
- [midje.checking.checkers collection-util util chatty defining]
- midje.checking.extended-equality)
+ [midje.checking.checkers collection-util util chatty defining])
(:require [clojure.string :as str]
[midje.util.pile :as pile]))
View
2 src/midje/checking/checkers/collection_util.clj
@@ -1,6 +1,6 @@
(ns midje.checking.checkers.collection-util
(:use midje.clojure.core
- [midje.checking.extended-falsehood :only [as-data-laden-falsehood]]))
+ midje.checking.core))
(defn same-lengths? [actual expected]
(= (count actual) (count expected)))
View
6 src/midje/checking/checkers/combining.clj
@@ -1,8 +1,8 @@
(ns ^{:doc "Checkers that combine other checkers."}
midje.checking.checkers.combining
- (:use [midje.checking.checkers.defining]
- [midje.checking.checkers.chatty]
- [midje.checking.extended-falsehood]))
+ (:use midje.checking.core
+ midje.checking.checkers.defining
+ midje.checking.checkers.chatty))
(defn report-failure [actual checker-form result]
(as-data-laden-falsehood {:actual actual
View
3 src/midje/checking/checkers/simple.clj
@@ -3,9 +3,8 @@
(ns ^{:doc "Prepackaged functions that perform common checks."}
midje.checking.checkers.simple
(:use midje.clojure.core
+ midje.checking.core
[midje.checking.checkers.defining :only [as-checker checker defchecker]]
- [midje.checking.extended-falsehood :only [extended-false?]]
- [midje.checking.extended-equality :only [extended-=]]
[midje.checking.checkers.util :only [named-as-call]]
[midje.error-handling.exceptions :only [captured-throwable?]]
[midje.util.ecosystem :only [clojure-1-3? +M -M *M]]
View
32 src/midje/checking/extended_equality.clj → src/midje/checking/core.clj
@@ -1,8 +1,32 @@
-(ns ^{:doc "`=` extended for regular expressions, functions, etc."}
- midje.checking.extended-equality
- (:use midje.clojure.core
- [midje.checking.extended-falsehood :only [as-data-laden-falsehood data-laden-falsehood?]]))
+(ns ^{:doc "Core ideas underlying all checking"}
+ midje.checking.core
+ (:use midje.clojure.core))
+;;; There is a notion of "extended falsehood", in which a false value may be a
+;;; map containing information about what went wrong.
+
+(defn as-data-laden-falsehood [value]
+ (vary-meta value assoc :midje/data-laden-falsehood true))
+
+(defn data-laden-falsehood? [value]
+ (:midje/data-laden-falsehood (meta value)))
+
+(defn data-laden-falsehood-to-map [value]
+ (with-meta value {}))
+
+(defn extended-false? [value]
+ (or (not value)
+ (data-laden-falsehood? value)))
+
+(defn extended-true? [value]
+ (not (extended-false? value)))
+
+(defn user-friendly-falsehood [value]
+ (if (data-laden-falsehood? value)
+ false
+ value))
+
+ ;;; There is a notion of "extended equality" that powers the right-hand-side of Midje examples.
(defn evaluate-checking-function
"Returns a sequence. The first value is either truthy or falsey.
View
2 src/midje/checking/examples.clj
@@ -1,7 +1,7 @@
(ns ^{:doc "Core Midje functions that process expects and report on their results."}
midje.checking.examples
(:use midje.clojure.core
- [midje.checking.extended-equality :only [extended-= evaluate-checking-function]]
+ midje.checking.core
[midje.error-handling.exceptions :only [captured-throwable]]
midje.data.prerequisite-state
midje.util.laziness)
View
23 src/midje/checking/extended_falsehood.clj
@@ -1,23 +0,0 @@
-(ns ^{:doc "Some failing checks carry additional information."}
- midje.checking.extended-falsehood)
-
-(defn as-data-laden-falsehood [value]
- (vary-meta value assoc :midje/data-laden-falsehood true))
-
-(defn data-laden-falsehood? [value]
- (:midje/data-laden-falsehood (meta value)))
-
-(defn data-laden-falsehood-to-map [value]
- (with-meta value {}))
-
-(defn extended-false? [value]
- (or (not value)
- (data-laden-falsehood? value)))
-
-(defn extended-true? [value]
- (not (extended-false? value)))
-
-(defn user-friendly-falsehood [value]
- (if (data-laden-falsehood? value)
- false
- value))
View
5 src/midje/data/prerequisite_state.clj
@@ -1,9 +1,8 @@
(ns ^{:doc "The semi-sweet representation of provided forms."}
midje.data.prerequisite-state
(:use midje.clojure.core
- [midje.checking.extended-equality :only [extended-= extended-list-=]]
- [midje.util.thread-safe-var-nesting :only [namespace-values-inside-out
- with-altered-roots]]
+ midje.checking.core
+ [midje.util.thread-safe-var-nesting :only [with-altered-roots]]
[midje.emission.deprecation :only [deprecate]]
[midje.parsing.arrow-symbols])
(:require [clojure.tools.macro :as macro]
View
2 src/midje/parsing/3_from_lexical_maps/from_fake_maps.clj
@@ -1,9 +1,9 @@
(ns ^{:doc "The semi-sweet representation of provided forms."}
midje.parsing.3-from-lexical-maps.from-fake-maps
(:use midje.clojure.core
+ midje.checking.core
[midje.checkers :only [exactly]]
[midje.checking.checkers.defining :only [checker?]]
- [midje.checking.extended-equality :only [extended-=]]
[midje.parsing.util.file-position :only [user-file-position]]
[midje.parsing.arrow-symbols])
(:require [midje.error-handling.exceptions :as exceptions]))
View
4 test/midje/checking/checkers/t_chatty.clj
@@ -1,11 +1,11 @@
(ns midje.checking.checkers.t-chatty
(:use midje.sweet
midje.util
+ midje.checking.core
[midje.checking.checkers.defining :only [checker?]]
[midje.checking.checkers.chatty :only [chatty-worth-reporting-on?
chatty-untease
chatty-checker?]]
- [midje.checking.extended-falsehood :only [data-laden-falsehood?]]
midje.test-util))
(expose-testables midje.checking.checkers.chatty)
@@ -98,7 +98,7 @@
(= b 2))))
(fact "chatty checkers can use a destructuring argument"
- ;; Note: Can't use extended-equality because it swallows chatty-failures
+ ;; Note: Can't use extended-= because it swallows chatty-failures
(= (vec-structured-checker [1 2 3 4]) true) => truthy )
(tabular "chatty checkers can use a map destructuring argument"
View
6 test/midje/checking/checkers/t_collection.clj
@@ -1,8 +1,8 @@
(ns midje.checking.checkers.t-collection
- (:use [midje sweet test-util]
+ (:use midje.sweet
+ midje.test-util
+ midje.checking.core
[midje.checking.checkers.defining :only [checker?]]
- [midje.checking.extended-falsehood :only [data-laden-falsehood-to-map
- data-laden-falsehood?]]
midje.util))
(expose-testables midje.checking.checkers.collection)
View
6 test/midje/checking/checkers/t_collection_old.clj
@@ -1,7 +1,7 @@
(ns midje.checking.checkers.t-collection-old
- (:use [midje sweet test-util]
- [midje.checking.extended-falsehood :only [data-laden-falsehood-to-map
- data-laden-falsehood?]]))
+ (:use midje.sweet
+ midje.checking.core
+ midje.test-util))
;; These are still potentially useful tests from a misguided code organization.
;; Delete them as they fail (after moving better tests to t-collection.
View
2 test/midje/checking/checkers/t_combining.clj
@@ -1,7 +1,7 @@
(ns midje.checking.checkers.t-combining
(:use midje.sweet
+ midje.checking.core
[midje.checking.checkers.defining :only [checker?]]
- midje.checking.extended-falsehood
midje.test-util))
(fact "about 'every' combinations"
View
31 test/midje/checking/t_extended_equality.clj → test/midje/checking/t_core.clj
@@ -1,8 +1,35 @@
-(ns midje.checking.t-extended-equality
+(ns midje.checking.t-core
(:use midje.sweet
- midje.checking.extended-equality
+ midje.checking.core
midje.test-util))
+(facts "about an extended notion of falsehood"
+ (extended-false? false) => truthy
+ (extended-false? true) => falsey
+ (extended-false? {:intermediate-results 3}) => falsey
+ (extended-false? (as-data-laden-falsehood {})) => truthy
+
+ ".. and its inverse"
+ (extended-true? false) => falsey
+ (extended-true? true) => truthy
+ (extended-true? {:intermediate-results 3}) => truthy
+ (extended-true? (as-data-laden-falsehood {})) => falsey)
+
+(facts "about data-laden falsehoods"
+ (as-data-laden-falsehood [5]) => data-laden-falsehood?
+ (meta (as-data-laden-falsehood (with-meta [5] {:foo true}))) => (contains {:foo true}))
+
+(facts "user-friendly-falsehood converts extended-falsehood into just false"
+ (user-friendly-falsehood false) => false
+ (user-friendly-falsehood nil) => nil
+ (user-friendly-falsehood (as-data-laden-falsehood {})) => false)
+
+
+
+
+
+
+
(facts "about extended equality"
(extended-= 1 2) => falsey
(extended-= 1 odd?) => truthy
View
28 test/midje/checking/t_extended_falsehood.clj
@@ -1,28 +0,0 @@
-(ns midje.checking.t-extended-falsehood
- (:use midje.sweet
- [midje.checking.extended-falsehood]
- midje.test-util))
-
-(facts "about an extended notion of falsehood"
- (extended-false? false) => truthy
- (extended-false? true) => falsey
- (extended-false? {:intermediate-results 3}) => falsey
- (extended-false? (as-data-laden-falsehood {})) => truthy
-
- ".. and its inverse"
- (extended-true? false) => falsey
- (extended-true? true) => truthy
- (extended-true? {:intermediate-results 3}) => truthy
- (extended-true? (as-data-laden-falsehood {})) => falsey)
-
-(facts "about data-laden falsehoods"
- (as-data-laden-falsehood [5]) => data-laden-falsehood?
- (meta (as-data-laden-falsehood (with-meta [5] {:foo true}))) => (contains {:foo true}))
-
-(facts "user-friendly-falsehood converts extended-falsehood into just false"
- (user-friendly-falsehood false) => false
- (user-friendly-falsehood nil) => nil
- (user-friendly-falsehood (as-data-laden-falsehood {})) => false)
-
-
-
View
3 test/midje/test_util.clj
@@ -1,8 +1,7 @@
(ns midje.test-util
(:use [clojure.test]
midje.checkers
- [midje.checking.extended-equality :only [extended-=]]
- [midje.checking.extended-falsehood :only [extended-false?]]
+ midje.checking.core
midje.error-handling.exceptions)
(:require midje.clojure.core
[midje.config :as config]

0 comments on commit 43985f3

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