temple 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -8
  3. data/.gitignore +1 -0
  4. data/CHANGES +5 -0
  5. data/README.md +1 -1
  6. data/Rakefile +3 -11
  7. data/lib/temple/erb/parser.rb +1 -1
  8. data/lib/temple/generator.rb +11 -5
  9. data/lib/temple/version.rb +1 -1
  10. data/spec/engine_spec.rb +189 -0
  11. data/{test/test_erb.rb → spec/erb_spec.rb} +11 -11
  12. data/spec/filter_spec.rb +29 -0
  13. data/{test/filters/test_code_merger.rb → spec/filters/code_merger_spec.rb} +7 -7
  14. data/{test/filters/test_control_flow.rb → spec/filters/control_flow_spec.rb} +13 -13
  15. data/{test/filters/test_dynamic_inliner.rb → spec/filters/dynamic_inliner_spec.rb} +18 -18
  16. data/{test/filters/test_eraser.rb → spec/filters/eraser_spec.rb} +9 -9
  17. data/{test/filters/test_escapable.rb → spec/filters/escapable_spec.rb} +10 -10
  18. data/{test/filters/test_multi_flattener.rb → spec/filters/multi_flattener_spec.rb} +4 -4
  19. data/{test/filters/test_static_analyzer.rb → spec/filters/static_analyzer_spec.rb} +6 -8
  20. data/{test/filters/test_static_merger.rb → spec/filters/static_merger_spec.rb} +7 -7
  21. data/{test/filters/test_string_splitter.rb → spec/filters/string_splitter_spec.rb} +4 -5
  22. data/spec/generator_spec.rb +167 -0
  23. data/spec/grammar_spec.rb +47 -0
  24. data/{test/html/test_attribute_merger.rb → spec/html/attribute_merger_spec.rb} +11 -11
  25. data/{test/html/test_attribute_remover.rb → spec/html/attribute_remover_spec.rb} +7 -7
  26. data/{test/html/test_attribute_sorter.rb → spec/html/attribute_sorter_spec.rb} +7 -7
  27. data/{test/html/test_fast.rb → spec/html/fast_spec.rb} +23 -23
  28. data/{test/html/test_pretty.rb → spec/html/pretty_spec.rb} +7 -7
  29. data/spec/map_spec.rb +39 -0
  30. data/{test/mixins/test_dispatcher.rb → spec/mixins/dispatcher_spec.rb} +12 -12
  31. data/{test/mixins/test_grammar_dsl.rb → spec/mixins/grammar_dsl_spec.rb} +19 -19
  32. data/{test/helper.rb → spec/spec_helper.rb} +3 -4
  33. data/{test/test_static_analyzer.rb → spec/static_analyzer_spec.rb} +6 -6
  34. data/spec/utils_spec.rb +39 -0
  35. data/temple.gemspec +1 -1
  36. metadata +28 -28
  37. data/test/test_engine.rb +0 -189
  38. data/test/test_filter.rb +0 -29
  39. data/test/test_generator.rb +0 -158
  40. data/test/test_grammar.rb +0 -47
  41. data/test/test_map.rb +0 -39
  42. data/test/test_utils.rb +0 -39
@@ -1,13 +1,13 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::Eraser do
4
4
  it 'should respect keep' do
5
5
  eraser = Temple::Filters::Eraser.new(keep: [:a])
