|
8 | 8 | (defn queries_from_suite [suite-yaml]
|
9 | 9 | (:queries (yaml/from-file suite-yaml)))
|
10 | 10 |
|
| 11 | +(defn- query-implementation [{:keys [selector document ordered]}] |
| 12 | + (let [current (json-path/at-path selector document)] |
| 13 | + (if (= ordered false) |
| 14 | + (sort-by json/write-str current) |
| 15 | + current))) |
| 16 | + |
11 | 17 | (deftest regression
|
12 | 18 | (let [non-consensus-query-ids (->> (queries_from_suite "test/Clojure_json-path.yaml")
|
13 | 19 | (map :id)
|
|
17 | 23 | (map (fn [{:keys [id selector document ordered] :as query}]
|
18 | 24 | (let [expected (if (contains? query :scalar-consensus)
|
19 | 25 | (:scalar-consensus query)
|
20 |
| - (:consensus query)) |
21 |
| - current (json-path/at-path selector document) |
22 |
| - current-reordered (if (= ordered false) |
23 |
| - (sort-by json/write-str current) |
24 |
| - current)] |
| 26 | + (:consensus query))] |
25 | 27 | (testing id
|
26 | 28 | (is (= expected
|
27 |
| - current-reordered)))))) |
| 29 | + (query-implementation query))))))) |
28 | 30 | doall)))
|
29 | 31 |
|
30 | 32 | (defn- report-change [current-reordered status result {:keys [selector document consensus id]}]
|
|
50 | 52 | query-lookup (zipmap (map :id all-queries)
|
51 | 53 | all-queries)]
|
52 | 54 | (->> (queries_from_suite "test/Clojure_json-path.yaml")
|
53 |
| - (map (fn [{:keys [id status result] :as query}] |
54 |
| - (let [{:keys [selector document ordered]} (get query-lookup id)] |
| 55 | + (map (fn [{:keys [id status result]}] |
| 56 | + (let [query (get query-lookup id)] |
55 | 57 | (testing id
|
56 | 58 | (try
|
57 |
| - (let [current (doall (json-path/at-path selector document)) |
58 |
| - current-reordered (if (= ordered false) |
59 |
| - (sort-by json/write-str current) |
60 |
| - current)] |
| 59 | + (let [current (query-implementation query)] |
61 | 60 | (when (or (= "error" status)
|
62 |
| - (not= result current-reordered)) |
63 |
| - (report-change current-reordered status result (get query-lookup id)))) |
| 61 | + (not= result current)) |
| 62 | + (report-change current status result query))) |
64 | 63 | (catch Exception e
|
65 | 64 | (when (not= "error"
|
66 | 65 | status)
|
67 | 66 | (do
|
68 |
| - (println (format "Warning: implementation has changed to error for %s: %s (status %s)" id selector status)) |
| 67 | + (println (format "Warning: implementation has changed to error for %s: %s (status %s)" id (:selector query) status)) |
69 | 68 | (println (format " was %s" (pr-str result)))))))))))
|
70 | 69 | doall)))
|
0 commit comments