@jdeighan/coffee-utils 4.1.6 → 4.1.10

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.
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
- # ----------------------------------------------------------------------------
@@ -1,54 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // privenv.test.coffee
3
- var simple;
4
-
5
- import assert from 'assert';
6
-
7
- import test from 'ava';
8
-
9
- import {
10
- undef,
11
- pass,
12
- isString,
13
- isHash,
14
- isEmpty,
15
- nonEmpty
16
- } from '@jdeighan/coffee-utils';
17
-
18
- import {
19
- log,
20
- setLogger
21
- } from '@jdeighan/coffee-utils/log';
22
-
23
- import {
24
- UnitTester
25
- } from '@jdeighan/coffee-utils/test';
26
-
27
- import {
28
- hPrivEnv,
29
- resetPrivEnv,
30
- setPrivEnvVar,
31
- logPrivEnv
32
- } from '@jdeighan/coffee-utils/privenv';
33
-
34
- simple = new UnitTester();
35
-
36
- // ----------------------------------------------------------------------------
37
- (function() {
38
- var strLogs;
39
- resetPrivEnv();
40
- setPrivEnvVar('DIR_ROOT', '/usr/johnd');
41
- setPrivEnvVar('DIR_COMPONENTS', '/usr/johnd/components');
42
- simple.equal(24, hPrivEnv['DIR_ROOT'], '/usr/johnd');
43
- strLogs = '';
44
- setLogger(function(line) {
45
- return strLogs += `${line}\n`;
46
- });
47
- logPrivEnv();
48
- return simple.equal(30, strLogs, `PRIVATE ENVIRONMENT:
49
- DIR_ROOT = '/usr/johnd'
50
- DIR_COMPONENTS = '/usr/johnd/components'
51
- ----------------------------------------`);
52
- })();
53
-
54
- // ----------------------------------------------------------------------------
package/.save/temp.coffee DELETED
@@ -1,19 +0,0 @@
1
- # temp.coffee
2
-
3
- import {log} from '@jdeighan/coffee-utils/log'
4
- import {mydir, forEachFile} from '@jdeighan/coffee-utils/fs'
5
- import {
6
- debug, setDebugging, checkTraceFile,
7
- } from '@jdeighan/coffee-utils/debug'
8
-
9
- testDir = mydir(`import.meta.url`)
10
-
11
- # ---------------------------------------------------------------------------
12
-
13
- main = () ->
14
-
15
- checkTraceFile "c:/Users/johnd/coffee-utils/test/temp.txt"
16
-
17
- # ---------------------------------------------------------------------------
18
-
19
- main()
package/.save/temp.js DELETED
@@ -1,28 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // temp.coffee
3
- var main, testDir;
4
-
5
- import {
6
- log
7
- } from '@jdeighan/coffee-utils/log';
8
-
9
- import {
10
- mydir,
11
- forEachFile
12
- } from '@jdeighan/coffee-utils/fs';
13
-
14
- import {
15
- debug,
16
- setDebugging,
17
- checkTraceFile
18
- } from '@jdeighan/coffee-utils/debug';
19
-
20
- testDir = mydir(import.meta.url);
21
-
22
- // ---------------------------------------------------------------------------
23
- main = function() {
24
- return checkTraceFile("c:/Users/johnd/coffee-utils/test/temp.txt");
25
- };
26
-
27
- // ---------------------------------------------------------------------------
28
- main();
@@ -1,75 +0,0 @@
1
- # test.coffee
2
-
3
- import {pass} from '@jdeighan/coffee-utils'
4
- import {UnitTester} from '@jdeighan/coffee-utils/test'
5
-
6
- tester = new UnitTester
7
-
8
- tester.equal 7, 'abc', 'abc'
9
- tester.equal 8, ['a','b'], [ 'a', 'b', ]
10
- tester.truthy 9, 42
11
- tester.falsy 10, null
12
- tester.notequal 11, 'abc', 'def'
13
- tester.fails 12, () -> throw new Error("bad")
14
- tester.different 13, ['a'], ['a']
15
-
16
- lItems = ['a', 'b', 'c']
17
- tester.same 16, lItems, lItems
18
-
19
- # --- Duplicate line # should not be an error
20
- tester.notequal 11, 'xxx', 'xxxx'
21
-
22
- # ---------------------------------------------------------------------------
23
- # --- Test creating custom tester
24
-
25
- class CapTester extends UnitTester
26
-
27
- transformValue: (input) ->
28
- return input.toUpperCase()
29
-
30
- capTester = new CapTester()
31
-
32
- capTester.equal 26, 'abc', 'ABC'
33
- capTester.equal 27, 'ABC', 'ABC'
34
- capTester.notequal 28, 'abc', 'abc'
35
-
36
- # ---------------------------------------------------------------------------
37
- # --- Test string normalization
38
-
39
- tester.equal 31, """
40
- line 1
41
-
42
- line 2
43
-
44
- line 3
45
- """, """
46
- line 1
47
- line 2
48
- line 3
49
- """
50
-
51
- # ---------------------------------------------------------------------------
52
- # --- Test same_list
53
-
54
- tester.same_list 54, [1,2,3], [1,2,3]
55
- tester.same_list 55, [2,1,3], [1,2,3]
56
- tester.same_list 56, ['a','b','c'], ['a','b','c']
57
- tester.same_list 57, ['b','a','c'], ['a','b','c']
58
-
59
- # ---------------------------------------------------------------------------
60
- # --- Test not_same_list
61
-
62
- tester.not_same_list 62, [1,2,3], [1,2]
63
- tester.not_same_list 63, [2,1,3], [1,2]
64
- tester.not_same_list 64, ['a','b','c'], ['a','b']
65
- tester.not_same_list 65, ['b','a','c'], ['a','b']
66
-
67
- # ---------------------------------------------------------------------------
68
- # Test if negative line numbers generate error if env var FINALTEST is set
69
-
70
- process.env.FINALTEST = 'yes'
71
-
72
- tester.fails 72, () ->
73
- tester.equal -99, 2, 2
74
-
75
- delete process.env.FINALTEST
@@ -1,93 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // test.coffee
3
- var CapTester, capTester, lItems, tester;
4
-
5
- import {
6
- pass
7
- } from '@jdeighan/coffee-utils';
8
-
9
- import {
10
- UnitTester
11
- } from '@jdeighan/coffee-utils/test';
12
-
13
- tester = new UnitTester();
14
-
15
- tester.equal(7, 'abc', 'abc');
16
-
17
- tester.equal(8, ['a', 'b'], ['a', 'b']);
18
-
19
- tester.truthy(9, 42);
20
-
21
- tester.falsy(10, null);
22
-
23
- tester.notequal(11, 'abc', 'def');
24
-
25
- tester.fails(12, function() {
26
- throw new Error("bad");
27
- });
28
-
29
- tester.different(13, ['a'], ['a']);
30
-
31
- lItems = ['a', 'b', 'c'];
32
-
33
- tester.same(16, lItems, lItems);
34
-
35
- // --- Duplicate line # should not be an error
36
- tester.notequal(11, 'xxx', 'xxxx');
37
-
38
- // ---------------------------------------------------------------------------
39
- // --- Test creating custom tester
40
- CapTester = class CapTester extends UnitTester {
41
- transformValue(input) {
42
- return input.toUpperCase();
43
- }
44
-
45
- };
46
-
47
- capTester = new CapTester();
48
-
49
- capTester.equal(26, 'abc', 'ABC');
50
-
51
- capTester.equal(27, 'ABC', 'ABC');
52
-
53
- capTester.notequal(28, 'abc', 'abc');
54
-
55
- // ---------------------------------------------------------------------------
56
- // --- Test string normalization
57
- tester.equal(31, `line 1
58
-
59
- line 2
60
-
61
- line 3`, `line 1
62
- line 2
63
- line 3`);
64
-
65
- // ---------------------------------------------------------------------------
66
- // --- Test same_list
67
- tester.same_list(54, [1, 2, 3], [1, 2, 3]);
68
-
69
- tester.same_list(55, [2, 1, 3], [1, 2, 3]);
70
-
71
- tester.same_list(56, ['a', 'b', 'c'], ['a', 'b', 'c']);
72
-
73
- tester.same_list(57, ['b', 'a', 'c'], ['a', 'b', 'c']);
74
-
75
- // ---------------------------------------------------------------------------
76
- // --- Test not_same_list
77
- tester.not_same_list(62, [1, 2, 3], [1, 2]);
78
-
79
- tester.not_same_list(63, [2, 1, 3], [1, 2]);
80
-
81
- tester.not_same_list(64, ['a', 'b', 'c'], ['a', 'b']);
82
-
83
- tester.not_same_list(65, ['b', 'a', 'c'], ['a', 'b']);
84
-
85
- // ---------------------------------------------------------------------------
86
- // Test if negative line numbers generate error if env var FINALTEST is set
87
- process.env.FINALTEST = 'yes';
88
-
89
- tester.fails(72, function() {
90
- return tester.equal(-99, 2, 2);
91
- });
92
-
93
- delete process.env.FINALTEST;