Skip to content

Commit

Permalink
pangram: update to latest (#736)
Browse files Browse the repository at this point in the history
* pangram: add generator and regenerate tests

[no important files changed]

* Update exercises/practice/pangram/.meta/generator.tpl

Co-authored-by: Anastasios Chatzialexiou <[email protected]>

* Update exercises/practice/pangram/.meta/generator.tpl

Co-authored-by: Anastasios Chatzialexiou <[email protected]>

* Update exercises/practice/pangram/.meta/generator.tpl

Co-authored-by: Anastasios Chatzialexiou <[email protected]>

* Dont' HTML escape

* Fix strings

---------

Co-authored-by: Anastasios Chatzialexiou <[email protected]>
  • Loading branch information
ErikSchierboom and tasxatzial authored Jan 13, 2025
1 parent 01c1b9e commit 5c28e85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 8 additions & 0 deletions exercises/practice/pangram/.meta/generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns pangram-test
(:require [clojure.test :refer [deftest testing is]]
pangram))
{{#test_cases.isPangram}}
(deftest pangram?_test_{{idx}}
(testing "{{description}}"
(is ({{#expected}}true?{{else}}false?{{/expected}} (pangram/pangram? {{string input.sentence}})))))
{{/test_cases.isPangram~}}
23 changes: 15 additions & 8 deletions generators/src/templates.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
[hbs.ext :refer :all :exclude [hash]]
[clojure.string :as str]
[log]
[paths]))
[paths])
(:import [com.github.jknack.handlebars EscapingStrategy]))

(defhelper list-helper [ctx options]
(safe-str (str "'" (seq ctx))))

(register-helper! *hbs* "list" list-helper)
(register-helper! *hbs* "ifequals" ifequals)
(register-helper! *hbs* "ifgreater" ifgreater)
(register-helper! *hbs* "ifless" ifless)
(register-helper! *hbs* "ifcontains" ifcontains)
(register-helper! *hbs* "ifempty" ifempty)
(defhelper string-helper [ctx options]
(safe-str (str "\"" (str/escape ctx char-escape-string) "\"")))

(def reg (. *hbs* with EscapingStrategy/NOOP))

(register-helper! reg "list" list-helper)
(register-helper! reg "string" string-helper)
(register-helper! reg "ifequals" ifequals)
(register-helper! reg "ifgreater" ifgreater)
(register-helper! reg "ifless" ifless)
(register-helper! reg "ifcontains" ifcontains)
(register-helper! reg "ifempty" ifempty)

(def exercises-with-template
(->> paths/exercises-dir
Expand Down Expand Up @@ -50,5 +57,5 @@
(defn generate-test-files [slug test-cases]
(let [template (slurp (paths/generator-template-file slug))
data (test-cases->data slug test-cases)]
(->> (render template data)
(->> (render reg template data)
(spit (paths/tests-file slug)))))

0 comments on commit 5c28e85

Please sign in to comment.