update standard function names to be more consistent with the others

This commit is contained in:
Gered 2014-03-05 18:14:30 -05:00
parent 2a22d77a12
commit 8f47565e0a
2 changed files with 22 additions and 20 deletions

View file

@ -11,7 +11,7 @@
; :aliases, which should be a vector of strings containing one or more possible aliases for this function. ; :aliases, which should be a vector of strings containing one or more possible aliases for this function.
(defonce standard-functions (defonce standard-functions
{"blankIfNull" {"blank_if_null"
{:fn (fn [x] {:fn (fn [x]
(if (nil? x) "" x)) (if (nil? x) "" x))
:aliases ["nonull"]} :aliases ["nonull"]}
@ -91,14 +91,16 @@
{:fn (fn [sequence] {:fn (fn [sequence]
(sort < sequence))} (sort < sequence))}
"sortDescending" "sort_descending"
{:fn (fn [sequence] {:fn (fn [sequence]
(sort > sequence))} (sort > sequence))
:aliases ["sort_desc"]}
"sortBy" "sort_by"
{:fn (fn [coll k] {:fn (fn [coll k]
(sort-by #(get % k) coll))} (sort-by #(get % k) coll))}
"sortDescendingBy" "sort_descending_by"
{:fn (fn [coll k] {:fn (fn [coll k]
(sort-by #(get % k) #(compare %2 %1) coll))}}) (sort-by #(get % k) #(compare %2 %1) coll))
:aliases ["sort_desc_by"]}})

View file

@ -254,7 +254,7 @@
(deftest standard-functions (deftest standard-functions
(testing "Standard functions were added properly" (testing "Standard functions were added properly"
(is (true? (function-exists? "blankIfNull"))) (is (true? (function-exists? "blank_if_null")))
(is (true? (function-exists? "butlast"))) (is (true? (function-exists? "butlast")))
(is (true? (function-exists? "dump"))) (is (true? (function-exists? "dump")))
(is (true? (function-exists? "nth"))) (is (true? (function-exists? "nth")))
@ -265,16 +265,16 @@
(is (true? (function-exists? "rest"))) (is (true? (function-exists? "rest")))
(is (true? (function-exists? "second"))) (is (true? (function-exists? "second")))
(is (true? (function-exists? "sort"))) (is (true? (function-exists? "sort")))
(is (true? (function-exists? "sortDescending"))) (is (true? (function-exists? "sort_descending")))
(is (true? (function-exists? "sortBy"))) (is (true? (function-exists? "sort_by")))
(is (true? (function-exists? "sortDescendingBy")))) (is (true? (function-exists? "sort_descending_by"))))
(testing "blankIfNull" (testing "blank_if_null"
(is (= (render "{{ a|blankIfNull }}" nil) (is (= (render "{{ a|blank_if_null }}" nil)
"")) ""))
(is (= (render "{{ a|blankIfNull }}" {:a nil}) (is (= (render "{{ a|blank_if_null }}" {:a nil})
"")) ""))
(is (= (render "{{ a|blankIfNull }}" {:a "foo"}) (is (= (render "{{ a|blank_if_null }}" {:a "foo"})
"foo")) "foo"))
(is (= (render "{{ a|nonull }}" nil) (is (= (render "{{ a|nonull }}" nil)
""))) "")))
@ -333,14 +333,14 @@
(is (= (render "{{ [2, 1, 5, 3, 4]|sort }}" nil) (is (= (render "{{ [2, 1, 5, 3, 4]|sort }}" nil)
"[1, 2, 3, 4, 5]"))) "[1, 2, 3, 4, 5]")))
(testing "sortDescending" (testing "sort_descending"
(is (= (render "{{ [2, 1, 5, 3, 4]|sortDescending }}" nil) (is (= (render "{{ [2, 1, 5, 3, 4]|sort_descending }}" nil)
"[5, 4, 3, 2, 1]"))) "[5, 4, 3, 2, 1]")))
(testing "sortBy" (testing "sort_by"
(is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sortBy(\"a\") }}" nil) (is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sort_by(\"a\") }}" nil)
"[{a=1}, {a=2}, {a=3}, {a=4}, {a=5}]"))) "[{a=1}, {a=2}, {a=3}, {a=4}, {a=5}]")))
(testing "sortDescendingBy" (testing "sort_descending_by"
(is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sortDescendingBy(\"a\") }}" nil) (is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sort_descending_by(\"a\") }}" nil)
"[{a=5}, {a=4}, {a=3}, {a=2}, {a=1}]")))) "[{a=5}, {a=4}, {a=3}, {a=2}, {a=1}]"))))