rearrange nth function alphabetically
This commit is contained in:
parent
d807f45091
commit
fd73645574
|
@ -43,15 +43,6 @@
|
||||||
(with-out-str
|
(with-out-str
|
||||||
(clojure.pprint/print-table x)))}
|
(clojure.pprint/print-table x)))}
|
||||||
|
|
||||||
"nth"
|
|
||||||
{:fn (fn [sequence index & optional-not-found]
|
|
||||||
(let [values (if (map? sequence) ; map instance check to match behaviour of jtwig's first/last implementation
|
|
||||||
(-> sequence vals)
|
|
||||||
sequence)]
|
|
||||||
(if optional-not-found
|
|
||||||
(nth values index (first optional-not-found))
|
|
||||||
(nth values index))))}
|
|
||||||
|
|
||||||
"max"
|
"max"
|
||||||
{:fn (fn [& numbers]
|
{:fn (fn [& numbers]
|
||||||
(if (coll? (first numbers))
|
(if (coll? (first numbers))
|
||||||
|
@ -68,6 +59,15 @@
|
||||||
{:fn (fn [s]
|
{:fn (fn [s]
|
||||||
(StringUtils/normalizeSpace s))}
|
(StringUtils/normalizeSpace s))}
|
||||||
|
|
||||||
|
"nth"
|
||||||
|
{:fn (fn [sequence index & optional-not-found]
|
||||||
|
(let [values (if (map? sequence) ; map instance check to match behaviour of jtwig's first/last implementation
|
||||||
|
(-> sequence vals)
|
||||||
|
sequence)]
|
||||||
|
(if optional-not-found
|
||||||
|
(nth values index (first optional-not-found))
|
||||||
|
(nth values index))))}
|
||||||
|
|
||||||
"pad_left"
|
"pad_left"
|
||||||
{:fn (fn [s size & [padding-string]]
|
{:fn (fn [s size & [padding-string]]
|
||||||
(StringUtils/leftPad s size (or padding-string " ")))}
|
(StringUtils/leftPad s size (or padding-string " ")))}
|
||||||
|
|
|
@ -304,16 +304,6 @@
|
||||||
(is (= (render "{{ t|dump_table }}", {:t [{:a 1 :b 2 :c 3} {:b 5 :a 7 :c "dog"}]})
|
(is (= (render "{{ t|dump_table }}", {:t [{:a 1 :b 2 :c 3} {:b 5 :a 7 :c "dog"}]})
|
||||||
"\n| b | c | a |\n|---+-----+---|\n| 2 | 3 | 1 |\n| 5 | dog | 7 |\n")))
|
"\n| b | c | a |\n|---+-----+---|\n| 2 | 3 | 1 |\n| 5 | dog | 7 |\n")))
|
||||||
|
|
||||||
(testing "nth"
|
|
||||||
(is (= (render "{{ [1, 2, 3, 4, 5]|nth(2) }}" nil)
|
|
||||||
"3"))
|
|
||||||
(is (thrown-with-msg?
|
|
||||||
Exception
|
|
||||||
#"java.lang.IndexOutOfBoundsException"
|
|
||||||
(render "{{ [1, 2, 3, 4, 5]|nth(6) }}" nil)))
|
|
||||||
(is (= (render "{{ [1, 2, 3, 4, 5]|nth(6, \"not found\") }}" nil)
|
|
||||||
"not found")))
|
|
||||||
|
|
||||||
(testing "max"
|
(testing "max"
|
||||||
(is (= (render "{{ [2, 1, 5, 3, 4]|max }}" nil)
|
(is (= (render "{{ [2, 1, 5, 3, 4]|max }}" nil)
|
||||||
"5"))
|
"5"))
|
||||||
|
@ -330,6 +320,16 @@
|
||||||
(is (= (render "{{ normalize_space(' hello world ') }}" nil)
|
(is (= (render "{{ normalize_space(' hello world ') }}" nil)
|
||||||
"hello world")))
|
"hello world")))
|
||||||
|
|
||||||
|
(testing "nth"
|
||||||
|
(is (= (render "{{ [1, 2, 3, 4, 5]|nth(2) }}" nil)
|
||||||
|
"3"))
|
||||||
|
(is (thrown-with-msg?
|
||||||
|
Exception
|
||||||
|
#"java.lang.IndexOutOfBoundsException"
|
||||||
|
(render "{{ [1, 2, 3, 4, 5]|nth(6) }}" nil)))
|
||||||
|
(is (= (render "{{ [1, 2, 3, 4, 5]|nth(6, \"not found\") }}" nil)
|
||||||
|
"not found")))
|
||||||
|
|
||||||
(testing "pad_left"
|
(testing "pad_left"
|
||||||
(is (= (render "{{ pad_left('bat', 5) }}" nil)
|
(is (= (render "{{ pad_left('bat', 5) }}" nil)
|
||||||
" bat"))
|
" bat"))
|
||||||
|
|
Reference in a new issue