@jdeighan/coffee-utils 4.1.4 → 4.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,315 +0,0 @@
1
- # log.test.coffee
2
-
3
- import {undef} from '@jdeighan/coffee-utils'
4
- import {arrayToBlock} from '@jdeighan/coffee-utils/block'
5
- import {UnitTester} from '@jdeighan/coffee-utils/test'
6
- import {
7
- stringify, setStringifier, log, setLogger, tamlStringify,
8
- } from '@jdeighan/coffee-utils/log'
9
-
10
- simple = new UnitTester()
11
-
12
- # ---------------------------------------------------------------------------
13
-
14
- class LogTester extends UnitTester
15
-
16
- transformValue: (lLines) ->
17
- return arrayToBlock(lLines)
18
- normalize: (text) ->
19
- return text
20
-
21
- tester = new LogTester()
22
-
23
- # ---------------------------------------------------------------------------
24
-
25
- lLines = undef
26
- setLogger (str) -> lLines.push(str)
27
-
28
- # ---------------------------------------------------------------------------
29
-
30
- (() ->
31
- lLines = []
32
- log 'enter myfunc'
33
- tester.equal 33, lLines, """
34
- enter myfunc
35
- """
36
- )()
37
-
38
- # ---------------------------------------------------------------------------
39
-
40
- (() ->
41
- lLines = []
42
- log 'abc'
43
- log 'def'
44
- log 'ghi'
45
- tester.equal 45, lLines, """
46
- abc
47
- def
48
- ghi
49
- """
50
- )()
51
-
52
- # ---------------------------------------------------------------------------
53
- # test logging various small objects
54
-
55
- (() ->
56
- lLines = []
57
- log 'abc'
58
- log 'name', undef
59
- tester.equal 59, lLines, """
60
- abc
61
- name = undef
62
- """
63
- )()
64
-
65
- (() ->
66
- lLines = []
67
- log 'abc'
68
- log 'name', 42
69
- tester.equal 68, lLines, """
70
- abc
71
- name = 42
72
- """
73
- )()
74
-
75
- (() ->
76
- lLines = []
77
- log 'abc'
78
- log 'name', 'John'
79
- tester.equal 79, lLines, """
80
- abc
81
- name = 'John'
82
- """
83
- )()
84
-
85
- (() ->
86
- lLines = []
87
- log 'abc'
88
- log 'name', {a: 1, b: 'xyz'}
89
- tester.equal 89, lLines, """
90
- abc
91
- name = {"a":1,"b":"xyz"}
92
- """
93
- )()
94
-
95
- (() ->
96
- lLines = []
97
- log 'abc'
98
- log 'name', ['a', 42, [1,2]]
99
- tester.equal 99, lLines, """
100
- abc
101
- name = ["a",42,[1,2]]
102
- """
103
- )()
104
-
105
- # ---------------------------------------------------------------------------
106
- # test logging various large objects
107
-
108
- (() ->
109
- lLines = []
110
- log 'abc'
111
- log 'name', """
112
- This is a rather long bit of
113
- text which changes
114
- how it's displayed
115
- """
116
- tester.equal 116, lLines, """
117
- abc
118
- name:
119
- ==========================================
120
- This is a rather long bit of
121
- text which changes
122
- how it's displayed
123
- ==========================================
124
- """
125
- )()
126
-
127
- (() ->
128
- lLines = []
129
- log 'abc'
130
- log 'name', {
131
- fname: 'John',
132
- lname: 'Deighan',
133
- age: 68,
134
- home: 'Blacksburg, VA',
135
- }
136
- tester.equal 134, lLines, """
137
- abc
138
- name:
139
- ---
140
- fname: John
141
- lname: Deighan
142
- age: 68
143
- home: Blacksburg, VA
144
- """
145
- )()
146
-
147
- (() ->
148
- lLines = []
149
- log 'abc'
150
- log 'name', [
151
- 68,
152
- 'a rather long string of text',
153
- {a:1, b:2}
154
- ]
155
- tester.equal 153, lLines, """
156
- abc
157
- name:
158
- ---
159
- - 68
160
- - a rather long string of text
161
- -
162
- a: 1
163
- b: 2
164
- """
165
- )()
166
-
167
- # ---------------------------------------------------------------------------
168
- # test providing a prefix
169
-
170
- (() ->
171
- lLines = []
172
- log 'name', undef, {prefix: '<-->', logItem: true}
173
- tester.equal 171, lLines, """
174
- <-->name = undef
175
- """
176
- )()
177
-
178
- (() ->
179
- lLines = []
180
- log 'name', 42, {prefix: '<-->', logItem: true}
181
- tester.equal 179, lLines, """
182
- <-->name = 42
183
- """
184
- )()
185
-
186
- (() ->
187
- lLines = []
188
- log 'name', 'John', {prefix: '<-->', logItem: true}
189
- tester.equal 187, lLines, """
190
- <-->name = 'John'
191
- """
192
- )()
193
-
194
- (() ->
195
- lLines = []
196
- log 'name', {a: 1, b: 'xyz'}, {prefix: '<-->', logItem: true}
197
- tester.equal 195, lLines, """
198
- <-->name = {"a":1,"b":"xyz"}
199
- """
200
- )()
201
-
202
- (() ->
203
- lLines = []
204
- log 'name', ['a', 42, [1,2]], {prefix: '<-->', logItem: true}
205
- tester.equal 203, lLines, """
206
- <-->name = ["a",42,[1,2]]
207
- """
208
- )()
209
-
210
- (() ->
211
- lLines = []
212
- log 'name', """
213
- This is a rather long bit of
214
- text which changes
215
- how it's displayed
216
- """, {prefix: '<-->', logItem: true}
217
- tester.equal 215, lLines, """
218
- <-->name:
219
- ==========================================
220
- This is a rather long bit of
221
- text which changes
222
- how it's displayed
223
- ==========================================
224
- """
225
- )()
226
-
227
- (() ->
228
- lLines = []
229
- log 'name', {
230
- fname: 'John',
231
- lname: 'Deighan',
232
- age: 68,
233
- home: 'Blacksburg, VA',
234
- }, {prefix: '<-->', logItem: true}
235
- tester.equal 231, lLines, """
236
- <-->name:
237
- ---
238
- fname: John
239
- lname: Deighan
240
- age: 68
241
- home: Blacksburg, VA
242
- """
243
- )()
244
-
245
- (() ->
246
- lLines = []
247
- log 'name', [
248
- 68,
249
- 'a rather long string of text',
250
- {a:1, b:2}
251
- ], {prefix: '<-->', logItem: true}
252
- tester.equal 248, lLines, """
253
- <-->name:
254
- ---
255
- - 68
256
- - a rather long string of text
257
- -
258
- a: 1
259
- b: 2
260
- """
261
- )()
262
-
263
- # ---------------------------------------------------------------------------
264
-
265
- simple.equal 261, tamlStringify({a:"word", b:"blind"}), """
266
- ---
267
- a: word
268
- b: blind
269
- """
270
- simple.equal 266, stringify({a:"word", b:"blind"}), """
271
- ---
272
- a: word
273
- b: blind
274
- """
275
-
276
- setStringifier(JSON.stringify)
277
-
278
- simple.equal 274, stringify({a:"word", b:"blind"}),
279
- '{"a":"word","b":"blind"}'
280
-
281
- setStringifier(tamlStringify)
282
-
283
- simple.equal 279, stringify({a:"word", b:"blind"}), """
284
- ---
285
- a: word
286
- b: blind
287
- """
288
-
289
- # ---------------------------------------------------------------------------
290
-
291
- (() ->
292
- lItems = []
293
- setLogger (item) -> lItems.push(item)
294
- log 'a'
295
- log 'b'
296
- log 'c'
297
- setLogger() # reset
298
-
299
- simple.equal 295, lItems, ['a','b','c']
300
- )()
301
-
302
- (() ->
303
- lItems = []
304
- setLogger (item) -> lItems.push(item)
305
- log 'a'
306
- log 'b'
307
- log 'c'
308
- setLogger() # reset
309
-
310
- simple.equal 306, lItems, ['a','b','c']
311
- )()
312
-
313
- simple.fails 309, () -> error("an error message")
314
-
315
- # ---------------------------------------------------------------------------
package/.save/log.test.js DELETED
@@ -1,336 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // log.test.coffee
3
- var LogTester, lLines, simple, tester;
4
-
5
- import {
6
- undef
7
- } from '@jdeighan/coffee-utils';
8
-
9
- import {
10
- arrayToBlock
11
- } from '@jdeighan/coffee-utils/block';
12
-
13
- import {
14
- UnitTester
15
- } from '@jdeighan/coffee-utils/test';
16
-
17
- import {
18
- stringify,
19
- setStringifier,
20
- log,
21
- setLogger,
22
- tamlStringify
23
- } from '@jdeighan/coffee-utils/log';
24
-
25
- simple = new UnitTester();
26
-
27
- // ---------------------------------------------------------------------------
28
- LogTester = class LogTester extends UnitTester {
29
- transformValue(lLines) {
30
- return arrayToBlock(lLines);
31
- }
32
-
33
- normalize(text) {
34
- return text;
35
- }
36
-
37
- };
38
-
39
- tester = new LogTester();
40
-
41
- // ---------------------------------------------------------------------------
42
- lLines = undef;
43
-
44
- setLogger(function(str) {
45
- return lLines.push(str);
46
- });
47
-
48
- // ---------------------------------------------------------------------------
49
- (function() {
50
- lLines = [];
51
- log('enter myfunc');
52
- return tester.equal(33, lLines, `enter myfunc`);
53
- })();
54
-
55
- // ---------------------------------------------------------------------------
56
- (function() {
57
- lLines = [];
58
- log('abc');
59
- log('def');
60
- log('ghi');
61
- return tester.equal(45, lLines, `abc
62
- def
63
- ghi`);
64
- })();
65
-
66
- // ---------------------------------------------------------------------------
67
- // test logging various small objects
68
- (function() {
69
- lLines = [];
70
- log('abc');
71
- log('name', undef);
72
- return tester.equal(59, lLines, `abc
73
- name = undef`);
74
- })();
75
-
76
- (function() {
77
- lLines = [];
78
- log('abc');
79
- log('name', 42);
80
- return tester.equal(68, lLines, `abc
81
- name = 42`);
82
- })();
83
-
84
- (function() {
85
- lLines = [];
86
- log('abc');
87
- log('name', 'John');
88
- return tester.equal(79, lLines, `abc
89
- name = 'John'`);
90
- })();
91
-
92
- (function() {
93
- lLines = [];
94
- log('abc');
95
- log('name', {
96
- a: 1,
97
- b: 'xyz'
98
- });
99
- return tester.equal(89, lLines, `abc
100
- name = {"a":1,"b":"xyz"}`);
101
- })();
102
-
103
- (function() {
104
- lLines = [];
105
- log('abc');
106
- log('name', ['a', 42, [1, 2]]);
107
- return tester.equal(99, lLines, `abc
108
- name = ["a",42,[1,2]]`);
109
- })();
110
-
111
- // ---------------------------------------------------------------------------
112
- // test logging various large objects
113
- (function() {
114
- lLines = [];
115
- log('abc');
116
- log('name', `This is a rather long bit of
117
- text which changes
118
- how it's displayed`);
119
- return tester.equal(116, lLines, `abc
120
- name:
121
- ==========================================
122
- This is a rather long bit of
123
- text which changes
124
- how it's displayed
125
- ==========================================`);
126
- })();
127
-
128
- (function() {
129
- lLines = [];
130
- log('abc');
131
- log('name', {
132
- fname: 'John',
133
- lname: 'Deighan',
134
- age: 68,
135
- home: 'Blacksburg, VA'
136
- });
137
- return tester.equal(134, lLines, `abc
138
- name:
139
- ---
140
- fname: John
141
- lname: Deighan
142
- age: 68
143
- home: Blacksburg, VA`);
144
- })();
145
-
146
- (function() {
147
- lLines = [];
148
- log('abc');
149
- log('name', [
150
- 68,
151
- 'a rather long string of text',
152
- {
153
- a: 1,
154
- b: 2
155
- }
156
- ]);
157
- return tester.equal(153, lLines, `abc
158
- name:
159
- ---
160
- - 68
161
- - a rather long string of text
162
- -
163
- a: 1
164
- b: 2`);
165
- })();
166
-
167
- // ---------------------------------------------------------------------------
168
- // test providing a prefix
169
- (function() {
170
- lLines = [];
171
- log('name', undef, {
172
- prefix: '<-->',
173
- logItem: true
174
- });
175
- return tester.equal(171, lLines, `<-->name = undef`);
176
- })();
177
-
178
- (function() {
179
- lLines = [];
180
- log('name', 42, {
181
- prefix: '<-->',
182
- logItem: true
183
- });
184
- return tester.equal(179, lLines, `<-->name = 42`);
185
- })();
186
-
187
- (function() {
188
- lLines = [];
189
- log('name', 'John', {
190
- prefix: '<-->',
191
- logItem: true
192
- });
193
- return tester.equal(187, lLines, `<-->name = 'John'`);
194
- })();
195
-
196
- (function() {
197
- lLines = [];
198
- log('name', {
199
- a: 1,
200
- b: 'xyz'
201
- }, {
202
- prefix: '<-->',
203
- logItem: true
204
- });
205
- return tester.equal(195, lLines, `<-->name = {"a":1,"b":"xyz"}`);
206
- })();
207
-
208
- (function() {
209
- lLines = [];
210
- log('name', ['a', 42, [1, 2]], {
211
- prefix: '<-->',
212
- logItem: true
213
- });
214
- return tester.equal(203, lLines, `<-->name = ["a",42,[1,2]]`);
215
- })();
216
-
217
- (function() {
218
- lLines = [];
219
- log('name', `This is a rather long bit of
220
- text which changes
221
- how it's displayed`, {
222
- prefix: '<-->',
223
- logItem: true
224
- });
225
- return tester.equal(215, lLines, `<-->name:
226
- ==========================================
227
- This is a rather long bit of
228
- text which changes
229
- how it's displayed
230
- ==========================================`);
231
- })();
232
-
233
- (function() {
234
- lLines = [];
235
- log('name', {
236
- fname: 'John',
237
- lname: 'Deighan',
238
- age: 68,
239
- home: 'Blacksburg, VA'
240
- }, {
241
- prefix: '<-->',
242
- logItem: true
243
- });
244
- return tester.equal(231, lLines, `<-->name:
245
- ---
246
- fname: John
247
- lname: Deighan
248
- age: 68
249
- home: Blacksburg, VA`);
250
- })();
251
-
252
- (function() {
253
- lLines = [];
254
- log('name', [
255
- 68,
256
- 'a rather long string of text',
257
- {
258
- a: 1,
259
- b: 2
260
- }
261
- ], {
262
- prefix: '<-->',
263
- logItem: true
264
- });
265
- return tester.equal(248, lLines, `<-->name:
266
- ---
267
- - 68
268
- - a rather long string of text
269
- -
270
- a: 1
271
- b: 2`);
272
- })();
273
-
274
- // ---------------------------------------------------------------------------
275
- simple.equal(261, tamlStringify({
276
- a: "word",
277
- b: "blind"
278
- }), `---
279
- a: word
280
- b: blind`);
281
-
282
- simple.equal(266, stringify({
283
- a: "word",
284
- b: "blind"
285
- }), `---
286
- a: word
287
- b: blind`);
288
-
289
- setStringifier(JSON.stringify);
290
-
291
- simple.equal(274, stringify({
292
- a: "word",
293
- b: "blind"
294
- }), '{"a":"word","b":"blind"}');
295
-
296
- setStringifier(tamlStringify);
297
-
298
- simple.equal(279, stringify({
299
- a: "word",
300
- b: "blind"
301
- }), `---
302
- a: word
303
- b: blind`);
304
-
305
- // ---------------------------------------------------------------------------
306
- (function() {
307
- var lItems;
308
- lItems = [];
309
- setLogger(function(item) {
310
- return lItems.push(item);
311
- });
312
- log('a');
313
- log('b');
314
- log('c');
315
- setLogger(); // reset
316
- return simple.equal(295, lItems, ['a', 'b', 'c']);
317
- })();
318
-
319
- (function() {
320
- var lItems;
321
- lItems = [];
322
- setLogger(function(item) {
323
- return lItems.push(item);
324
- });
325
- log('a');
326
- log('b');
327
- log('c');
328
- setLogger(); // reset
329
- return simple.equal(306, lItems, ['a', 'b', 'c']);
330
- })();
331
-
332
- simple.fails(309, function() {
333
- return error("an error message");
334
- });
335
-
336
- // ---------------------------------------------------------------------------
@@ -1,38 +0,0 @@
1
- # privenv.test.coffee
2
-
3
- import assert from 'assert'
4
- import test from 'ava'
5
-
6
- import {
7
- undef, pass, isString, isHash, isEmpty, nonEmpty,
8
- } from '@jdeighan/coffee-utils'
9
- import {log, setLogger} from '@jdeighan/coffee-utils/log'
10
- import {UnitTester} from '@jdeighan/coffee-utils/test'
11
- import {
12
- hPrivEnv, resetPrivEnv, setPrivEnvVar, logPrivEnv,
13
- } from '@jdeighan/coffee-utils/privenv'
14
-
15
- simple = new UnitTester()
16
-
17
- # ----------------------------------------------------------------------------
18
-
19
- (() ->
20
- resetPrivEnv()
21
- setPrivEnvVar('DIR_ROOT', '/usr/johnd')
22
- setPrivEnvVar('DIR_COMPONENTS', '/usr/johnd/components')
23
-
24
- simple.equal 24, hPrivEnv['DIR_ROOT'], '/usr/johnd'
25
-
26
- strLogs = ''
27
- setLogger (line) -> strLogs += "#{line}\n"
28
- logPrivEnv()
29
-
30
- simple.equal 30, strLogs, """
31
- PRIVATE ENVIRONMENT:
32
- DIR_ROOT = '/usr/johnd'
33
- DIR_COMPONENTS = '/usr/johnd/components'
34
- ----------------------------------------
35
- """
36
- )()
37
-
38
- # ----------------------------------------------------------------------------