-
Notifications
You must be signed in to change notification settings - Fork 18
/
xresources.js
203 lines (153 loc) · 4.39 KB
/
xresources.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
'use strict';
var fs = require('fs');
var assert = require('chai').assert;
var same = require('../utils/same');
var defaults = require('../../lib/formats/defaults');
var xresources = require('../../lib/formats/xresources');
describe('formats/xresources', function () {
var COLORS = defaults.colors;
var OUTPUT = fs.readFileSync(__dirname + '/../../examples/xresources.txt', 'utf8');
describe('.import', function () {
it('should parse configuration', function () {
var actual = xresources.import(OUTPUT);
same(actual, COLORS);
});
it('should parse foreground and background colors', function () {
var actual = xresources.import(
'background: #BADA55 \n'+
'foreground: #C0FFEE \n'
);
var expected = {
background: '#bada55',
foreground: '#c0ffee'
};
same(actual, expected);
});
it('should parse different prefixes', function () {
var actual = xresources.import(
'color0 : #000000 \n'+
'*color1 : #111111 \n'+
'*.color2 : #222222 \n'+
'aterm.color3 : #333333 \n'+
'xterm*color4 : #444444 \n'+
'urxvt*color5 : #555555 \n'+
'URxvt.color6 : #666666 \n'+
'URxvt*color7 : #777777 \n'
);
var expected = {
0: '#000000',
1: '#111111',
2: '#222222',
3: '#333333',
4: '#444444',
5: '#555555',
6: '#666666',
7: '#777777',
};
same(actual, expected);
});
it('should ignore invalid color names', function () {
var actual = xresources.import(
'color20: #012345 \n'+
'.color-1: #123456 \n'+
'*color00: #234567 \n'+
'urxvt.color16: #345678 \n'+
'urxvt*someground: #456789 \n'+
'URxvt.backfore: #56789A \n'+
'URxvt*99: #6789AB \n'+
'xpdf.background: #cccaaa'
);
var expected = {};
same(actual, expected);
});
it('should replace definitions', function () {
var actual = xresources.import(
'#define red #FF0000 \n'+
'#define green #00FF00 \n'+
'#define yellow #00FFFF \n'+
'color1: red \n' +
'color2: green \n' +
'color3: yellow \n' +
'color4: missing \n' +
'color9: red \n'
);
var expected = {
1: '#ff0000',
2: '#00ff00',
3: '#00ffff',
9: '#ff0000'
};
same(actual, expected);
});
it('should ignore comments', function () {
var actual = xresources.import(
'color1: #FF0000 \n'+
'! color1: #000000 \n'
);
var expected = {
1: '#ff0000'
};
same(actual, expected);
});
it('should only ignore partial words', function () {
var actual = xresources.import(
'color2: #FF0000 \n'+
'cursorColor2: #000000 \n'
);
var expected = {
2: '#ff0000'
};
same(actual, expected);
});
it('should replace definitions properly', function () {
var actual = xresources.import(
'#define x #AAAAAA \n'+
'#define xx #BBBBBB \n'+
'#define background #CCCCCC \n'+
'*.background: background \n'+
'*.color0: x \n'+
'*.color1: xx \n'
);
var expected = {
0: '#aaaaaa',
1: '#bbbbbb',
background: '#cccccc'
};
same(actual, expected);
});
it('should ignore opacity', function () {
var actual = xresources.import(
'background: [20] #AAAAAA \n'+
'foreground:[90]#CCCCCC \n'+
'urxvt.color0: [100]#123000'
);
var expected = {
background: '#aaaaaa',
foreground: '#cccccc',
0: '#123000'
};
same(actual, expected);
});
it('should parse rgb:a/b/c colors', function () {
var actual = xresources.import(
'background: rgb:a/b/c \n' +
'foreground: rgb:c0/af/21 \n' +
'urxvt.color0: rgb:d/9f/a \n' +
'urxvt.color1: rgb:00/11/22'
);
var expected = {
background: '#aabbcc',
foreground: '#c0af21',
0: '#dd9faa',
1: '#001122'
};
same(actual, expected);
});
});
describe('.export', function () {
it('should export as guake', function () {
var actual = xresources.export(COLORS);
same(actual, OUTPUT);
});
});
});