forked from gregwebs/hamlet.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.coffee
133 lines (112 loc) · 2.8 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Hamlet = this.Hamlet
t = (a, b) =>
h = Hamlet.toHtml(b).replace(/\n/g, " ")
if a != h
console.log("from:\n" + b + "\n\nnot equal:\n" + a + "\n" + h)
# class shortcut and class attribute
t '<div class="guide-entry {{zebra(episode)}}"></div>', """
<.guide-entry class="{{zebra(episode)}}">
"""
# id and class shortcut next to tag with no spaces
t '<a id="btn" class="watchlist" href="#">Add to Favorites</a>', """
<a#btn.watchlist href="#">
Add to Favorites
"""
# class shortcut next to tag with no spaces
t '<a class="btn-watchlist" href="#">Add to Favorites</a>', """
<a.btn-watchlist href="#">
Add to Favorites
"""
# multiple classes
t '<div class="foo bar"></div>', """
<.foo.bar>
"""
# dot in class field
t '<p class="foo.bar"><div id="bar">baz</div></p>', """
<p class=foo.bar
<#bar>baz
"""
# id shortcut next to tag with no spaces
t '<a id="btn-watchlist" href="#">Add to Favorites</a>', """
<a#btn-watchlist href="#">
Add to Favorites
"""
# basic tests
t("<div></div>", "<div>")
t('<span>%{foo}</span>', '<span>%{foo}')
# multiple tags at same level
t('<div class="actions bottom-row"><a class="like" href="#">Like</a></div><div class="likes bottom-row"><a class="likes" href="#">387 people</a> like this</a></div>',"""
<div class="actions bottom-row">
<a class="like" href="#">Like
<div class="likes bottom-row">
<a class="likes" href="#">387 people</a> like this
""")
# html entities
t('<a class="open-post" href="{{fb_item_link(feed)}}" target="blank">↗</a>',
'<a class="open-post" href="{{fb_item_link(feed)}}" target="blank">↗'
)
# dashed attribute
t('<div class="klass" ng-controller="Controller"></div>',
"<.klass ng-controller=Controller>")
# id & class shortcuts
t '<p class="foo"><div id="bar">baz </div></p>', """
<p .foo>
<#bar>baz ## this is a comment
"""
# multiple lines of text
t "<div>foo bar</div>", """
<div>
foo
bar
"""
# tag spacing lines of text - this doesn't seem correct really :)
t "<ul><li><a>foo</a> <a>foo2</a></li><li><a>bar</a></li></ul>", """
<ul>
<li>
<a>foo
<a>foo2
<li>
<a>
bar
"""
t '<p>You are logged in as <i>Greg</i> <b>Weber</b>, <a href="/logout">logout</a>.</p><p>Multi line paragraph.</p>', """
<p>You are logged in as
<i>Greg
<b>Weber
>,
<a href="/logout">logout
>.
><p>Multi
line
paragraph.
"""
t '<i>No</i><b>Space</b>', '''
<i>No
><b>Space
'''
t '<p>No close bracket</p> <p>No close</p>', '''
<p
No close bracket
<p
No close
'''
t '<img></img><p>No close</p>', '''
<img
<p
No close
'''
t '<p><b>no space</b>none here either. Two spaces after a period is bad!</p>', '''
<p>
<b>no space
>none here either.
> Two spaces after a period is bad!
'''
interp = =>
r = Hamlet('#{foo} #{bar}',
foo : "a"
bar : "b"
)
unless "a b" == r
console.log("Fail: " + r)
interp()
###