@jdeighan/coffee-utils 4.1.4 → 4.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,319 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // utils.test.coffee
3
- var hEsc, simple;
4
-
5
- import {
6
- UnitTester
7
- } from '@jdeighan/coffee-utils/test';
8
-
9
- import {
10
- say,
11
- undef,
12
- error,
13
- warn,
14
- isString,
15
- isObject,
16
- isArray,
17
- isHash,
18
- isEmpty,
19
- nonEmpty,
20
- isComment,
21
- getClassName,
22
- isNumber,
23
- isFunction,
24
- isInteger,
25
- rtrim,
26
- ltrunc,
27
- rtrunc,
28
- extractMatches,
29
- words,
30
- escapeStr,
31
- titleLine,
32
- removeCR,
33
- CWS,
34
- isArrayOfHashes,
35
- oneline,
36
- croak,
37
- isRegExp
38
- } from '@jdeighan/coffee-utils';
39
-
40
- import {
41
- setLogger
42
- } from '@jdeighan/coffee-utils/log';
43
-
44
- import {
45
- setDebugging
46
- } from '@jdeighan/coffee-utils/debug';
47
-
48
- import {
49
- arrayToBlock
50
- } from '@jdeighan/coffee-utils/block';
51
-
52
- simple = new UnitTester();
53
-
54
- // ---------------------------------------------------------------------------
55
- simple.truthy(19, isEmpty(''));
56
-
57
- simple.truthy(20, isEmpty(' \t\t'));
58
-
59
- simple.truthy(21, isEmpty([]));
60
-
61
- simple.truthy(22, isEmpty({}));
62
-
63
- simple.truthy(24, nonEmpty('a'));
64
-
65
- simple.truthy(25, nonEmpty('.'));
66
-
67
- simple.truthy(26, nonEmpty([2]));
68
-
69
- simple.truthy(27, nonEmpty({
70
- width: 2
71
- }));
72
-
73
- simple.truthy(29, isComment("# a comment"));
74
-
75
- simple.truthy(30, isComment("### a comment"));
76
-
77
- simple.truthy(31, isComment("#\ta comment"));
78
-
79
- simple.truthy(32, isComment("###\ta comment"));
80
-
81
- simple.truthy(33, isComment(" # a comment"));
82
-
83
- simple.truthy(34, isComment(" ### a comment"));
84
-
85
- simple.falsy(35, isComment("not much"));
86
-
87
- simple.falsy(36, isComment("#foreach x in lItems"));
88
-
89
- simple.truthy(37, isComment('#'));
90
-
91
- simple.truthy(38, isComment(' #'));
92
-
93
- simple.truthy(39, isComment(' ###'));
94
-
95
- simple.falsy(40, isComment('#for'));
96
-
97
- simple.falsy(41, isComment(' #for'));
98
-
99
- simple.falsy(42, isComment('#for line in lLines'));
100
-
101
- simple.equal(44, titleLine('a thing').length, 42);
102
-
103
- simple.equal(45, titleLine('a thing', '-', 5, 90).length, 90);
104
-
105
- // ---------------------------------------------------------------------------
106
- simple.equal(80, rtrim("abc"), "abc");
107
-
108
- simple.equal(81, rtrim(" abc"), " abc");
109
-
110
- simple.equal(82, rtrim("abc "), "abc");
111
-
112
- simple.equal(83, rtrim(" abc "), " abc");
113
-
114
- // ---------------------------------------------------------------------------
115
- simple.equal(87, words('a b c'), ['a', 'b', 'c']);
116
-
117
- simple.equal(88, words(' a b c '), ['a', 'b', 'c']);
118
-
119
- // ---------------------------------------------------------------------------
120
- simple.equal(92, escapeStr("\t\tXXX\n"), "\\t\\tXXX\\n");
121
-
122
- hEsc = {
123
- "\n": "\\n",
124
- "\t": "\\t",
125
- "\"": "\\\""
126
- };
127
-
128
- simple.equal(64, escapeStr("\thas quote: \"\nnext line", hEsc), "\\thas quote: \\\"\\nnext line");
129
-
130
- // ---------------------------------------------------------------------------
131
- simple.equal(130, rtrunc('/user/lib/.env', 5), '/user/lib');
132
-
133
- simple.equal(131, ltrunc('abcdefg', 3), 'defg');
134
-
135
- simple.equal(133, removeCR("abc\r\ndef\r\n"), "abc\ndef\n");
136
-
137
- simple.equal(139, CWS(`abc
138
- def
139
- ghi`), "abc def ghi");
140
-
141
- // ---------------------------------------------------------------------------
142
- simple.truthy(147, isArrayOfHashes([]));
143
-
144
- simple.truthy(148, isArrayOfHashes([{}, {}]));
145
-
146
- simple.truthy(149, isArrayOfHashes([
147
- {
148
- a: 1,
149
- b: 2
150
- },
151
- {}
152
- ]));
153
-
154
- simple.truthy(150, isArrayOfHashes([
155
- {
156
- a: 1,
157
- b: 2,
158
- c: [1,
159
- 2,
160
- 3]
161
- },
162
- {}
163
- ]));
164
-
165
- simple.falsy(152, isArrayOfHashes({}));
166
-
167
- simple.falsy(153, isArrayOfHashes([1, 2, 3]));
168
-
169
- simple.falsy(154, isArrayOfHashes([
170
- {
171
- a: 1,
172
- b: 2,
173
- c: [1,
174
- 2,
175
- 3]
176
- },
177
- 4
178
- ]));
179
-
180
- simple.falsy(155, isArrayOfHashes([
181
- {
182
- a: 1,
183
- b: 2,
184
- c: [1,
185
- 2,
186
- 3]
187
- },
188
- {},
189
- [1,
190
- 2]
191
- ]));
192
-
193
- // ---------------------------------------------------------------------------
194
- (function() {
195
- var NewClass, h, l, n, n2, o, s, s2;
196
- NewClass = class NewClass {};
197
- h = {
198
- a: 1,
199
- b: 2
200
- };
201
- l = [1, 2, 2];
202
- o = new NewClass();
203
- n = 42;
204
- n2 = new Number(42);
205
- s = 'simple';
206
- s2 = new String('abc');
207
- simple.truthy(170, isHash(h));
208
- simple.falsy(171, isHash(l));
209
- simple.falsy(172, isHash(o));
210
- simple.falsy(173, isHash(n));
211
- simple.falsy(174, isHash(n2));
212
- simple.falsy(175, isHash(s));
213
- simple.falsy(176, isHash(s2));
214
- simple.falsy(178, isArray(h));
215
- simple.truthy(179, isArray(l));
216
- simple.falsy(180, isArray(o));
217
- simple.falsy(181, isArray(n));
218
- simple.falsy(182, isArray(n2));
219
- simple.falsy(183, isArray(s));
220
- simple.falsy(184, isArray(s2));
221
- simple.falsy(186, isString(h));
222
- simple.falsy(187, isString(l));
223
- simple.falsy(188, isString(o));
224
- simple.falsy(189, isString(n));
225
- simple.falsy(190, isString(n2));
226
- simple.truthy(191, isString(s));
227
- simple.truthy(192, isString(s2));
228
- simple.falsy(194, isObject(h));
229
- simple.falsy(195, isObject(l));
230
- simple.truthy(196, isObject(o));
231
- simple.falsy(197, isObject(n));
232
- simple.falsy(198, isObject(n2));
233
- simple.falsy(199, isObject(s));
234
- simple.falsy(200, isObject(s2));
235
- simple.falsy(202, isNumber(h));
236
- simple.falsy(203, isNumber(l));
237
- simple.falsy(204, isNumber(o));
238
- simple.truthy(205, isNumber(n));
239
- simple.truthy(206, isNumber(n2));
240
- simple.falsy(207, isNumber(s));
241
- return simple.falsy(208, isNumber(s2));
242
- })();
243
-
244
- // ---------------------------------------------------------------------------
245
- simple.truthy(214, isFunction(function() {
246
- return pass;
247
- }));
248
-
249
- simple.falsy(215, isFunction(23));
250
-
251
- simple.truthy(217, isInteger(42));
252
-
253
- simple.truthy(218, isInteger(new Number(42)));
254
-
255
- simple.falsy(219, isInteger('abc'));
256
-
257
- simple.falsy(220, isInteger({}));
258
-
259
- simple.falsy(221, isInteger([]));
260
-
261
- // ---------------------------------------------------------------------------
262
- simple.equal(233, oneline(undef), "undef");
263
-
264
- simple.equal(234, oneline("\t\tabc\nxyz"), "'\\t\\tabc\\nxyz'");
265
-
266
- simple.equal(235, oneline({
267
- a: 1,
268
- b: 'xyz'
269
- }), '{"a":1,"b":"xyz"}');
270
-
271
- // ---------------------------------------------------------------------------
272
- simple.equal(239, CWS(`a simple
273
- error message`), "a simple error message");
274
-
275
- // ---------------------------------------------------------------------------
276
- // test croak()
277
- (function() {
278
- var lLines, obj;
279
- lLines = [];
280
- setLogger(function(line) {
281
- return lLines.push(line);
282
- });
283
- obj = {
284
- a: 1,
285
- b: 2
286
- };
287
- try {
288
- croak("bad stuff", "An Object", obj);
289
- } catch (error1) {}
290
- simple.equal(255, arrayToBlock(lLines), `ERROR: bad stuff
291
- An Object = {"a":1,"b":2}`);
292
- return setLogger();
293
- })();
294
-
295
- // ---------------------------------------------------------------------------
296
- // test isRegExp()
297
- simple.truthy(265, isRegExp(/^abc$/));
298
-
299
- simple.truthy(266, isRegExp(/^\s*where\s+areyou$/));
300
-
301
- simple.falsy(272, isRegExp(42));
302
-
303
- simple.falsy(272, isRegExp('abc'));
304
-
305
- simple.falsy(272, isRegExp([1, 'a']));
306
-
307
- simple.falsy(272, isRegExp({
308
- a: 1,
309
- b: 'ccc'
310
- }));
311
-
312
- simple.falsy(272, isRegExp(undef));
313
-
314
- simple.truthy(278, isRegExp(/\.coffee/));
315
-
316
- // ---------------------------------------------------------------------------
317
- simple.equal(212, extractMatches("..3 and 4 plus 5", /\d+/g, parseInt), [3, 4, 5]);
318
-
319
- simple.equal(214, extractMatches("And This Is A String", /A/g), ['A', 'A']);
@@ -1,52 +0,0 @@
1
- # private_env.coffee
2
-
3
- import {assert} from '@jdeighan/coffee-utils'
4
- import {log} from '@jdeighan/coffee-utils/log'
5
-
6
- # --- Use by simply importing and using hEnvLib
7
- # This module does no loading - it merely holds hEnvLib
8
- export hPrivEnv = {}
9
-
10
- # --- None of these callbacks should replace variable hEnvLib
11
-
12
- export hPrivEnvCallbacks = {
13
- getVar: (name) ->
14
- return hPrivEnv[name]
15
- setVar: (name, value) ->
16
- hPrivEnv[name] = value
17
- return
18
- clearVar: (name) ->
19
- delete hPrivEnv[name]
20
- return
21
- clearAll: () ->
22
- for name in Object.keys(hPrivEnv)
23
- delete hPrivEnv[name]
24
- return
25
- names: () ->
26
- return Object.keys(hPrivEnv)
27
- }
28
-
29
- # ---------------------------------------------------------------------------
30
-
31
- export setPrivEnvVar = (name, value) ->
32
-
33
- hPrivEnv[name] = value
34
- return
35
-
36
- # ---------------------------------------------------------------------------
37
-
38
- export resetPrivEnv = () ->
39
-
40
- for name in Object.keys(hPrivEnv)
41
- delete hPrivEnv[name]
42
- return
43
-
44
- # ---------------------------------------------------------------------------
45
-
46
- export logPrivEnv = () ->
47
-
48
- log "PRIVATE ENVIRONMENT:"
49
- for key,value of hPrivEnv
50
- log " #{key} = '#{value}'"
51
- log '-'.repeat(40)
52
- return
@@ -1,63 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // private_env.coffee
3
- import {
4
- assert
5
- } from '@jdeighan/coffee-utils';
6
-
7
- import {
8
- log
9
- } from '@jdeighan/coffee-utils/log';
10
-
11
- // --- Use by simply importing and using hEnvLib
12
- // This module does no loading - it merely holds hEnvLib
13
- export var hPrivEnv = {};
14
-
15
- // --- None of these callbacks should replace variable hEnvLib
16
- export var hPrivEnvCallbacks = {
17
- getVar: function(name) {
18
- return hPrivEnv[name];
19
- },
20
- setVar: function(name, value) {
21
- hPrivEnv[name] = value;
22
- },
23
- clearVar: function(name) {
24
- delete hPrivEnv[name];
25
- },
26
- clearAll: function() {
27
- var i, len, name, ref;
28
- ref = Object.keys(hPrivEnv);
29
- for (i = 0, len = ref.length; i < len; i++) {
30
- name = ref[i];
31
- delete hPrivEnv[name];
32
- }
33
- },
34
- names: function() {
35
- return Object.keys(hPrivEnv);
36
- }
37
- };
38
-
39
- // ---------------------------------------------------------------------------
40
- export var setPrivEnvVar = function(name, value) {
41
- hPrivEnv[name] = value;
42
- };
43
-
44
- // ---------------------------------------------------------------------------
45
- export var resetPrivEnv = function() {
46
- var i, len, name, ref;
47
- ref = Object.keys(hPrivEnv);
48
- for (i = 0, len = ref.length; i < len; i++) {
49
- name = ref[i];
50
- delete hPrivEnv[name];
51
- }
52
- };
53
-
54
- // ---------------------------------------------------------------------------
55
- export var logPrivEnv = function() {
56
- var key, value;
57
- log("PRIVATE ENVIRONMENT:");
58
- for (key in hPrivEnv) {
59
- value = hPrivEnv[key];
60
- log(` ${key} = '${value}'`);
61
- }
62
- log('-'.repeat(40));
63
- };