summaryrefslogtreecommitdiff
path: root/ruby/test/test_filters.rb
blob: 03159d775e5ff2e343f051ce2043280354e8b87f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'minitest/autorun'
require 'luigi-template'

class FiltersTest < 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