6
- eraser.call([:multi,
6
+ expect(eraser.call([:multi,
7
7
  [:a],
8
8
  [:b],
9
9
  [:c]
10
- ]).should.equal [:multi,
10
+ ])).to eq [:multi,
11
11
  [:a],
12
12
  [:multi],
13
13
  [:multi]
@@ -16,11 +16,11 @@ describe Temple::Filters::Eraser do
16
16
 
17
17
  it 'should respect erase' do
18
18
  eraser = Temple::Filters::Eraser.new(erase: [:a])
19
- eraser.call([:multi,
19
+ expect(eraser.call([:multi,
20
20
  [:a],
21
21
  [:b],
22
22
  [:c]
23
- ]).should.equal [:multi,
23
+ ])).to eq [:multi,
24
24
  [:multi],
25
25
  [:b],
26
26
  [:c]
@@ -29,11 +29,11 @@ describe Temple::Filters::Eraser do
29
29
 
30
30
  it 'should choose erase over keep' do
31
31
  eraser = Temple::Filters::Eraser.new(keep: [:a, :b], erase: [:a])
32
- eraser.call([:multi,
32
+ expect(eraser.call([:multi,
33
33
  [:a],
34
34
  [:b],
35
35
  [:c]
36
- ]).should.equal [:multi,
36
+ ])).to eq [:multi,
37
37
  [:multi],
38
38
  [:b],
39
39
  [:multi]
@@ -42,11 +42,11 @@ describe Temple::Filters::Eraser do
42
42
 
43
43
  it 'should erase nested types' do
44
44
  eraser = Temple::Filters::Eraser.new(erase: [[:a, :b]])
45
- eraser.call([:multi,
45
+ expect(eraser.call([:multi,
46
46
  [:a, :a],
47
47
  [:a, :b],
48
48
  [:b]
49
- ]).should.equal [:multi,
49
+ ])).to eq [:multi,
50
50
  [:a, :a],
51
51
  [:multi],
52
52
  [:b]
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::Escapable do
4
4
  before do
@@ -6,11 +6,11 @@ describe Temple::Filters::Escapable do
6
6
  end
7
7
 
8
8
  it 'should handle escape expressions' do
9
- @filter.call([:escape, true,
9
+ expect(@filter.call([:escape, true,
10
10
  [:multi,
11
11
  [:static, "a < b"],
12
12
  [:dynamic, "ruby_method"]]
13
- ]).should.equal [:multi,
13
+ ])).to eq [:multi,
14
14
  [:static, "a &lt; b"],
15
15
  [:dynamic, "::Temple::Utils.escape_html((ruby_method))"],
16
16
  ]
@@ -18,32 +18,32 @@ describe Temple::Filters::Escapable do
18
18
 
19
19
  it 'should keep codes intact' do
20
20
  exp = [:multi, [:code, 'foo']]
21
- @filter.call(exp).should.equal exp
21
+ expect(@filter.call(exp)).to eq(exp)
22
22
  end
23
23
 
24
24
  it 'should keep statics intact' do
25
25
  exp = [:multi, [:static, '<']]
26
- @filter.call(exp).should.equal exp
26
+ expect(@filter.call(exp)).to eq(exp)
27
27
  end
28
28
 
29
29
  it 'should keep dynamic intact' do
30
30
  exp = [:multi, [:dynamic, 'foo']]
31
- @filter.call(exp).should.equal exp
31
+ expect(@filter.call(exp)).to eq(exp)
32
32
  end
33
33
 
34
34
  it 'should have use_html_safe option' do
35
35
  with_html_safe do
36
36
  filter = Temple::Filters::Escapable.new(use_html_safe: true)
37
- filter.call([:escape, true,
37
+ expect(filter.call([:escape, true,
38
38
  [:static, Temple::HTML::SafeString.new("a < b")]
39
- ]).should.equal [:static, "a < b"]
39
+ ])).to eq [:static, "a < b"]
40
40
  end
41
41
  end
42
42
 
43
43
  it 'should support censoring' do
44
44
  filter = Temple::Filters::Escapable.new(escape_code: '(%s).gsub("Temple sucks", "Temple rocks")')
45
- filter.call([:escape, true,
45
+ expect(filter.call([:escape, true,
46
46
  [:static, "~~ Temple sucks ~~"]
47
- ]).should.equal [:static, "~~ Temple rocks ~~"]
47
+ ])).to eq [:static, "~~ Temple rocks ~~"]
48
48
  end
49
49
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::MultiFlattener do
4
4
  before do
@@ -6,7 +6,7 @@ describe Temple::Filters::MultiFlattener do
6
6
  end
7
7
 
8
8
  it 'should flatten nested multi expressions' do
9
- @filter.call([:multi,
9
+ expect(@filter.call([:multi,
10
10
  [:static, "a"],
11
11
  [:multi,
12
12
  [:dynamic, "aa"],
@@ -17,7 +17,7 @@ describe Temple::Filters::MultiFlattener do
17
17
  [:dynamic, "ab"],
18
18
  ],
19
19
  [:static, "b"],
20
- ]).should.equal [:multi,
20
+ ])).to eq [:multi,
21
21
  [:static, "a"],
22
22
  [:dynamic, "aa"],
23
23
  [:static, "aaa"],
@@ -28,6 +28,6 @@ describe Temple::Filters::MultiFlattener do
28
28
  end
29
29
 
30
30
  it 'should return first element' do
31
- @filter.call([:multi, [:code, 'foo']]).should.equal [:code, 'foo']
31
+ expect(@filter.call([:multi, [:code, 'foo']])).to eq([:code, 'foo'])
32
32
  end
33
33
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::StaticAnalyzer do
4
4
  before do
@@ -8,21 +8,19 @@ describe Temple::Filters::StaticAnalyzer do
8
8
 
9
9
  if Temple::StaticAnalyzer.available?
10
10
  it 'should convert :dynamic to :static if code is static' do
11
- @filter.call([:dynamic, '"#{"hello"}#{100}"']
12
- ).should.equal [:static, 'hello100']
11
+ expect(@filter.call([:dynamic, '"#{"hello"}#{100}"'])).to eq([:static, 'hello100'])
13
12
  end
14
13
 
15
14
  it 'should not convert :dynamic if code is dynamic' do
16
15
  exp = [:dynamic, '"#{hello}#{100}"']
17
- @filter.call(exp).should.equal(exp)
16
+ expect(@filter.call(exp)).to eq(exp)
18
17
  end
19
18
 
20
19
  it 'should not change number of newlines in generated code' do
21
20
  exp = [:dynamic, "[100,\n200,\n]"]
22
- @filter.call(exp).should.equal([:multi, [:static, '[100, 200]'], [:newline], [:newline]])
21
+ expect(@filter.call(exp)).to eq([:multi, [:static, '[100, 200]'], [:newline], [:newline]])
23
22
 
24
- @generator.call(@filter.call(exp)).count("\n").
25
- should.equal(@generator.call(exp).count("\n"))
23
+ expect(@generator.call(@filter.call(exp)).count("\n")).to eq(@generator.call(exp).count("\n"))
26
24
  end
27
25
  else
28
26
  it 'should do nothing' do
@@ -30,7 +28,7 @@ describe Temple::Filters::StaticAnalyzer do
30
28
  [:dynamic, '"#{"hello"}#{100}"'],
31
29
  [:dynamic, '"#{hello}#{100}"'],
32
30
  ].each do |exp|
33
- @filter.call(exp).should.equal(exp)
31
+ expect(@filter.call(exp)).to eq(exp)
34
32
  end
35
33
  end
36
34
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::Filters::StaticMerger do
4
4
  before do
@@ -6,21 +6,21 @@ describe Temple::Filters::StaticMerger do
6
6
  end
7
7
 
8
8
  it 'should merge serveral statics' do
9
- @filter.call([:multi,
9
+ expect(@filter.call([:multi,
10
10
  [:static, "Hello "],
11
11
  [:static, "World, "],
12
12
  [:static, "Good night"]
13
- ]).should.equal [:static, "Hello World, Good night"]
13
+ ])).to eq [:static, "Hello World, Good night"]
14
14
  end
15
15
 
16
16
  it 'should merge serveral statics around code' do
17
- @filter.call([:multi,
17
+ expect(@filter.call([:multi,
18
18
  [:static, "Hello "],
19
19
  [:static, "World!"],
20
20
  [:code, "123"],
21
21
  [:static, "Good night, "],
22
22
  [:static, "everybody"]
23
- ]).should.equal [:multi,
23
+ ])).to eq [:multi,
24
24
  [:static, "Hello World!"],
25
25
  [:code, "123"],
26
26
  [:static, "Good night, everybody"]
@@ -28,12 +28,12 @@ describe Temple::Filters::StaticMerger do
28
28
  end
29
29
 
30
30
  it 'should merge serveral statics across newlines' do
31
- @filter.call([:multi,
31
+ expect(@filter.call([:multi,
32
32
  [:static, "Hello "],
33
33
  [:static, "World, "],
34
34
  [:newline],
35
35
  [:static, "Good night"]
36
- ]).should.equal [:multi,
36
+ ])).to eq [:multi,
37
37
  [:static, "Hello World, Good night"],
38
38
  [:newline]
39
39
  ]
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
  begin
3
3
  require 'ripper'
4
4
  rescue LoadError
@@ -32,19 +32,18 @@ if defined?(Ripper) && RUBY_VERSION >= "2.0.0"
32
32
  }.each do |code, expected|
33
33
  it "should split #{code}" do
34
34
  actual = @filter.call([:dynamic, code])
35
- actual.should.equal expected
35
+ expect(actual).to eq(expected)
36
36
  end
37
37
  end
38
38
 
39
39
  describe '.compile' do
40
40
  it 'should raise CompileError for non-string literals' do
41
- lambda { Temple::Filters::StringSplitter.compile('1') }.
42
- should.raise(Temple::FilterError)
41
+ expect { Temple::Filters::StringSplitter.compile('1') }.to raise_error(Temple::FilterError)
43
42
  end
44
43
 
45
44
  it 'should compile strings quoted with parenthesis' do
46
45
  tokens = Temple::Filters::StringSplitter.compile('%Q(href("#{1 + 1}");)')
47
- tokens.should.equal [[:static, "href(\""], [:dynamic, "1 + 1"], [:static, "\");"]]
46
+ expect(tokens).to eq([[:static, "href(\""], [:dynamic, "1 + 1"], [:static, "\");"]])
48
47
  end
49
48
  end
50
49
  end
@@ -0,0 +1,167 @@
1
+ require 'spec_helper'
2
+
3
+ class SimpleGenerator < Temple::Generator
4
+ def preamble
5
+ "#{buffer} = BUFFER"
6
+ end
7
+
8
+ def postamble
9
+ buffer
10
+ end
11
+
12
+ def on_static(s)
13
+ concat "S:#{s}"
14
+ end
15
+
16
+ def on_dynamic(s)
17
+ concat "D:#{s}"
18
+ end
19
+
20
+ def on_code(s)
21
+ "C:#{s}"
22
+ end
23
+ end
24
+
25
+ describe Temple::Generator do
26
+ it 'should compile simple expressions' do
27
+ gen = SimpleGenerator.new
28
+
29
+ expect(gen.call([:static, 'test'])).to eq('_buf = BUFFER; _buf << (S:test); _buf')
30
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = BUFFER; _buf << (D:test); _buf')
31
+ expect(gen.call([:code, 'test'])).to eq('_buf = BUFFER; C:test; _buf')
32
+ end
33
+
34
+ it 'should compile multi expression' do
35
+ gen = SimpleGenerator.new(buffer: "VAR")
36
+ expect(gen.call([:multi,
37
+ [:static, "static"],
38
+ [:dynamic, "dynamic"],
39
+ [:code, "code"]
40
+ ])).to eq('VAR = BUFFER; VAR << (S:static); VAR << (D:dynamic); C:code; VAR')
41
+ end
42
+
43
+ it 'should compile capture' do
44
+ gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
45
+ expect(gen.call([:capture, "foo",
46
+ [:static, "test"]
47
+ ])).to eq('VAR = BUFFER; foo = BUFFER; foo << (S:test); foo; VAR')
48
+ end
49
+
50
+ it 'should compile capture with multi' do
51
+ gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
52
+ expect(gen.call([:multi,
53
+ [:static, "before"],
54
+
55
+ [:capture, "foo", [:multi,
56
+ [:static, "static"],
57
+ [:dynamic, "dynamic"],
58
+ [:code, "code"]]],
59
+
60
+ [:static, "after"]
61
+ ])).to eq('VAR = BUFFER; VAR << (S:before); foo = BUFFER; foo << (S:static); ' +
62
+ 'foo << (D:dynamic); C:code; foo; VAR << (S:after); VAR')
63
+ end
64
+
65
+ it 'should compile nested capture with the same capture_generator' do
66
+ gen = SimpleGenerator.new(buffer: "VAR", capture_generator: SimpleGenerator)
67
+ expect(gen.call([:capture, "foo", [:multi,
68
+ [:capture, "bar", [:multi,
69
+ [:static, "a"],
70
+ [:static, "b"]]]]
71
+ ])).to eq "VAR = BUFFER; foo = BUFFER; bar = BUFFER; bar << (S:a); bar << (S:b); bar; foo; VAR"
72
+ end
73
+
74
+ it 'should compile newlines' do
75
+ gen = SimpleGenerator.new(buffer: "VAR")
76
+ expect(gen.call([:multi,
77
+ [:static, "static"],
78
+ [:newline],
79
+ [:dynamic, "dynamic"],
80
+ [:newline],
81
+ [:code, "code"]
82
+ ])).to eq("VAR = BUFFER; VAR << (S:static); \n; " +
83
+ "VAR << (D:dynamic); \n; C:code; VAR")
84
+ end
85
+ end
86
+
87
+ describe Temple::Generators::Array do
88
+ it 'should compile simple expressions' do
89
+ gen = Temple::Generators::Array.new(freeze_static: false)
90
+ expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test"); _buf')
91
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = []; _buf << (test); _buf')
92
+ expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf')
93
+
94
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf')
95
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf')
96
+ end
97
+
98
+ it 'should freeze static' do
99
+ gen = Temple::Generators::Array.new(freeze_static: true)
100
+ expect(gen.call([:static, 'test'])).to eq('_buf = []; _buf << ("test".freeze); _buf')
101
+ end
102
+ end
103
+
104
+ describe Temple::Generators::ArrayBuffer do
105
+ it 'should compile simple expressions' do
106
+ gen = Temple::Generators::ArrayBuffer.new(freeze_static: false)
107
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
108
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
109
+ expect(gen.call([:code, 'test'])).to eq('_buf = []; test; _buf = _buf.join("")')
110
+
111
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << ("b"); _buf = _buf.join("")')
112
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = []; _buf << ("a"); _buf << (b); _buf = _buf.join("")')
113
+ end
114
+
115
+ it 'should freeze static' do
116
+ gen = Temple::Generators::ArrayBuffer.new(freeze_static: true)
117
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
118
+ expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = []; _buf << (1); _buf << ("test".freeze); _buf = _buf.join("".freeze)')
119
+ end
120
+ end
121
+
122
+ describe Temple::Generators::StringBuffer do
123
+ it 'should compile simple expressions' do
124
+ gen = Temple::Generators::StringBuffer.new(freeze_static: false)
125
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
126
+ expect(gen.call([:dynamic, 'test'])).to eq('_buf = (test).to_s')
127
+ expect(gen.call([:code, 'test'])).to eq('_buf = \'\'; test; _buf')
128
+
129
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ("b"); _buf')
130
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('_buf = \'\'; _buf << ("a"); _buf << ((b).to_s); _buf')
131
+ end
132
+
133
+ it 'should freeze static' do
134
+ gen = Temple::Generators::StringBuffer.new(freeze_static: true)
135
+ expect(gen.call([:static, 'test'])).to eq('_buf = "test"')
136
+ expect(gen.call([:multi, [:dynamic, '1'], [:static, 'test']])).to eq('_buf = \'\'; _buf << ((1).to_s); _buf << ("test".freeze); _buf')
137
+ end
138
+ end
139
+
140
+ describe Temple::Generators::ERB do
141
+ it 'should compile simple expressions' do
142
+ gen = Temple::Generators::ERB.new
143
+ expect(gen.call([:static, 'test'])).to eq('test')
144
+ expect(gen.call([:dynamic, 'test'])).to eq('<%= test %>')
145
+ expect(gen.call([:code, 'test'])).to eq('<% test %>')
146
+
147
+ expect(gen.call([:multi, [:static, 'a'], [:static, 'b']])).to eq('ab')
148
+ expect(gen.call([:multi, [:static, 'a'], [:dynamic, 'b']])).to eq('a<%= b %>')
149
+ end
150
+ end
151
+
152
+ describe Temple::Generators::RailsOutputBuffer do
153
+ it 'should compile simple expressions' do
154
+ gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: false)
155
+ expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
156
+ '@output_buffer.safe_concat(("test")); @output_buffer')
157
+ expect(gen.call([:dynamic, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
158
+ '@output_buffer.safe_concat(((test).to_s)); @output_buffer')
159
+ expect(gen.call([:code, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; ' +
160
+ 'test; @output_buffer')
161
+ end
162
+
163
+ it 'should freeze static' do
164
+ gen = Temple::Generators::RailsOutputBuffer.new(freeze_static: true)
165
+ expect(gen.call([:static, 'test'])).to eq('@output_buffer = output_buffer || ActionView::OutputBuffer.new; @output_buffer.safe_concat(("test".freeze)); @output_buffer')
166
+ end
167
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Temple::Grammar do
4
+ it 'should match core expressions' do
5
+ expect(Temple::Grammar).to be_match([:multi])
6
+ expect(Temple::Grammar).to be_match([:multi, [:multi]])
7
+ expect(Temple::Grammar).to be_match([:static, 'Text'])
8
+ expect(Temple::Grammar).to be_match([:dynamic, 'Text'])
9
+ expect(Temple::Grammar).to be_match([:code, 'Text'])
10
+ expect(Temple::Grammar).to be_match([:capture, 'Text', [:multi]])
11
+ expect(Temple::Grammar).to be_match([:newline])
12
+ end
13
+
14
+ it 'should not match invalid core expressions' do
15
+ expect(Temple::Grammar).not_to be_match([:multi, 'String'])
16
+ expect(Temple::Grammar).not_to be_match([:static])
17
+ expect(Temple::Grammar).not_to be_match([:dynamic, 1])
18
+ expect(Temple::Grammar).not_to be_match([:code, :sym])
19
+ expect(Temple::Grammar).not_to be_match([:capture, [:multi]])
20
+ expect(Temple::Grammar).not_to be_match([:newline, [:multi]])
21
+ end
22
+
23
+ it 'should match control flow expressions' do
24
+ expect(Temple::Grammar).to be_match([:if, 'Condition', [:multi]])
25
+ expect(Temple::Grammar).to be_match([:if, 'Condition', [:multi], [:multi]])
26
+ expect(Temple::Grammar).to be_match([:block, 'Loop', [:multi]])
27
+ expect(Temple::Grammar).to be_match([:case, 'Arg', ['Cond1', [:multi]], ['Cond1', [:multi]], [:else, [:multi]]])
28
+ expect(Temple::Grammar).not_to be_match([:case, 'Arg', [:sym, [:multi]]])
29
+ expect(Temple::Grammar).to be_match([:cond, ['Cond1', [:multi]], ['Cond2', [:multi]], [:else, [:multi]]])
30
+ expect(Temple::Grammar).not_to be_match([:cond, [:sym, [:multi]]])
31
+ end
32
+
33
+ it 'should match escape expression' do
34
+ expect(Temple::Grammar).to be_match([:escape, true, [:multi]])
35
+ expect(Temple::Grammar).to be_match([:escape, false, [:multi]])
36
+ end
37
+
38
+ it 'should match html expressions' do
39
+ expect(Temple::Grammar).to be_match([:html, :doctype, 'Doctype'])
40
+ expect(Temple::Grammar).to be_match([:html, :comment, [:multi]])
41
+ expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:multi]])
42
+ expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:multi], [:multi]])
43
+ expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:multi], [:static, 'Text']])
44
+ expect(Temple::Grammar).to be_match([:html, :tag, 'Tag', [:html, :attrs, [:html, :attr, 'id',
45
+ [:static, 'val']]], [:static, 'Text']])
46
+ end
47
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::AttributeMerger do
4
4
  before do
@@ -6,24 +6,24 @@ describe Temple::HTML::AttributeMerger do
6
6
  end
7
7
 
8
8
  it 'should pass static attributes through' do
9
- @merger.call([:html, :tag,
9
+ expect(@merger.call([:html, :tag,
10
10
  'div',
11
11
  [:html, :attrs, [:html, :attr, 'class', [:static, 'b']]],
12
12
  [:content]
13
- ]).should.equal [:html, :tag, "div",
13
+ ])).to eq [:html, :tag, "div",
14
14
  [:html, :attrs,
15
15
  [:html, :attr, "class", [:static, "b"]]],
16
16
  [:content]]
17
17
  end
18
18
 
19
19
  it 'should preserve the order of html attributes' do
20
- @merger.call([:html, :tag,
20
+ expect(@merger.call([:html, :tag,
21
21
  'meta',
22
22
  [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
23
23
  [:html, :attr, 'd', [:static, '2']],
24
24
  [:html, :attr, 'a', [:static, '3']],
25
25
  [:html, :attr, 'b', [:static, '4']]]
26
- ]).should.equal [:html, :tag, 'meta',
26
+ ])).to eq [:html, :tag, 'meta',
27
27
  [:html, :attrs,
28
28
  [:html, :attr, 'c', [:static, '1']],
29
29
  [:html, :attr, 'd', [:static, '2']],
@@ -31,22 +31,22 @@ describe Temple::HTML::AttributeMerger do
31
31
  [:html, :attr, 'b', [:static, '4']]]]
32
32
 
33
33
  # Use case:
34
- @merger.call([:html, :tag,
34
+ expect(@merger.call([:html, :tag,
35
35
  'meta',
36
36
  [:html, :attrs, [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
37
37
  [:html, :attr, 'content', [:static, '']]]
38
- ]).should.equal [:html, :tag, 'meta',
38
+ ])).to eq [:html, :tag, 'meta',
39
39
  [:html, :attrs,
40
40
  [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
41
41
  [:html, :attr, 'content', [:static, '']]]]
42
42
  end
43
43
 
44
44
  it 'should merge ids' do
45
- @merger.call([:html, :tag,
45
+ expect(@merger.call([:html, :tag,
46
46
  'div',
47
47
  [:html, :attrs, [:html, :attr, 'id', [:dynamic, 'a']], [:html, :attr, 'id', [:dynamic, 'b']]],
48
48
  [:content]
49
- ]).should.equal [:html, :tag, "div",
49
+ ])).to eq [:html, :tag, "div",
50
50
  [:html, :attrs,
51
51
  [:html, :attr, "id",
52
52
  [:multi,
@@ -58,11 +58,11 @@ describe Temple::HTML::AttributeMerger do
58
58
  end
59
59
 
60
60
  it 'should merge classes' do
61
- @merger.call([:html, :tag,
61
+ expect(@merger.call([:html, :tag,
62
62
  'div',
63
63
  [:html, :attrs, [:html, :attr, 'class', [:static, 'a']], [:html, :attr, 'class', [:dynamic, 'b']]],
64
64
  [:content]
65
- ]).should.equal [:html, :tag, "div",
65
+ ])).to eq [:html, :tag, "div",
66
66
  [:html, :attrs,
67
67
  [:html, :attr, "class",
68
68
  [:multi,
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::AttributeRemover do
4
4
  before do
@@ -6,22 +6,22 @@ describe Temple::HTML::AttributeRemover do
6
6
  end
7
7
 
8
8
  it 'should pass static attributes through' do
9
- @remover.call([:html, :tag,
9
+ expect(@remover.call([:html, :tag,
10
10
  'div',
11
11
  [:html, :attrs, [:html, :attr, 'class', [:static, 'b']]],
12
12
  [:content]
13
- ]).should.equal [:html, :tag, "div",
13
+ ])).to eq [:html, :tag, "div",
14
14
  [:multi,
15
15
  [:html, :attr, "class", [:static, "b"]]],
16
16
  [:content]]
17
17
  end
18
18
 
19
19
  it 'should check for empty dynamic attribute if it is included in :remove_empty_attrs' do
20
- @remover.call([:html, :tag,
20
+ expect(@remover.call([:html, :tag,
21
21
  'div',
22
22
  [:html, :attrs, [:html, :attr, 'class', [:dynamic, 'b']]],
23
23
  [:content]
24
- ]).should.equal [:html, :tag, "div",
24
+ ])).to eq [:html, :tag, "div",
25
25
  [:multi,
26
26
  [:multi,
27
27
  [:capture, "_temple_html_attributeremover1", [:dynamic, "b"]],
@@ -31,11 +31,11 @@ describe Temple::HTML::AttributeRemover do
31
31
  end
32
32
 
33
33
  it 'should not check for empty dynamic attribute if it is not included in :remove_empty_attrs' do
34
- @remover.call([:html, :tag,
34
+ expect(@remover.call([:html, :tag,
35
35
  'div',
36
36
  [:html, :attrs, [:html, :attr, 'name', [:dynamic, 'b']]],
37
37
  [:content]
38
- ]).should.equal [:html, :tag, "div",
38
+ ])).to eq [:html, :tag, "div",
39
39
  [:multi,
40
40
  [:html, :attr, "name", [:dynamic, "b"]]],
41
41
  [:content]]
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Temple::HTML::AttributeSorter do
4
4
  before do
@@ -7,13 +7,13 @@ describe Temple::HTML::AttributeSorter do
7
7
  end
8
8
 
9
9
  it 'should sort html attributes by name by default, when :sort_attrs is true' do
10
- @ordered.call([:html, :tag,
10
+ expect(@ordered.call([:html, :tag,
11
11
  'meta',
12
12
  [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
13
13
  [:html, :attr, 'd', [:static, '2']],
14
14
  [:html, :attr, 'a', [:static, '3']],
15
15
  [:html, :attr, 'b', [:static, '4']]]
16
- ]).should.equal [:html, :tag, 'meta',
16
+ ])).to eq [:html, :tag, 'meta',
17
17
  [:html, :attrs,
18
18
  [:html, :attr, 'a', [:static, '3']],
19
19
  [:html, :attr, 'b', [:static, '4']],
@@ -22,13 +22,13 @@ describe Temple::HTML::AttributeSorter do
22
22
  end
23
23
 
24
24
  it 'should preserve the order of html attributes when :sort_attrs is false' do
25
- @unordered.call([:html, :tag,
25
+ expect(@unordered.call([:html, :tag,
26
26
  'meta',
27
27
  [:html, :attrs, [:html, :attr, 'c', [:static, '1']],
28
28
  [:html, :attr, 'd', [:static, '2']],
29
29
  [:html, :attr, 'a', [:static, '3']],
30
30
  [:html, :attr, 'b', [:static, '4']]]
31
- ]).should.equal [:html, :tag, 'meta',
31
+ ])).to eq [:html, :tag, 'meta',
32
32
  [:html, :attrs,
33
33
  [:html, :attr, 'c', [:static, '1']],
34
34
  [:html, :attr, 'd', [:static, '2']],
@@ -36,11 +36,11 @@ describe Temple::HTML::AttributeSorter do
36
36
  [:html, :attr, 'b', [:static, '4']]]]
37
37
 
38
38
  # Use case:
39
- @unordered.call([:html, :tag,
39
+ expect(@unordered.call([:html, :tag,
40
40
  'meta',
41
41
  [:html, :attrs, [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
42
42
  [:html, :attr, 'content', [:static, '']]]
43
- ]).should.equal [:html, :tag, 'meta',
43
+ ])).to eq [:html, :tag, 'meta',
44
44
  [:html, :attrs,
45
45
  [:html, :attr, 'http-equiv', [:static, 'Content-Type']],
46
46
  [:html, :attr, 'content', [:static, '']]]]