-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.coffee
180 lines (154 loc) · 4.25 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
jcss = require './jcss.js'
render = jcss.render
fs = require 'fs'
assert = require('chai').assert
describe 'simple structures', ->
css =
'.class':
style1: 'value'
style2: 20
it 'plain styles', ->
res = """
.class {
style1: value;
style2: 20;
}
"""
assert.strictEqual render(css), res
it 'minified styles', ->
res = ".class{style1:value;style2:20;}"
assert.strictEqual render(css, true), res
describe 'multiselector', ->
it 'selectors', ->
css =
'.class1':
style1: 'value'
'.class2':
style2: 'value'
res = '.class1{style1:value;}.class2{style2:value;}';
assert.strictEqual render(css, true), res
describe 'hierarchy', ->
it 'normal join', ->
css =
'.class1':
style1: 'red'
'.class2':
style2: 'blue'
res = '.class1{style1:red;}.class1 .class2{style2:blue;}'
assert.strictEqual render(css, true), res
it 'left join', ->
css =
'.class1':
style1: 'red'
'&-inner2':
style2: 'blue'
res = '.class1{style1:red;}.class1-inner2{style2:blue;}'
assert.strictEqual render(css, true), res
it 'normal join', ->
css =
'.class1':
style1: 'red'
'.class2 &':
style2: 'blue'
res = '.class1{style1:red;}.class2 .class1{style2:blue;}'
assert.strictEqual render(css, true), res
describe 'difficult structure', ->
it 'split', ->
css =
'.class1|.class2':
style1: 'red'
'&-inner3|.class4 &':
style2: 'blue'
'-inner3':
'.class1&':
style2: 'green'
res = '.class1{style1:red;}.class1-inner3{style2:green;}.class4 .class1{style2:blue;}.class2{style1:red;}.class2-inner3{style2:blue;}.class4 .class2{style2:blue;}'
assert.strictEqual render(css, true), res
it 'extend', ->
css =
'.class1':
style1: 'red'
'.class2':
style1: 'blue'
'.class1':
style1: 'blue'
'.class2':
style: 'red'
res = '.class1{style1:blue;}.class1 .class2{style:red;}'
assert.strictEqual render(css, true), res
describe 'extra', ->
it '@media', ->
css =
'@media (max-width=980)':
'.class1':
style1: 'red'
'.class2':
style2: 'blue'
'.class1':
'@media (max-width=980)':
style1: 'blue'
'.class2':
style2: 'red'
res = '@media (max-width=980){.class1{style1:blue;}.class1 .class2{style2:red;}}'
assert.strictEqual render(css, true), res
it '@font-face', ->
css =
'@font-face': [
fontFamily: 'FontName1'
src: 'url(fontname1.otf)'
,
fontFamily: 'FontName2'
src: 'url(fontname2.otf)'
]
res = '@font-face{font-family:FontName1;src:url(fontname1.otf);}@font-face{font-family:FontName2;src:url(fontname2.otf);}'
assert.strictEqual render(css, true), res
it '@import', ->
css =
'@import': [
'url("one.css") all'
'url("two.css") all'
]
res = '@import url("one.css") all;@import url("two.css") all;'
assert.strictEqual render(css, true), res
describe 'mixins', ->
mixins = jcss.mixins
it 'simple', ->
css =
'.class1':
size: '200px 100px'
res = '.class1{width:200px;height:100px;}';
assert.strictEqual render(css, true), res
it 'define', ->
css =
'.class1':
borderRadius: '5px'
res = '.class1{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;}'
jcss.mixins =
borderRadius: (val) ->
WebkitBorderRadius: val
MozBorderRadius: val
borderRadius: val
assert.strictEqual render(css, true), res
jcss.mixins = mixins
it 'inserted', ->
css =
'.class1':
size: '200 100'
jcss.mixins =
size: mixins.size
width: (val) ->
width: val + 'px'
height: (val) ->
height: val + 'px'
res = '.class1{width:200px;height:100px;}'
assert.strictEqual render(css, true), res
jcss.mixins = mixins
describe 'custom object', ->
it 'example', ->
class Test
toString: -> '100px'
css =
'.class1':
width: new Test
res = '.class1{width:100px;}'
assert.strictEqual render(css, true), res