@jdeighan/coffee-utils 4.1.7 → 4.1.11

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,64 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // block2.test.coffee
3
- var filepath, simple, testDir;
4
-
5
- import assert from 'assert';
6
-
7
- import test from 'ava';
8
-
9
- import {
10
- undef,
11
- say,
12
- isString,
13
- isHash,
14
- isEmpty,
15
- nonEmpty
16
- } from '@jdeighan/coffee-utils';
17
-
18
- import {
19
- mydir,
20
- mkpath
21
- } from '@jdeighan/coffee-utils/fs';
22
-
23
- import {
24
- UnitTester
25
- } from '@jdeighan/coffee-utils/test';
26
-
27
- import {
28
- forEachLine,
29
- forEachBlock,
30
- forEachSetOfBlocks
31
- } from '@jdeighan/coffee-utils/block';
32
-
33
- testDir = mydir(import.meta.url);
34
-
35
- simple = new UnitTester();
36
-
37
- filepath = mkpath(testDir, 'code2.test.txt');
38
-
39
- // ----------------------------------------------------------------------------
40
- (function() {
41
- var callback, lFirstBlocks;
42
- lFirstBlocks = undef;
43
- callback = function(lBlocks) {
44
- lFirstBlocks = lBlocks;
45
- return true; // we're only interested in the first set
46
- };
47
- return test("line 29", async function(t) {
48
- await forEachSetOfBlocks(filepath, callback);
49
- return t.deepEqual(lFirstBlocks, ["f()", "f"]);
50
- });
51
- })();
52
-
53
- // ----------------------------------------------------------------------------
54
- (function() {
55
- var callback, lAllBlockSets;
56
- lAllBlockSets = [];
57
- callback = function(lBlocks) {
58
- lAllBlockSets.push(lBlocks);
59
- };
60
- return test("line 44", async function(t) {
61
- await forEachSetOfBlocks(filepath, callback);
62
- return t.deepEqual(lAllBlockSets, [["f()", "f"], ["f = (key=undef) ->\n\tswitch key\n\t\twhen 'ok'\n\t\t\tsay 'all is OK'", "f,say,mkpath"]]);
63
- });
64
- })();
@@ -1,290 +0,0 @@
1
- # debug.test.coffee
2
-
3
- import {undef, OL} from '@jdeighan/coffee-utils'
4
- import {blockToArray, arrayToBlock} from '@jdeighan/coffee-utils/block'
5
- import {log, setLogger} from '@jdeighan/coffee-utils/log'
6
- import {
7
- setDebugging, debug, resetDebugging, funcMatch,
8
- } from '@jdeighan/coffee-utils/debug'
9
- import {UnitTester} from '@jdeighan/coffee-utils/test'
10
-
11
- simple = new UnitTester()
12
-
13
- # ---------------------------------------------------------------------------
14
-
15
- lLines = undef
16
- setLogger (str) -> lLines.push(str)
17
- setDebugging true
18
-
19
- # ---------------------------------------------------------------------------
20
-
21
- (() ->
22
- lLines = []
23
- debug 'abc'
24
- simple.equal 24, lLines, ['abc']
25
- )()
26
-
27
- # ---------------------------------------------------------------------------
28
-
29
- class TraceTester extends UnitTester
30
-
31
- initialize: () ->
32
- lLines = []
33
-
34
- transformValue: (block) ->
35
-
36
- for line in blockToArray(block)
37
- debug line
38
- return arrayToBlock(lLines)
39
-
40
- normalize: (text) ->
41
- return text
42
-
43
- tester = new TraceTester()
44
-
45
- # ---------------------------------------------------------------------------
46
-
47
- (() ->
48
- lLines = []
49
- debug 'enter myfunc'
50
- debug 'something'
51
- debug 'more'
52
- debug 'return 42 from myfunc'
53
- debug "Answer is 42"
54
- simple.equal 54, lLines, [
55
- "enter myfunc"
56
- "│ something"
57
- "│ more"
58
- "└─> return 42 from myfunc"
59
- "Answer is 42"
60
- ]
61
- )()
62
-
63
- # ---------------------------------------------------------------------------
64
-
65
- (() ->
66
- lLines = []
67
- debug 'enter myfunc'
68
- debug 'something'
69
- debug 'enter newfunc'
70
- debug 'something else'
71
- debug 'return abc from newfunc'
72
- debug 'return 42 from myfunc'
73
- simple.equal 73, lLines, [
74
- "enter myfunc"
75
- "│ something"
76
- "│ enter newfunc"
77
- "│ │ something else"
78
- "│ └─> return abc from newfunc"
79
- "└─> return 42 from myfunc"
80
- ]
81
- )()
82
-
83
- # ---------------------------------------------------------------------------
84
-
85
- (() ->
86
- lLines = []
87
- obj = {
88
- first: 1
89
- second: 2
90
- }
91
- debug 'enter myfunc'
92
- debug 'something'
93
- debug 'obj', obj
94
- debug 'return 42 from myfunc'
95
- simple.equal 95, lLines, [
96
- "enter myfunc"
97
- "│ something"
98
- '│ obj = {"first":1,"second":2}'
99
- "└─> return 42 from myfunc"
100
- ]
101
- )()
102
-
103
- # ---------------------------------------------------------------------------
104
-
105
- (() ->
106
- lLines = []
107
- obj = {
108
- first: "this is the first item in the hash"
109
- second: "this is the second item in the hash"
110
- }
111
- debug 'enter myfunc'
112
- debug 'something'
113
- debug 'obj', obj
114
- debug 'return 42 from myfunc'
115
- simple.equal 115, lLines, [
116
- "enter myfunc"
117
- "│ something"
118
- "│ obj:"
119
- "│ ---"
120
- "│ first: this is the first item in the hash"
121
- "│ second: this is the second item in the hash"
122
- "└─> return 42 from myfunc"
123
- ]
124
- )()
125
-
126
- # ---------------------------------------------------------------------------
127
- # --- Test ability to debug only a particular function
128
-
129
- (() ->
130
- lLines = []
131
- resetDebugging()
132
- setDebugging 'innerFunc'
133
-
134
- debug "enter myfunc"
135
- debug "something"
136
- debug "enter innerFunc"
137
- debug "something else"
138
- debug "return nothing from innerFunc"
139
- debug "this should not appear"
140
- debug "return 42 from myfunc"
141
- simple.equal 141, lLines, [
142
- "enter innerFunc"
143
- "│ something else"
144
- "└─> return nothing from innerFunc"
145
- ]
146
- setDebugging false
147
- )()
148
-
149
- # ---------------------------------------------------------------------------
150
- # --- Test ability to debug only a particular function
151
- # using actual functions!
152
-
153
- (() ->
154
- lLines = []
155
- resetDebugging()
156
- setDebugging 'innerFunc'
157
-
158
- innerFunc = () ->
159
-
160
- debug "enter innerFunc()"
161
- debug "answer is 42"
162
- x = 42
163
- debug "return from innerFunc()"
164
- return
165
-
166
- outerFunc = () ->
167
-
168
- debug "enter outerFunc()"
169
- innerFunc()
170
- debug "return from outerFunc()"
171
- return
172
-
173
- outerFunc()
174
-
175
- simple.equal 175, lLines, [
176
- "enter innerFunc()"
177
- "│ answer is 42"
178
- "└─> return from innerFunc()"
179
- ]
180
- setDebugging false
181
- )()
182
-
183
- # ---------------------------------------------------------------------------
184
-
185
- (() ->
186
- setDebugging 'get'
187
-
188
- simple.truthy 188, funcMatch('get')
189
- simple.truthy 189, funcMatch('StringInput.get')
190
- setDebugging false
191
- )()
192
-
193
- # ---------------------------------------------------------------------------
194
-
195
- (() ->
196
- resetDebugging()
197
- setDebugging true
198
- lLines = []
199
-
200
- line = 'first line'
201
- debug "line is #{OL(line)}"
202
-
203
- simple.equal 203, lLines.length, 1
204
- simple.equal 204, lLines, [
205
- "line is 'first line'"
206
- ]
207
- setDebugging false
208
- )()
209
-
210
- # ---------------------------------------------------------------------------
211
-
212
- (() ->
213
- resetDebugging()
214
- setDebugging true
215
- lLines = []
216
-
217
- obj = {
218
- first: "this is the first item in the hash"
219
- second: "this is the second item in the hash"
220
- }
221
-
222
- debug 'enter myfunc'
223
- debug 'return from myfunc', obj
224
- debug "Answer is 42"
225
- simple.equal 225, lLines, [
226
- "enter myfunc"
227
- "└─> return from myfunc:"
228
- " ---"
229
- " first: this is the first item in the hash"
230
- " second: this is the second item in the hash"
231
- "Answer is 42"
232
- ]
233
- )()
234
-
235
- # ---------------------------------------------------------------------------
236
-
237
- (() ->
238
- resetDebugging()
239
- setDebugging true
240
- lLines = []
241
-
242
- longBlock = """
243
- this is one very long line
244
- this is another very long line
245
- """
246
-
247
- debug 'enter myfunc'
248
- debug 'return from myfunc', longBlock
249
- debug "Answer is 42"
250
- simple.equal 250, lLines, [
251
- "enter myfunc"
252
- "└─> return from myfunc:"
253
- " =========================================="
254
- " this is one very long line"
255
- " this is another very long line"
256
- " =========================================="
257
- "Answer is 42"
258
- ]
259
- )()
260
-
261
- # ---------------------------------------------------------------------------
262
-
263
- (() ->
264
- resetDebugging()
265
- setDebugging 'get'
266
-
267
- block = """
268
- enter myfunc
269
- enter get
270
- enter fetch
271
- return from fetch
272
- return from get
273
- enter nofunc
274
- return from nofunc
275
- enter get
276
- something
277
- return from get
278
- return from myfunc
279
- """
280
-
281
- tester.equal 279, block, """
282
- enter get
283
- │ enter fetch
284
- │ └─> return from fetch
285
- └─> return from get
286
- enter get
287
- │ something
288
- └─> return from get
289
- """
290
- )()
@@ -1,242 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // debug.test.coffee
3
- var TraceTester, lLines, simple, tester;
4
-
5
- import {
6
- undef,
7
- OL
8
- } from '@jdeighan/coffee-utils';
9
-
10
- import {
11
- blockToArray,
12
- arrayToBlock
13
- } from '@jdeighan/coffee-utils/block';
14
-
15
- import {
16
- log,
17
- setLogger
18
- } from '@jdeighan/coffee-utils/log';
19
-
20
- import {
21
- setDebugging,
22
- debug,
23
- resetDebugging,
24
- funcMatch
25
- } from '@jdeighan/coffee-utils/debug';
26
-
27
- import {
28
- UnitTester
29
- } from '@jdeighan/coffee-utils/test';
30
-
31
- simple = new UnitTester();
32
-
33
- // ---------------------------------------------------------------------------
34
- lLines = undef;
35
-
36
- setLogger(function(str) {
37
- return lLines.push(str);
38
- });
39
-
40
- setDebugging(true);
41
-
42
- // ---------------------------------------------------------------------------
43
- (function() {
44
- lLines = [];
45
- debug('abc');
46
- return simple.equal(24, lLines, ['abc']);
47
- })();
48
-
49
- // ---------------------------------------------------------------------------
50
- TraceTester = class TraceTester extends UnitTester {
51
- initialize() {
52
- return lLines = [];
53
- }
54
-
55
- transformValue(block) {
56
- var i, len, line, ref;
57
- ref = blockToArray(block);
58
- for (i = 0, len = ref.length; i < len; i++) {
59
- line = ref[i];
60
- debug(line);
61
- }
62
- return arrayToBlock(lLines);
63
- }
64
-
65
- normalize(text) {
66
- return text;
67
- }
68
-
69
- };
70
-
71
- tester = new TraceTester();
72
-
73
- // ---------------------------------------------------------------------------
74
- (function() {
75
- lLines = [];
76
- debug('enter myfunc');
77
- debug('something');
78
- debug('more');
79
- debug('return 42 from myfunc');
80
- debug("Answer is 42");
81
- return simple.equal(54, lLines, ["enter myfunc", "│ something", "│ more", "└─> return 42 from myfunc", "Answer is 42"]);
82
- })();
83
-
84
- // ---------------------------------------------------------------------------
85
- (function() {
86
- lLines = [];
87
- debug('enter myfunc');
88
- debug('something');
89
- debug('enter newfunc');
90
- debug('something else');
91
- debug('return abc from newfunc');
92
- debug('return 42 from myfunc');
93
- return simple.equal(73, lLines, ["enter myfunc", "│ something", "│ enter newfunc", "│ │ something else", "│ └─> return abc from newfunc", "└─> return 42 from myfunc"]);
94
- })();
95
-
96
- // ---------------------------------------------------------------------------
97
- (function() {
98
- var obj;
99
- lLines = [];
100
- obj = {
101
- first: 1,
102
- second: 2
103
- };
104
- debug('enter myfunc');
105
- debug('something');
106
- debug('obj', obj);
107
- debug('return 42 from myfunc');
108
- return simple.equal(95, lLines, ["enter myfunc", "│ something", '│ obj = {"first":1,"second":2}', "└─> return 42 from myfunc"]);
109
- })();
110
-
111
- // ---------------------------------------------------------------------------
112
- (function() {
113
- var obj;
114
- lLines = [];
115
- obj = {
116
- first: "this is the first item in the hash",
117
- second: "this is the second item in the hash"
118
- };
119
- debug('enter myfunc');
120
- debug('something');
121
- debug('obj', obj);
122
- debug('return 42 from myfunc');
123
- return simple.equal(115, lLines, ["enter myfunc", "│ something", "│ obj:", "│ ---", "│ first: this is the first item in the hash", "│ second: this is the second item in the hash", "└─> return 42 from myfunc"]);
124
- })();
125
-
126
- // ---------------------------------------------------------------------------
127
- // --- Test ability to debug only a particular function
128
- (function() {
129
- lLines = [];
130
- resetDebugging();
131
- setDebugging('innerFunc');
132
- debug("enter myfunc");
133
- debug("something");
134
- debug("enter innerFunc");
135
- debug("something else");
136
- debug("return nothing from innerFunc");
137
- debug("this should not appear");
138
- debug("return 42 from myfunc");
139
- simple.equal(141, lLines, ["enter innerFunc", "│ something else", "└─> return nothing from innerFunc"]);
140
- return setDebugging(false);
141
- })();
142
-
143
- // ---------------------------------------------------------------------------
144
- // --- Test ability to debug only a particular function
145
- // using actual functions!
146
- (function() {
147
- var innerFunc, outerFunc;
148
- lLines = [];
149
- resetDebugging();
150
- setDebugging('innerFunc');
151
- innerFunc = function() {
152
- var x;
153
- debug("enter innerFunc()");
154
- debug("answer is 42");
155
- x = 42;
156
- debug("return from innerFunc()");
157
- };
158
- outerFunc = function() {
159
- debug("enter outerFunc()");
160
- innerFunc();
161
- debug("return from outerFunc()");
162
- };
163
- outerFunc();
164
- simple.equal(175, lLines, ["enter innerFunc()", "│ answer is 42", "└─> return from innerFunc()"]);
165
- return setDebugging(false);
166
- })();
167
-
168
- // ---------------------------------------------------------------------------
169
- (function() {
170
- setDebugging('get');
171
- simple.truthy(188, funcMatch('get'));
172
- simple.truthy(189, funcMatch('StringInput.get'));
173
- return setDebugging(false);
174
- })();
175
-
176
- // ---------------------------------------------------------------------------
177
- (function() {
178
- var line;
179
- resetDebugging();
180
- setDebugging(true);
181
- lLines = [];
182
- line = 'first line';
183
- debug(`line is ${OL(line)}`);
184
- simple.equal(203, lLines.length, 1);
185
- simple.equal(204, lLines, ["line is 'first line'"]);
186
- return setDebugging(false);
187
- })();
188
-
189
- // ---------------------------------------------------------------------------
190
- (function() {
191
- var obj;
192
- resetDebugging();
193
- setDebugging(true);
194
- lLines = [];
195
- obj = {
196
- first: "this is the first item in the hash",
197
- second: "this is the second item in the hash"
198
- };
199
- debug('enter myfunc');
200
- debug('return from myfunc', obj);
201
- debug("Answer is 42");
202
- return simple.equal(225, lLines, ["enter myfunc", "└─> return from myfunc:", " ---", " first: this is the first item in the hash", " second: this is the second item in the hash", "Answer is 42"]);
203
- })();
204
-
205
- // ---------------------------------------------------------------------------
206
- (function() {
207
- var longBlock;
208
- resetDebugging();
209
- setDebugging(true);
210
- lLines = [];
211
- longBlock = `this is one very long line
212
- this is another very long line`;
213
- debug('enter myfunc');
214
- debug('return from myfunc', longBlock);
215
- debug("Answer is 42");
216
- return simple.equal(250, lLines, ["enter myfunc", "└─> return from myfunc:", " ==========================================", " this is one very long line", " this is another very long line", " ==========================================", "Answer is 42"]);
217
- })();
218
-
219
- // ---------------------------------------------------------------------------
220
- (function() {
221
- var block;
222
- resetDebugging();
223
- setDebugging('get');
224
- block = `enter myfunc
225
- enter get
226
- enter fetch
227
- return from fetch
228
- return from get
229
- enter nofunc
230
- return from nofunc
231
- enter get
232
- something
233
- return from get
234
- return from myfunc`;
235
- return tester.equal(279, block, `enter get
236
- │ enter fetch
237
- │ └─> return from fetch
238
- └─> return from get
239
- enter get
240
- │ something
241
- └─> return from get`);
242
- })();