-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
111 lines (89 loc) · 2.37 KB
/
test.js
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
import test from 'tape'
import {parse, stringify} from './index.js'
test('css-declarations', function (t) {
t.test('.parse()', function (st) {
st.equal(typeof parse, 'function', 'should be a method')
st.deepEqual(
parse(),
{},
'should return an empty object for an empty value'
)
st.deepEqual(
parse('\n\t\t '),
{},
'should return an empty object for white-space'
)
st.deepEqual(
parse('color: red; font-weight: bolder'),
{color: 'red', fontWeight: 'bolder'},
'should work'
)
st.deepEqual(
parse('-webkit-border-radius: 3px'),
{webkitBorderRadius: '3px'},
'should capitalise prefixes correctly'
)
st.deepEqual(
parse('/*background-*/color: /*purple*/red'),
{color: 'red'},
'should ignore comments correctly'
)
st.deepEqual(parse('/* comment */'), {}, 'should ignore just a comment')
st.deepEqual(
parse('@media (min-width: 1) { a { b: c} } '),
{},
'should ignore an at rule'
)
st.test('warnings', function (sst) {
var index = -1
var matrix = [
["missing '}'", 0],
["missing '{'", 10]
]
sst.plan(7)
/** Handler */
function warning() {
index++
sst.equal(arguments[0], matrix[index][0])
sst.equal(arguments[1], matrix[index][1])
sst.equal(arguments.length, 2)
}
sst.deepEqual(
parse('!important', {warning}),
{},
'should ignore invalid declarations'
)
})
st.end()
})
t.test('.stringify()', function (st) {
st.equal(typeof stringify, 'function', 'should be a method')
st.deepEqual(
stringify({}),
'',
'should return an empty string for an empty object'
)
st.deepEqual(
stringify({color: null, borderColor: undefined}),
'',
'should ignore `null` and `undefined` values'
)
st.deepEqual(
stringify({color: ''}),
'color: ;',
'should return an empty declaration for empty strings'
)
st.deepEqual(
stringify({color: 'red', backgroundColor: 'blue'}),
'color: red; background-color: blue;',
'should work'
)
st.deepEqual(
stringify({webkitBorderRadius: '3px !important'}),
'-webkit-border-radius: 3px !important;',
'should support prefixes'
)
st.end()
})
t.end()
})