flavour_saver 0.3.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +26 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile.lock +34 -62
- data/README.md +3 -10
- data/flavour_saver.gemspec +14 -9
- data/lib/flavour_saver/helpers.rb +2 -4
- data/lib/flavour_saver/runtime.rb +5 -5
- data/lib/flavour_saver/version.rb +1 -1
- data/spec/acceptance/backtrack_spec.rb +1 -1
- data/spec/acceptance/comment_spec.rb +1 -1
- data/spec/acceptance/custom_block_helper_spec.rb +2 -2
- data/spec/acceptance/custom_helper_spec.rb +1 -1
- data/spec/acceptance/ensure_no_rce_spec.rb +2 -2
- data/spec/acceptance/handlebars_qunit_spec.rb +219 -219
- data/spec/acceptance/if_else_spec.rb +2 -2
- data/spec/acceptance/multi_level_with_spec.rb +1 -1
- data/spec/acceptance/one_character_identifier_spec.rb +2 -2
- data/spec/acceptance/raw_block_spec.rb +1 -1
- data/spec/acceptance/runtime_run_spec.rb +1 -1
- data/spec/acceptance/sections_spec.rb +3 -3
- data/spec/acceptance/segment_literals_spec.rb +3 -3
- data/spec/acceptance/simple_expression_spec.rb +3 -3
- data/spec/acceptance/subexpression_spec.rb +4 -5
- data/spec/lib/flavour_saver/lexer_spec.rb +36 -36
- data/spec/lib/flavour_saver/parser_spec.rb +91 -91
- data/spec/lib/flavour_saver/runtime_spec.rb +37 -37
- metadata +24 -75
- data/.travis.yml +0 -18
- data/Guardfile +0 -12
@@ -8,10 +8,10 @@ describe 'Fixture: if_else.hbs' do
|
|
8
8
|
|
9
9
|
it 'renders correctly when given a name' do
|
10
10
|
context.name = 'Alan'
|
11
|
-
subject.
|
11
|
+
expect(subject).to eq "Say hello to Alan."
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'renders correctly when not given a name' do
|
15
|
-
subject.
|
15
|
+
expect(subject).to eq "Nobody to say hi to."
|
16
16
|
end
|
17
17
|
end
|
@@ -9,7 +9,7 @@ describe 'Fixture: multi_level_with.hbs' do
|
|
9
9
|
it 'renders correctly when person has a name' do
|
10
10
|
context.person = Struct.new(:name).new('Alan')
|
11
11
|
context.company = Struct.new(:name).new('Rad, Inc.')
|
12
|
-
subject.
|
12
|
+
expect(subject).to eq 'Alan - Rad, Inc.'
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
@@ -7,7 +7,7 @@ describe 'Fixture: one_character_identifier.hbs' do
|
|
7
7
|
let(:context) { double(:context) }
|
8
8
|
|
9
9
|
it 'renders correctly' do
|
10
|
-
context.
|
11
|
-
subject.
|
10
|
+
expect(context).to receive(:a).and_return('foo')
|
11
|
+
expect(subject).to eq "foo"
|
12
12
|
end
|
13
13
|
end
|
@@ -8,18 +8,18 @@ describe 'Fixture: sections.hbs' do
|
|
8
8
|
|
9
9
|
it 'renders correctly when given a name' do
|
10
10
|
context.name = 'Alan'
|
11
|
-
subject.
|
11
|
+
expect(subject).to eq "Say hello to Alan."
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'renders correctly when given a list of names' do
|
15
15
|
context.names = ['Foo', 'Bar']
|
16
|
-
subject.
|
16
|
+
expect(subject).to eq "* Foo * Bar"
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'renders correctly when given an order' do
|
20
20
|
class Order; def number; 1234; end; end
|
21
21
|
context.order = Order.new
|
22
|
-
subject.
|
22
|
+
expect(subject).to eq 'Number: 1234'
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -17,10 +17,10 @@ describe FlavourSaver do
|
|
17
17
|
foos = []
|
18
18
|
foos << double(:foo)
|
19
19
|
foos << double(:foo)
|
20
|
-
foos[1].
|
20
|
+
expect(foos[1]).to receive(:bar).and_return('two')
|
21
21
|
|
22
|
-
context.
|
23
|
-
subject.
|
22
|
+
allow(context).to receive(:foos).and_return(foos)
|
23
|
+
expect(subject).to eq 'two'
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -7,11 +7,11 @@ describe 'Fixture: simple_expression.hbs' do
|
|
7
7
|
let(:context) { double(:context) }
|
8
8
|
|
9
9
|
it 'renders correctly' do
|
10
|
-
context.
|
11
|
-
subject.
|
10
|
+
expect(context).to receive(:hello).and_return('hello world')
|
11
|
+
expect(subject).to eq "hello world"
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'renders nothing if undefined' do
|
15
|
-
subject.
|
15
|
+
expect(subject).to eq ""
|
16
16
|
end
|
17
17
|
end
|
@@ -11,18 +11,18 @@ describe 'Subexpressions' do
|
|
11
11
|
end
|
12
12
|
context "simple subexpression" do
|
13
13
|
let(:template) { "{{sum 1 (sum 1 1)}}" }
|
14
|
-
specify{subject.
|
14
|
+
specify{expect(subject).to eq "3"}
|
15
15
|
end
|
16
16
|
|
17
17
|
context "nested subexpressions" do
|
18
18
|
let(:template) { "{{sum 1 (sum 1 (sum 1 1))}}" }
|
19
|
-
specify{subject.
|
19
|
+
specify{expect(subject).to eq "4"}
|
20
20
|
end
|
21
21
|
|
22
22
|
context "subexpression as argument" do
|
23
23
|
before {FlavourSaver.register_helper(:cents) { |a| a[:total] + 10}}
|
24
24
|
let(:template) { "{{cents total=(sum 1 1)}}" }
|
25
|
-
specify{subject.
|
25
|
+
specify{expect(subject).to eq "12"}
|
26
26
|
end
|
27
27
|
|
28
28
|
context "subexpression in block" do
|
@@ -32,7 +32,6 @@ describe 'Subexpressions' do
|
|
32
32
|
s
|
33
33
|
end}
|
34
34
|
let(:template) { "{{#repeat (sum 1 2)}}*{{/repeat}}" }
|
35
|
-
specify{subject.
|
35
|
+
specify{expect(subject).to eq "***"}
|
36
36
|
end
|
37
|
-
|
38
37
|
end
|
@@ -2,7 +2,7 @@ require 'flavour_saver/lexer'
|
|
2
2
|
|
3
3
|
describe FlavourSaver::Lexer do
|
4
4
|
it 'is an RLTK lexer' do
|
5
|
-
subject.
|
5
|
+
expect(subject).to be_a(RLTK::Lexer)
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'Tokens' do
|
@@ -11,17 +11,17 @@ describe FlavourSaver::Lexer do
|
|
11
11
|
subject { FlavourSaver::Lexer.lex "{{foo}}" }
|
12
12
|
|
13
13
|
it 'begins with an EXPRST' do
|
14
|
-
subject.first.type.
|
14
|
+
expect(subject.first.type).to eq :EXPRST
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'ends with an EXPRE' do
|
18
|
-
subject[-2].type.
|
18
|
+
expect(subject[-2].type).to eq :EXPRE
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'contains only the identifier "foo"' do
|
22
|
-
subject[1..-3].size.
|
23
|
-
subject[1].type.
|
24
|
-
subject[1].value.
|
22
|
+
expect(subject[1..-3].size).to eq 1
|
23
|
+
expect(subject[1].type).to eq :IDENT
|
24
|
+
expect(subject[1].value).to eq 'foo'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,11 +29,11 @@ describe FlavourSaver::Lexer do
|
|
29
29
|
subject { FlavourSaver::Lexer.lex "{{foo bar}}" }
|
30
30
|
|
31
31
|
it 'has tokens in the correct order' do
|
32
|
-
subject.map(&:type).
|
32
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :IDENT, :WHITE, :IDENT, :EXPRE, :EOS ]
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'has values in the correct order' do
|
36
|
-
subject.map(&:value).compact.
|
36
|
+
expect(subject.map(&:value).compact).to eq [ 'foo', 'bar' ]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -41,11 +41,11 @@ describe FlavourSaver::Lexer do
|
|
41
41
|
subject { FlavourSaver::Lexer.lex "{{foo \"bar\"}}" }
|
42
42
|
|
43
43
|
it 'has tokens in the correct order' do
|
44
|
-
subject.map(&:type).
|
44
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :IDENT, :WHITE, :STRING, :EXPRE, :EOS ]
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'has values in the correct order' do
|
48
|
-
subject.map(&:value).compact.
|
48
|
+
expect(subject.map(&:value).compact).to eq [ 'foo', 'bar' ]
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -53,11 +53,11 @@ describe FlavourSaver::Lexer do
|
|
53
53
|
subject { FlavourSaver::Lexer.lex "{{foo (bar 'baz')}}" }
|
54
54
|
|
55
55
|
it 'has tokens in the correct order' do
|
56
|
-
subject.map(&:type).
|
56
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :IDENT, :WHITE, :OPAR, :IDENT, :WHITE, :S_STRING, :CPAR, :EXPRE, :EOS ]
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'has values in the correct order' do
|
60
|
-
subject.map(&:value).compact.
|
60
|
+
expect(subject.map(&:value).compact).to eq [ 'foo', 'bar', 'baz' ]
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -65,11 +65,11 @@ describe FlavourSaver::Lexer do
|
|
65
65
|
subject { FlavourSaver::Lexer.lex '{{foo bar="baz" hello="goodbye"}}' }
|
66
66
|
|
67
67
|
it 'has tokens in the correct order' do
|
68
|
-
subject.map(&:type).
|
68
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :IDENT, :WHITE, :IDENT, :EQ, :STRING, :WHITE, :IDENT, :EQ, :STRING, :EXPRE, :EOS ]
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'has values in the correct order' do
|
72
|
-
subject.map(&:value).compact.
|
72
|
+
expect(subject.map(&:value).compact).to eq [ 'foo', 'bar', 'baz', 'hello', 'goodbye' ]
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
@@ -81,8 +81,8 @@ describe FlavourSaver::Lexer do
|
|
81
81
|
ids = %w( _ __ __123__ __ABC__ ABC123 Abc134def )
|
82
82
|
ids.each do |id|
|
83
83
|
subject = FlavourSaver::Lexer.lex "{{#{id}}}"
|
84
|
-
subject[1].type.
|
85
|
-
subject[1].value.
|
84
|
+
expect(subject[1].type).to eq :IDENT
|
85
|
+
expect(subject[1].value).to eq id
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -90,8 +90,8 @@ describe FlavourSaver::Lexer do
|
|
90
90
|
ids = %w( A-B 12_Mine - :example 0A test? )
|
91
91
|
ids.each do |id|
|
92
92
|
subject = FlavourSaver::Lexer.lex "{{#{id}}}"
|
93
|
-
subject[1].type.
|
94
|
-
subject[1].value.
|
93
|
+
expect(subject[1].type).to eq :LITERAL
|
94
|
+
expect(subject[1].value).to eq id
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -100,11 +100,11 @@ describe FlavourSaver::Lexer do
|
|
100
100
|
subject { FlavourSaver::Lexer.lex '{{foo bar=(baz qux)}}' }
|
101
101
|
|
102
102
|
it 'has tokens in the correct order' do
|
103
|
-
subject.map(&:type).
|
103
|
+
expect(subject.map(&:type)).to eq [:EXPRST, :IDENT, :WHITE, :IDENT, :EQ, :OPAR, :IDENT, :WHITE, :IDENT, :CPAR, :EXPRE, :EOS]
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'has values in the correct order' do
|
107
|
-
subject.map(&:value).compact.
|
107
|
+
expect(subject.map(&:value).compact).to eq [ 'foo', 'bar', 'baz', 'qux' ]
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -112,7 +112,7 @@ describe FlavourSaver::Lexer do
|
|
112
112
|
subject { FlavourSaver::Lexer.lex '{{else}}' }
|
113
113
|
|
114
114
|
it 'has tokens in the correct order' do
|
115
|
-
subject.map(&:type).
|
115
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :ELSE, :EXPRE, :EOS ]
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -121,11 +121,11 @@ describe FlavourSaver::Lexer do
|
|
121
121
|
subject { FlavourSaver::Lexer.lex "{{foo.bar}}" }
|
122
122
|
|
123
123
|
it 'has tokens in the correct order' do
|
124
|
-
subject.map(&:type).
|
124
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :IDENT, :DOT, :IDENT, :EXPRE, :EOS ]
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'has the correct values' do
|
128
|
-
subject.map(&:value).compact.
|
128
|
+
expect(subject.map(&:value).compact).to eq ['foo', 'bar']
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -133,11 +133,11 @@ describe FlavourSaver::Lexer do
|
|
133
133
|
subject { FlavourSaver::Lexer.lex "{{foo.[10].bar}}" }
|
134
134
|
|
135
135
|
it 'has tokens in the correct order' do
|
136
|
-
subject.map(&:type).
|
136
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :IDENT, :DOT, :LITERAL, :DOT, :IDENT, :EXPRE, :EOS ]
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'has the correct values' do
|
140
|
-
subject.map(&:value).compact.
|
140
|
+
expect(subject.map(&:value).compact).to eq ['foo', '10', 'bar']
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -145,11 +145,11 @@ describe FlavourSaver::Lexer do
|
|
145
145
|
subject { FlavourSaver::Lexer.lex '{{foo.[he!@#$(&@klA)].bar}}' }
|
146
146
|
|
147
147
|
it 'has tokens in the correct order' do
|
148
|
-
subject.map(&:type).
|
148
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :IDENT, :DOT, :LITERAL, :DOT, :IDENT, :EXPRE, :EOS ]
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'has the correct values' do
|
152
|
-
subject.map(&:value).compact.
|
152
|
+
expect(subject.map(&:value).compact).to eq ['foo', 'he!@#$(&@klA)', 'bar']
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
@@ -158,7 +158,7 @@ describe FlavourSaver::Lexer do
|
|
158
158
|
subject { FlavourSaver::Lexer.lex "{{{foo}}}" }
|
159
159
|
|
160
160
|
it 'has tokens in the correct order' do
|
161
|
-
subject.map(&:type).
|
161
|
+
expect(subject.map(&:type)).to eq [ :TEXPRST, :IDENT, :TEXPRE, :EOS ]
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -166,7 +166,7 @@ describe FlavourSaver::Lexer do
|
|
166
166
|
subject { FlavourSaver::Lexer.lex "{{! WAT}}" }
|
167
167
|
|
168
168
|
it 'has tokens in the correct order' do
|
169
|
-
subject.map(&:type).
|
169
|
+
expect(subject.map(&:type)).to eq [ :EXPRST, :BANG, :COMMENT, :EXPRE, :EOS ]
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
@@ -174,7 +174,7 @@ describe FlavourSaver::Lexer do
|
|
174
174
|
subject { FlavourSaver::Lexer.lex "{{../foo}}" }
|
175
175
|
|
176
176
|
it 'has tokens in the correct order' do
|
177
|
-
subject.map(&:type).
|
177
|
+
expect(subject.map(&:type)).to eq [:EXPRST, :DOT, :DOT, :FWSL, :IDENT, :EXPRE, :EOS]
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
@@ -182,7 +182,7 @@ describe FlavourSaver::Lexer do
|
|
182
182
|
subject { FlavourSaver::Lexer.lex "{{foo}}\n{{bar}}\r{{baz}}" }
|
183
183
|
|
184
184
|
it 'has tokens in the correct order' do
|
185
|
-
subject.map(&:type).
|
185
|
+
expect(subject.map(&:type)).to eq [:EXPRST,:IDENT,:EXPRE,:OUT,:EXPRST,:IDENT,:EXPRE,:OUT,:EXPRST,:IDENT,:EXPRE,:EOS]
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -191,7 +191,7 @@ describe FlavourSaver::Lexer do
|
|
191
191
|
|
192
192
|
describe '{{#foo}}{{bar}}{{/foo}}' do
|
193
193
|
it 'has tokens in the correct order' do
|
194
|
-
subject.map(&:type).
|
194
|
+
expect(subject.map(&:type)).to eq [
|
195
195
|
:EXPRST, :HASH, :IDENT, :EXPRE,
|
196
196
|
:EXPRST, :IDENT, :EXPRE,
|
197
197
|
:EXPRST, :FWSL, :IDENT, :EXPRE,
|
@@ -200,7 +200,7 @@ describe FlavourSaver::Lexer do
|
|
200
200
|
end
|
201
201
|
|
202
202
|
it 'has identifiers in the correct order' do
|
203
|
-
subject.map(&:value).compact.
|
203
|
+
expect(subject.map(&:value).compact).to eq [ 'foo', 'bar', 'foo' ]
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
@@ -209,7 +209,7 @@ describe FlavourSaver::Lexer do
|
|
209
209
|
subject { FlavourSaver::Lexer.lex "\r" }
|
210
210
|
|
211
211
|
it 'has tokens in the correct order' do
|
212
|
-
subject.map(&:type).
|
212
|
+
expect(subject.map(&:type)).to eq [:OUT,:EOS]
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -217,7 +217,7 @@ describe FlavourSaver::Lexer do
|
|
217
217
|
subject { FlavourSaver::Lexer.lex "\n" }
|
218
218
|
|
219
219
|
it 'has tokens in the correct order' do
|
220
|
-
subject.map(&:type).
|
220
|
+
expect(subject.map(&:type)).to eq [:OUT,:EOS]
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -225,7 +225,7 @@ describe FlavourSaver::Lexer do
|
|
225
225
|
subject { FlavourSaver::Lexer.lex "{" }
|
226
226
|
|
227
227
|
it 'has tokens in the correct order' do
|
228
|
-
subject.map(&:type).
|
228
|
+
expect(subject.map(&:type)).to eq [:OUT,:EOS]
|
229
229
|
end
|
230
230
|
end
|
231
231
|
end
|