Skip to content

Commit

Permalink
Bugfix: (fact "foo" => 33) thought "foo" was metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Jan 29, 2013
1 parent 32e700e commit 7dd02af
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/midje/parsing/1_to_explicit_form/metadata.clj
Expand Up @@ -16,11 +16,12 @@
(let [head (first body)
add-key (fn [key value] (assoc metadata key value))]

(cond (string? head)
(cond (arrows/start-of-checking-arrow-sequence? body)
[metadata body]

(string? head)
(recur (add-key :midje/description head) (rest body))

(arrows/start-of-checking-arrow-sequence? body)
[metadata body]

(symbol? head)
(recur (add-key :midje/name (name head)) (rest body))
Expand Down
35 changes: 33 additions & 2 deletions test/midje/parsing/1_to_explicit_form/t_metadata.clj
Expand Up @@ -18,7 +18,7 @@
(let [[meta _] (separate-metadata `(FOO "doc" ~@a-body))]
(:midje/source meta) => `(FOO "doc" ~@a-body)
(:midje/name meta) => "doc"))

(fact "doc strings"
(fact "can be separated"
(let [[meta body] (separate-metadata `(fact "doc" ~@a-body))]
Expand Down Expand Up @@ -87,7 +87,38 @@
body => a-body

(fact "and unparse into an explicit map"
(unparse-metadata meta) => (just [{:a 1} 'name] :in-any-order)))))
(unparse-metadata meta) => (just [{:a 1} 'name] :in-any-order))))


(fact "is not confused by the presence of an arrow form"
(let [[meta form] (separate-metadata `(fact 112 => 211))]
form => `(112 => 211))

(let [[meta form] (separate-metadata `(fact cons => cons))]
(:midje/name meta) => nil
form => `(cons => cons))

(let [[meta form] (separate-metadata `(fact :a => :b))]
(:a meta) => nil
form => `(:a => :b))

(let [[meta form] (separate-metadata `(fact {:a 1} => :b))]
(:a meta) => nil
form => `({:a 1} => :b))

(let [[meta form] (separate-metadata `(fact "foo" => 1))]
(:midje/description meta) => nil
form => `("foo" => 1))

(let [[meta form] (separate-metadata `(fact "name" "foo" => 1))]
(:midje/name meta) => "name"
(:midje/description meta) => "name"
form => `("foo" => 1))

(let [[meta form] (separate-metadata `(fact foo "bar" => 1))]
(:midje/name meta) => "foo"
form => `("bar" => 1))))


(facts "about separate-two-level-metadata"
(let [;; The core structure is this:
Expand Down

0 comments on commit 7dd02af

Please sign in to comment.