aboutsummaryrefslogtreecommitdiff
path: root/ruby/test/test_filters.rb
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-05 22:24:05 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-05 22:24:18 -0400
commitabe810de48da22fbc8e28369f50e2863291fe505 (patch)
tree3b15905a8ab7f8254d7251bed7c3e84084cdb14b /ruby/test/test_filters.rb
parentff3344c570a8200c2a5933ae6790e24611008bbf (diff)
downloadluigi-template-abe810de48da22fbc8e28369f50e2863291fe505.tar.bz2
luigi-template-abe810de48da22fbc8e28369f50e2863291fe505.zip
php: fix doc typo, ruby: add tests
Diffstat (limited to 'ruby/test/test_filters.rb')
-rw-r--r--ruby/test/test_filters.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/ruby/test/test_filters.rb b/ruby/test/test_filters.rb
new file mode 100644
index 0000000..9c34cd5
--- /dev/null
+++ b/ruby/test/test_filters.rb
@@ -0,0 +1,51 @@
+require 'minitest/autorun'
+require 'luigi-template'
+
+class TemplateTest < MiniTest::Test
+ def test_filter
+ r = Luigi::Template.run('foo%{bar|h}', {
+ bar: '<',
+ })
+
+ assert_equal 'foo&lt;', r
+ end
+
+ def test_filter_chain
+ want = 'foofeab40e1fca77c7360ccca1481bb8ba5f919ce3a'
+ r = Luigi::Template.run('foo%{bar | uc | hash sha1}', {
+ bar: 'foo',
+ })
+
+ assert_equal want, r
+ end
+
+ def test_custom_global_filter
+ Luigi::FILTERS[:barify] = proc { |v| 'BAR' }
+
+ r = Luigi::Template.run('foo%{bar | barify}', {
+ bar: 'foo',
+ })
+
+ assert_equal 'fooBAR', r
+ end
+
+ def test_custom_template_filter
+ r = Luigi::Template.run('foo%{bar | barify}', {
+ bar: 'foo',
+ }, {
+ barify: proc { |v| 'BAR' }
+ })
+
+ assert_equal 'fooBAR', r
+ end
+
+ def test_filter_args
+ want = 'foo0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
+
+ r = Luigi::Template.run('foo%{bar | hash sha1}', {
+ bar: 'foo'
+ })
+
+ assert_equal want, r
+ end
+end