This repository has been archived by the owner on Jun 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
test_preprocessor.coffee
72 lines (61 loc) · 1.94 KB
/
test_preprocessor.coffee
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
60
61
62
63
64
65
66
67
68
69
70
71
72
{preprocess} = require "../lib/preprocessor"
{fixture} = require "./lib/fixtures"
module.exports =
"preprocessing fixtures/hello.eco": (test) ->
test.same fixture("hello.coffee"), preprocess fixture("hello.eco")
test.done()
"preprocessing fixtures/projects.eco": (test) ->
test.same fixture("projects.coffee"), preprocess fixture("projects.eco")
test.done()
"preprocessing fixtures/helpers.eco": (test) ->
test.same fixture("helpers.coffee"), preprocess fixture("helpers.eco")
test.done()
"unexpected dedent": (test) ->
test.expect 1
try
preprocess """
<% if item = @items?[0]: %>
<%= item.price %>
<% end %>
<% end %>
"""
catch err
test.same "Parse error on line 4: unexpected dedent", err.toString()
test.done()
"unexpected newline in code block": (test) ->
test.expect 1
try
preprocess """
<%= item.price if
item = @items?[0] %>
"""
catch err
test.same "Parse error on line 1: unexpected newline in code block", err.toString()
test.done()
"unexpected end of template": (test) ->
test.expect 1
try
preprocess "<%= item.price"
catch err
test.same "Parse error on line 1: unexpected end of template", err.toString()
test.done()
"automatic captures use the same arrow as the function definition": (test) ->
output = preprocess "<% @foo -> %><br><% end %>"
test.ok output.match /capture ->/
output = preprocess "<% @foo => %><br><% end %>"
test.ok output.match /capture =>/
test.done()
"'end' dedents properly after an automatic capture": (test) ->
output = preprocess """
<ul>
<% @getItems (items) -> %>
<% for item in items: %>
<li><%= item.name %></li>
<% end %>
<% end %>
</ul>
"""
lines = output.split("\n")
test.same "", lines.pop()
test.ok lines.pop().match(/^\S/)
test.done()