@jdeighan/coffee-utils 4.1.5 → 4.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,129 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // block.test.coffee
3
- var simple;
4
-
5
- import assert from 'assert';
6
-
7
- import {
8
- UnitTester
9
- } from '@jdeighan/coffee-utils/test';
10
-
11
- import {
12
- blockToArray,
13
- arrayToBlock,
14
- firstLine,
15
- remainingLines,
16
- normalizeBlock,
17
- truncateBlock,
18
- joinBlocks,
19
- forEachLine,
20
- forEachBlock,
21
- forEachSetOfBlocks
22
- } from '@jdeighan/coffee-utils/block';
23
-
24
- simple = new UnitTester();
25
-
26
- // ---------------------------------------------------------------------------
27
- simple.equal(108, blockToArray("abc\nxyz\n"), ['abc', 'xyz']);
28
-
29
- simple.equal(113, blockToArray("abc\nxyz\n\n\n\n"), ['abc', 'xyz']);
30
-
31
- simple.equal(118, blockToArray("abc\n\nxyz\n"), ['abc', '', 'xyz']);
32
-
33
- // ---------------------------------------------------------------------------
34
- simple.equal(126, arrayToBlock(['a', 'b', 'c']), "a\nb\nc\n");
35
-
36
- // ---------------------------------------------------------------------------
37
- simple.equal(225, firstLine(`#starbucks
38
- do this
39
- do that`), '#starbucks');
40
-
41
- // ---------------------------------------------------------------------------
42
- simple.equal(225, remainingLines(`#starbucks
43
- do this
44
- do that`), `do this
45
- do that`);
46
-
47
- // ---------------------------------------------------------------------------
48
- (function() {
49
- var str;
50
- str = joinBlocks('import me', '', 'do this\ndo that');
51
- return simple.equal(17, str, `import me
52
- do this
53
- do that`);
54
- })();
55
-
56
- // ---------------------------------------------------------------------------
57
- simple.equal(49, normalizeBlock(`line 1
58
- line 2`), `line 1
59
- line 2` + '\n');
60
-
61
- simple.equal(57, normalizeBlock(`line 1
62
-
63
- line 2`), `line 1
64
- line 2` + '\n');
65
-
66
- simple.equal(66, normalizeBlock(`
67
- line 1
68
-
69
- line 2
70
-
71
- `), `line 1
72
- line 2` + '\n');
73
-
74
- // ---------------------------------------------------------------------------
75
- simple.equal(96, truncateBlock(`line 1
76
- line 2
77
- line 3
78
- line 4`, 2), `line 1
79
- line 2` + '\n');
80
-
81
- // ---------------------------------------------------------------------------
82
- (function() {
83
- var lBlocks, str;
84
- lBlocks = ["import {say} from '@jdeighan/coffee-utils'", "", "<script>\n\tx = 42\n</script>", ""];
85
- str = joinBlocks(...lBlocks);
86
- return simple.equal(34, str, `import {say} from '@jdeighan/coffee-utils'
87
- <script>
88
- x = 42
89
- </script>`);
90
- })();
91
-
92
- // ---------------------------------------------------------------------------
93
- (function() {
94
- var code, lImports, str;
95
- lImports = ["import {say} from '@jdeighan/coffee-utils'"];
96
- code = `if (x==42)
97
- log "line 2 in unit test"`;
98
- str = joinBlocks(...lImports, code);
99
- return simple.equal(34, str, `
100
- import {say} from '@jdeighan/coffee-utils'
101
- if (x==42)
102
- log "line 2 in unit test"`);
103
- })();
104
-
105
- // ---------------------------------------------------------------------------
106
- // test forEachLine()
107
- (async function() {
108
- var callback, filepath, lLines;
109
- lLines = [];
110
- callback = function(line) {
111
- lLines.push(line);
112
- };
113
- filepath = "c:/Users/johnd/coffee-utils/test/data/file2.txt";
114
- await forEachLine(filepath, callback);
115
- return simple.equal(55, lLines, ["abc", "def", "ghi", "jkl"]);
116
- })();
117
-
118
- // ---------------------------------------------------------------------------
119
- // test forEachBlock()
120
- (async function() {
121
- var callback, filepath, lBlocks;
122
- lBlocks = [];
123
- callback = function(block) {
124
- lBlocks.push(block);
125
- };
126
- filepath = "c:/Users/johnd/coffee-utils/test/data/file3.txt";
127
- await forEachBlock(filepath, callback);
128
- return simple.equal(76, lBlocks, ["abc\ndef", "abc\ndef\nghi", "abc\ndef\nghi\njkl"]);
129
- })();
@@ -1,47 +0,0 @@
1
- # block2.test.coffee
2
-
3
- import assert from 'assert'
4
- import test from 'ava'
5
-
6
- import {
7
- undef, say, isString, isHash, isEmpty, nonEmpty,
8
- } from '@jdeighan/coffee-utils'
9
- import {mydir, mkpath} from '@jdeighan/coffee-utils/fs'
10
- import {UnitTester} from '@jdeighan/coffee-utils/test'
11
- import {
12
- forEachLine, forEachBlock, forEachSetOfBlocks,
13
- } from '@jdeighan/coffee-utils/block'
14
-
15
- testDir = mydir(`import.meta.url`)
16
- simple = new UnitTester()
17
-
18
- filepath = mkpath(testDir, 'code2.test.txt')
19
-
20
- # ----------------------------------------------------------------------------
21
-
22
- (() ->
23
- lFirstBlocks = undef
24
- callback = (lBlocks) ->
25
- lFirstBlocks = lBlocks
26
- return true # we're only interested in the first set
27
-
28
- test "line 29", (t) ->
29
- await forEachSetOfBlocks filepath, callback
30
- t.deepEqual lFirstBlocks, ["f()", "f"]
31
- )()
32
-
33
- # ----------------------------------------------------------------------------
34
-
35
- (() ->
36
- lAllBlockSets = []
37
- callback = (lBlocks) ->
38
- lAllBlockSets.push(lBlocks)
39
- return
40
-
41
- test "line 44", (t) ->
42
- await forEachSetOfBlocks filepath, callback
43
- t.deepEqual lAllBlockSets, [
44
- ["f()", "f"],
45
- ["f = (key=undef) ->\n\tswitch key\n\t\twhen 'ok'\n\t\t\tsay 'all is OK'", "f,say,mkpath"],
46
- ]
47
- )()
@@ -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
- )()