Back

do-template (clj)

(source)

macro

(do-template argv expr & values)
Repeatedly copies expr (in a do block) for each group of arguments in values. values are automatically partitioned by the number of arguments in argv, an argument vector as in defn. Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5)) ;=> (do (+ 4 2) (+ 5 3))

Examples

krisajenkins/yesql
(ns yesql.util-test
  (:require [expectations :refer :all]
            [clojure.template :refer [do-template]]
            [yesql.util :refer :all]))

;;; Test underscores-to-dashes
(do-template [input output]
  (expect output
          (underscores-to-dashes input))
krisajenkins/yesql
(ns yesql.statement-parser-test
  (:require [expectations :refer :all]
            [clojure.template :refer [do-template]]
            [yesql.types :refer [map->Query]]
            [yesql.statement-parser :refer :all]))

(do-template [statement _ split-result]
  (do (expect (quote split-result)
              (tokenize statement))
      (expect (quote split-result)
              (tokenize (map->Query {:name "test"
                                     :doctstring "A test case."
                                     :statement statement}))))
krisajenkins/yesql
(ns yesql.queryfile-parser-test
  (:require [clojure.string :refer [join]]
            [clojure.template :refer [do-template]]
            [expectations :refer :all]
            [instaparse.core :as instaparse]
            [yesql.queryfile-parser :refer :all]
            [yesql.types :refer [map->Query]]
            [yesql.util :refer [slurp-from-classpath]])
  (:import [clojure.lang ExceptionInfo]))

(do-template [start-key input _ expected-output]
  (expect (if expected-output
            (list expected-output)
            (list))
          (instaparse/transform parser-transforms
                                (instaparse/parses parser input :start start-key)))
krisajenkins/yesql
(ns yesql.generate-test
  (:require [expectations :refer :all]
            [clojure.template :refer [do-template]]
            [yesql.statement-parser :refer [tokenize]]
            [yesql.generate :refer :all]))

(do-template [statement _ expected-parameters]
  (expect expected-parameters
          (expected-parameter-list statement))

;;; Testing reassemble-query
(do-template [statement parameters _ rewritten-form]
  (expect rewritten-form
          (rewrite-query-for-jdbc (tokenize statement)
                                  parameters))
planck-repl/planck
(ns general.core-test
  "General tests to ensure Planck is operating correctly.
  These tests are not testing any specific Planck namespace."
  (:require-macros
   [clojure.template :refer [do-template]]
   [cljs.analyzer.macros]
   [cljs.compiler.macros]
   [cljs.env.macros])
  (:require
   [cljs.test :refer-macros [deftest is]]
   [cljs.pprint]))

(deftest do-template-test
  (is (= '(do (+ 4 2) (+ 5 3))
        (macroexpand '(do-template [x y] (+ y x) 2 4 3 5)))))