forked from jekyll/jekyll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_liquid_encoder.rb
59 lines (49 loc) · 2.05 KB
/
test_liquid_encoder.rb
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
52
53
54
55
56
57
58
59
require 'helper'
class TestLiquidEncoder < Test::Unit::TestCase
context "LiquidEncoder" do
context "#initialize" do
should "give an empty LiquidEncoder without a string" do
encoder = Jekyll::LiquidEncoder.new
assert_equal(encoder.encoded_content, nil)
assert_equal(encoder.salt.length, 6)
end
should "give a populated LiquidEncoder with a string" do
encoder = Jekyll::LiquidEncoder.new('foo string')
assert_not_equal(encoder.encoded_content, nil)
end
end
context "#encode" do
should "raise an error if asked to encode a string when it's already encoded a string" do
encoder = Jekyll::LiquidEncoder.new('foo string')
assert_raise(RuntimeError){ encoder.encode 'bar string' }
end
should "overwrite old string if second argument is +true+" do
encoder = Jekyll::LiquidEncoder.new('foo string')
old_string = encoder.encoded_content
new_string = encoder.encode 'bar string', true
assert_not_equal(old_string, new_string)
end
should "replace liquid tags with HTML" do
encoder = Jekyll::LiquidEncoder.new('This is a {{sample}} string with {%liquid%} content.')
assert_nil(encoder.encoded_content.index('{{'))
assert_nil(encoder.encoded_content.index('{%'))
assert_match(encoder.decoder_regexp,encoder.encoded_content)
end
should "keep liquid tags within raw tags" do
encoder = Jekyll::LiquidEncoder.new('This is a {%raw%}test of {{raw}} content{%endraw%} - {{end}}.')
str = encoder.encoded_content
assert !str.include?('{{end}}')
assert !str.include?('{%raw%}')
assert !str.include?('{%endraw%}')
assert str.include?('{{raw}}')
end
end
context "#decode" do
should "decode correctly" do
encoder = Jekyll::LiquidEncoder.new('Sample {{text}}')
decoded_string = encoder.decode(encoder.encoded_content*3)
assert_equal('Sample {{text}}Sample {{text}}Sample {{text}}', decoded_string)
end
end
end
end