Skip to content

Commit

Permalink
Merge branch 'master' into handlebars
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/hopen/runner.cljs
  • Loading branch information
green-coder committed Apr 4, 2019
2 parents 87895f9 + 63cb594 commit 978e167
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/hopen/syntax/util.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns hopen.syntax.util
(:require [clojure.string :as str]))

(defn re-quote
"Escapes characters in the string that are not safe to use in a regex.
Function ported to Clojure from https://github.com/google/closure-library/blob/0257667129eded0cb9b86b4701e50c986b5db648/closure/goog/string/string.js#L1016"
[s]
(-> s
(str/replace #"[-()\[\]{}+?*.$\^|,:#<!\\]" #(str "\\" %))
(str/replace #"\x08", "\\x08")))
2 changes: 2 additions & 0 deletions test/hopen/runner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
[doo.runner :refer-macros [doo-all-tests doo-tests]]
[hopen.renderer.xf-test]
[hopen.syntax.handlebars-test]
[hopen.parser.util-test]
[hopen.util-test]))

(doo-tests 'hopen.renderer.xf-test
'hopen.parser.util-test
'hopen.syntax.handlebars-test
'hopen.util-test)
13 changes: 13 additions & 0 deletions test/hopen/syntax/util_test.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns hopen.syntax.util-test
(:require #?(:clj [clojure.test :refer [deftest testing is are]]
:cljs [cljs.test :refer [deftest testing is are]
:include-macros true])
[hopen.syntax.util :refer [re-quote]]))

(deftest re-quote-test
(are [input output]
(= (re-quote input) output)

"bonjour" "bonjour"
"{{}}" "\\{\\{\\}\\}"
"<%%>" "\\<%%>"))

0 comments on commit 978e167

Please sign in to comment.