Inital Commit
[oweals/finalsclub.git] / node_modules / jade / benchmarks / haml / spec / unit / spec.js
1
2 describe 'haml'
3   describe '.version'
4     it 'should be a triplet'
5       haml.version.should.match(/^\d+\.\d+\.\d+$/)
6     end
7   end
8   
9   describe '.render()'
10     before
11       assertAs = function(name, type, options) {
12         var str = fixture(name + '.haml')
13         try {
14           var html = haml.render(str, options).trim(),
15               expected = fixture(name + '.' + type).trim()
16           if (html === expected)
17             pass()
18           else
19             fail('got:\n' + html + '\n\nexpected:\n' + expected)
20         } catch (err) {
21           if (err instanceof haml.HamlError) {
22             throw err
23           } else {
24             fail('\n:' + err.stack + '\n')
25           }
26         }
27       }
28       assert = function(name, options) {
29         assertAs(name, 'html', options, 'CRLF', '\r\n')
30       }
31       assertXML = function(name, options) {
32         assertAs(name, 'xml', options, 'CRLF', '\r\n')
33       }
34     end
35     
36     it 'should allow passing of a context object'
37       assert('context', { context: 'yay' })
38     end
39     
40     it 'should allow passing of literals'
41       assert('literals', { locals: { user: 'tj' }})
42     end
43     
44     it 'should not fail on trailing indents'
45       assert('trailing-indent')
46     end
47     
48     it 'should add xml support via the "xml" option'
49       assertXML('feed', { xml: true })
50     end
51     
52     it 'should support xml namespaces'
53       assertXML('namespace')
54     end
55     
56     it 'should utilize "filename" option when an error is thrown'
57       try { assert('error', { filename: 'error.haml' }) }
58       catch (err) {
59         err.message.should.eql '(error.haml):3 invalid indentation; got 3, when previous was 1'
60       }
61     end
62     
63     it 'should default filename to "Haml" when an error is thrown'
64       try { assert('error') }
65       catch (err) {
66         err.message.should.eql '(Haml):3 invalid indentation; got 3, when previous was 1'
67       }
68     end
69     
70     it 'should bitch when "cache" is true without a filename given'
71       // -{ assert('tag.simple', { cache: true }) }.should.throw_error
72     end
73     
74     it 'should pre-compiled and cache when "cache" is true'
75       assert('tag.simple', { cache: true, filename: 'tag.simple.haml' })
76       assert('tag.simple', { cache: true, filename: 'tag.simple.haml' })
77     end
78     
79     it 'should support blank lines'
80       assert('newlines')
81     end
82     
83     describe '.class'
84       it 'should output a div with the given class'
85         assert('class')
86       end
87       
88       it 'should work with several classes'
89         assert('classes')
90       end
91     end
92     
93     describe '#id'
94       it 'should output a div with the given id'
95         assert('id')
96       end
97     end
98     
99     describe '%tag'
100       it 'should work with no text or block'
101         assert('tag.simple')
102       end
103       
104       it 'should work with text'
105         assert('tag.text')
106       end
107       
108       it 'should work with block text'
109         assert('tag.text.block')
110       end
111       
112       it 'should work with blocks of text and tags'
113         assert('tag.text.block.complex')
114       end
115       
116       it 'should work with many classes / ids / attrs'
117         assert('tag.complex')
118       end
119       
120       it 'should allow empty tags'
121         assert('tag.empty')
122       end
123     end
124     
125     describe '%tag.class'
126       it 'should output tag with a class'
127         assert('tag.class')
128       end
129       
130       it 'should work with several classes'
131         assert('tag.classes')
132       end
133       
134       it 'should support self-closing tags'
135         assert('tag.self-close')
136       end
137     end
138     
139     describe '%tag!='
140       it 'should output the evaluated code'
141         assert('tag.code')
142       end
143       
144       it 'should not escape output'
145         assert('tag.code.no-escape')
146       end
147     end
148     
149     describe '%tag='
150       it 'should escape the evaluated code'
151         assert('tag.escape')
152       end
153     end
154     
155     describe '%namespace:tag'
156       it 'should output a tag with a namespace prefix'
157         assert('namespace.tag')
158       end
159     end
160     
161     describe '{...}'
162       it 'should be mapped as html attributes'
163         assert('tag.attrs')
164       end
165       
166       it 'should escape values'
167         assert('tag.attrs.escape')
168       end
169       
170       it 'should allow booleans'
171         assert('tag.attrs.bools')
172       end
173     end
174     
175     describe '!!!'
176       it 'should default the doctype to 1.0 transitional'
177         assert('doctype')
178       end
179     end
180     
181     describe '!!! NAME'
182       it 'should output a specific doctype'
183         assert('doctype.xml')
184       end
185       
186       it 'should be case-insensitive'
187         assert('doctype.xml.case')
188       end
189     end
190     
191     describe 'nesting'
192       it 'should work when nested downwards'
193         assert('nesting.simple')
194       end
195       
196       it 'should work when blocks outdent'
197         assert('nesting.complex')
198       end
199     end
200     
201     describe '- code'
202       it 'should work with if statements'
203         assert('code.if')
204       end
205       
206       it 'should work when nested'
207         assert('code.nested')
208       end
209     end
210     
211     describe '- each'
212       it 'should iterate'
213         assert('code.each', { locals: { items: ['one', 'two', 'three'] }})
214         assert('code.each.non-enumerable', { locals: { items: null }})
215       end
216       
217       it 'should iterate objects'
218         assert('code.each', { locals: { items: { 0: 'one', 1: 'two', 2: 'three' }}})
219         assert('code.each.index', { locals: { items: { 0: 'one', 1: 'two', 2: 'three' }}})
220       end
221       
222       it 'should iterate with index'
223         assert('code.each.index', { locals: { items: ['one', 'two', 'three'] }})
224       end
225     end
226     
227     describe '= code'
228       it 'should output evaluation'
229         assert('code')
230       end
231     end
232     
233     describe '&= code'
234       it 'should output evaluation while escaping html entities'
235         assert('code.escape')
236       end
237     end
238     
239     describe '<literal></html>'
240       it 'should remain intact'
241         assert('html')
242       end
243     end
244     
245     describe '\\char'
246       it 'should escape the character'
247         assert('escape')
248       end
249     end
250     
251     describe '-#'
252       it 'should become a silent comment'
253         assert('comment')
254       end
255     end
256     
257     describe '/'
258       it 'should comment out tags'
259         assert('comment.tag')
260       end
261       
262       it 'should comment out blocks'
263         assert('comment.block')
264       end
265       
266       it 'should comment out text'
267         assert('comment.text')
268       end
269       
270       it 'should work in blocks'
271         assert('comment.text.complex')
272       end
273     end
274     
275     describe '/[]'
276       it 'should insert conditional comment blocks'
277         assert('comment.block.conditional')
278       end
279     end
280
281     describe ':filter'
282       describe 'plain'
283         it 'should ignore haml specific characters'
284           assert('filter.plain')
285         end
286       end
287     
288       describe 'cdata'
289         it 'should wrap with CDATA tags'
290           assert('filter.cdata')
291         end
292         
293         it 'should retain whitespace'
294           assert('filter.cdata.whitespace')
295         end
296       end
297       
298       describe 'javascript'
299         it 'should wrap with <script> and CDATA tags'
300           assert('filter.javascript')
301         end
302       end
303     end
304     
305     describe 'bug fixes'
306       it '#8 code block'
307         assert('issue.#8', { locals: { items: ['foo', 'bar', 'baz'] }})
308       end
309       
310       it '#10 Attributes should not need quotes'
311         assert('issue.#10')
312       end
313     end
314     
315   end
316 end