Skip to content

Commit 9cd4520

Browse files
Change library for templates
1 parent 750a785 commit 9cd4520

File tree

7 files changed

+58
-98
lines changed

7 files changed

+58
-98
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
(ns isogram-test
22
(:require [clojure.test :refer [deftest testing is]]
33
isogram))
4-
{% for test_case in test_cases %}
5-
(deftest isogram_test_{{forloop.counter}}
6-
(testing "{{test_case.path|join:" - "}}"
7-
{% if test_case.expected %}(is (isogram/isogram? "{{test_case.input.phrase}}")))) {% else %}(is (not (isogram/isogram? "{{test_case.input.phrase}}")))){% endif %}
8-
{% endfor %}
4+
5+
{{#test_cases}}
6+
(deftest isogram_test_{{idx}}
7+
(testing "{{description}}"
8+
{{#expected}}
9+
(is (isogram/isogram? "{{input.phrase}}"))))
10+
{{/expected}}
11+
{{^expected}}
12+
(is (not (isogram/isogram? "{{input.phrase}}")))))
13+
{{/expected}}
14+
15+
{{/test_cases}}
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,17 @@
11
(ns isogram-test
2-
(:require [clojure.test :refer [deftest testing is]]
3-
isogram))
4-
5-
(deftest isogram_test_1
6-
(testing "empty string"
7-
(is (isogram/isogram? ""))))
8-
9-
(deftest isogram_test_2
10-
(testing "isogram with only lower case characters"
11-
(is (isogram/isogram? "isogram"))))
12-
13-
(deftest isogram_test_3
14-
(testing "word with one duplicated character"
15-
(is (not (isogram/isogram? "eleven"))))
16-
17-
(deftest isogram_test_4
18-
(testing "word with one duplicated character from the end of the alphabet"
19-
(is (not (isogram/isogram? "zzyzx"))))
20-
21-
(deftest isogram_test_5
22-
(testing "longest reported english isogram"
23-
(is (isogram/isogram? "subdermatoglyphic"))))
24-
25-
(deftest isogram_test_6
26-
(testing "word with duplicated character in mixed case"
27-
(is (not (isogram/isogram? "Alphabet"))))
28-
29-
(deftest isogram_test_7
30-
(testing "word with duplicated character in mixed case, lowercase first"
31-
(is (not (isogram/isogram? "alphAbet"))))
32-
33-
(deftest isogram_test_8
34-
(testing "hypothetical isogrammic word with hyphen"
35-
(is (isogram/isogram? "thumbscrew-japingly"))))
36-
37-
(deftest isogram_test_9
38-
(testing "hypothetical word with duplicated character following hyphen"
39-
(is (not (isogram/isogram? "thumbscrew-jappingly"))))
40-
41-
(deftest isogram_test_10
42-
(testing "isogram with duplicated hyphen"
43-
(is (isogram/isogram? "six-year-old"))))
44-
45-
(deftest isogram_test_11
46-
(testing "made-up name that is an isogram"
47-
(is (isogram/isogram? "Emily Jung Schwartzkopf"))))
48-
49-
(deftest isogram_test_12
50-
(testing "duplicated character in the middle"
51-
(is (not (isogram/isogram? "accentor"))))
52-
53-
(deftest isogram_test_13
54-
(testing "same first and last characters"
55-
(is (not (isogram/isogram? "angola"))))
56-
57-
(deftest isogram_test_14
58-
(testing "word with duplicated character and with two hyphens"
59-
(is (not (isogram/isogram? "up-to-date"))))
60-
2+
(:require [clojure.test :refer [deftest is]]
3+
isogram))
4+
5+
(deftest test-isograms
6+
(is (isogram/isogram? "duplicates"))
7+
(is (isogram/isogram? "subdermatoglyphic"))
8+
(is (isogram/isogram? "thumbscrew-japingly"))
9+
(is (isogram/isogram? "Hjelmqvist-Gryb-Zock-Pfund-Wax"))
10+
(is (isogram/isogram? "Heizölrückstoßabdämpfung"))
11+
(is (isogram/isogram? "Emily Jung Schwartzkopf")))
12+
13+
(deftest test-non-isograms
14+
(is (not (isogram/isogram? "eleven")))
15+
(is (not (isogram/isogram? "Alphabet")))
16+
(is (not (isogram/isogram? "the quick brown fox")))
17+
(is (not (isogram/isogram? "éléphant"))))
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
(ns two-fer-test
22
(:require [clojure.test :refer [deftest testing is]]
33
two-fer))
4-
{% for test_case in test_cases %}
5-
(deftest two-fer_test_{{forloop.counter}}
6-
(testing "{{test_case.path|join:" - "}}"
7-
(is (= "{{test_case.expected}}" (two-fer/two-fer{% if test_case.input.name %} "{{test_case.input.name}}"{% endif %})))))
8-
{% endfor %}
4+
5+
{{#test_cases}}
6+
(deftest two-fer_test_{{idx}}
7+
(testing "{{description}}"
8+
(is (= "{{expected}}" (two-fer/two-fer{{#input.name}} "{{input.name}}"{{/input.name}})))))
9+
10+
{{/test_cases}}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
(ns two-fer-test
2-
(:require [clojure.test :refer [deftest testing is]]
3-
two-fer))
2+
(:require [clojure.test :refer [deftest is]]
3+
two-fer))
44

5-
(deftest two-fer_test_1
6-
(testing "no name given"
7-
(is (= "One for you, one for me." (two-fer/two-fer)))))
5+
(deftest two-fer-test
6+
(is (= "One for you, one for me." (two-fer/two-fer))))
87

9-
(deftest two-fer_test_2
10-
(testing "a name given"
11-
(is (= "One for Alice, one for me." (two-fer/two-fer "Alice")))))
12-
13-
(deftest two-fer_test_3
14-
(testing "another name given"
15-
(is (= "One for Bob, one for me." (two-fer/two-fer "Bob")))))
8+
(deftest name-alice-test
9+
(is (= "One for Alice, one for me." (two-fer/two-fer "Alice"))))
1610

11+
(deftest name-bob-test
12+
(is (= "One for Bob, one for me." (two-fer/two-fer "Bob"))))

generators/deps.edn

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{:paths ["src"]
22
:deps {org.clojure/data.json {:mvn/version "2.5.1"}
3-
selmer/selmer {:mvn/version "1.12.61"}
3+
pogonos/pogonos {:mvn/version "0.2.1"}
44
io.github.tonsky/toml-clj {:mvn/version "0.1.0"}
55
clj-jgit/clj-jgit {:mvn/version "1.1.0"}}}

generators/src/canonical_data.clj

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
[toml-clj.core :as toml]
55
[clj-jgit.porcelain :refer [git-clone git-pull load-repo]]
66
[log]
7-
[paths]))
7+
[paths]
8+
[clojure.string :as str]))
89

910
(def git-url "https://github.com/exercism/problem-specifications.git")
1011

@@ -41,9 +42,11 @@
4142
(let [excluded (excluded-uuids slug)]
4243
(fn [node] (contains? excluded (:uuid node)))))
4344

44-
(defn- node->test-case [node path]
45+
(defn- node->test-case [idx node]
4546
(-> node
46-
(assoc :path path :error (get-in node [:expected :error]))
47+
(assoc :idx (inc idx)
48+
:description (str/join " - " (:path node))
49+
:error (get-in node [:expected :error]))
4750
(dissoc :reimplements :comments :scenarios)))
4851

4952
(defn- test-case-nodes
@@ -54,12 +57,12 @@
5457
updated-path (if description (conj path description) path)]
5558
(if children
5659
(mapcat #(test-case-nodes % updated-path) children)
57-
[(node->test-case node updated-path)]))))
60+
[(assoc node :path updated-path)]))))
5861

5962
(defn test-cases [slug]
6063
(->> slug
6164
(canonical-data)
6265
(test-case-nodes)
6366
(remove (excluded? slug))
67+
(map-indexed node->test-case)
6468
(into [])))
65-

generators/src/templates.clj

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns templates
2-
(:require [selmer.parser :as selmer]
2+
(:require [pogonos.core :as pg]
3+
[pogonos.output :as output]
34
[log]
45
[paths]))
56

@@ -11,14 +12,8 @@
1112
(map #(-> % (.getParentFile) (.getParentFile) (.getName)))
1213
(set)))
1314

14-
(defn- render-template [data template]
15-
(selmer/render (slurp template) data))
16-
17-
(defn- render [slug test-cases]
18-
(let [data {:slug slug :test_cases test-cases}]
19-
(render-template data (paths/generator-template-file slug))))
20-
2115
(defn generate-tests-file [slug test-cases]
22-
(->> test-cases
23-
(render slug)
24-
(spit (paths/tests-file slug))))
16+
(pg/render-file
17+
(paths/generator-template-file slug)
18+
{:test_cases test-cases}
19+
{:output (output/to-file (paths/tests-file slug))}))

0 commit comments

Comments
 (0)