@jdeighan/coffee-utils 4.1.6 → 4.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- })();
@@ -1,148 +0,0 @@
1
- # fs.test.coffee
2
-
3
- import assert from 'assert'
4
- import {dirname, resolve} from 'path'
5
- import {fileURLToPath} from 'url'
6
- import {
7
- existsSync, copyFileSync, readFileSync, writeFileSync,
8
- } from 'fs'
9
-
10
- import {UnitTester} from '@jdeighan/coffee-utils/test'
11
- import {say, undef} from '@jdeighan/coffee-utils'
12
- import {debug} from '@jdeighan/coffee-utils/debug'
13
- import {
14
- mydir, mkpath, isFile, isDir, isSimpleFileName,
15
- getSubDirs, pathTo, getFullPath, parseSource, fileExt,
16
- withExt, withUnderScore,
17
- } from '@jdeighan/coffee-utils/fs'
18
-
19
- simple = new UnitTester()
20
-
21
- dir = mydir(`import.meta.url`)
22
- assert existsSync(dir)
23
-
24
- # ---------------------------------------------------------------------------
25
-
26
- hOpt = {removeLeadingUnderScore: true}
27
-
28
- simple.equal 21, withExt('file.py', 'svelte'), 'file.svelte'
29
- simple.equal 21, withExt('file.py', 'svelte', hOpt), 'file.svelte'
30
- simple.equal 21, withExt('_file.py', 'svelte', hOpt), 'file.svelte'
31
-
32
- simple.equal 21, withExt('/bin/file.py', 'svelte'), '/bin/file.svelte'
33
- simple.equal 21, withExt('/bin/file.py', 'svelte', hOpt), '/bin/file.svelte'
34
- simple.equal 21, withExt('/bin/_file.py', 'svelte', hOpt), '/bin/file.svelte'
35
-
36
- simple.equal 21, withUnderScore('file.py', 'svelte'), '_file.py'
37
- simple.equal 21, withUnderScore('_file.py', 'svelte'), '__file.py'
38
-
39
- simple.equal 21, withUnderScore('/bin/file.py', 'svelte'), '/bin/_file.py'
40
- simple.equal 21, withUnderScore('/bin/_file.py', 'svelte'), '/bin/__file.py'
41
-
42
- # ---------------------------------------------------------------------------
43
-
44
- (() ->
45
- fname = 'debug.test.coffee'
46
-
47
- simple.truthy 29, existsSync("#{dir}/#{fname}")
48
- simple.falsy 30, existsSync("#{dir}/nosuchfile.test.coffee")
49
- simple.equal 31, pathTo("#{fname}", dir), "#{dir}/#{fname}"
50
- )()
51
-
52
- # ---------------------------------------------------------------------------
53
-
54
- # --- dirs are returned in alphabetical order
55
- simple.equal 37, getSubDirs(dir), ['data','markdown','subdirectory']
56
-
57
- simple.equal 39, pathTo('test.txt', dir), \
58
- "#{dir}/subdirectory/test.txt"
59
-
60
- # ---------------------------------------------------------------------------
61
-
62
- simple.equal 44, mkpath('/usr/lib', 'johnd'), '/usr/lib/johnd'
63
- simple.equal 48, mkpath('', '/usr/lib', undef, 'johnd'), '/usr/lib/johnd'
64
- simple.equal 45, mkpath("c:", 'local/user'), 'c:/local/user'
65
- simple.equal 46, mkpath('/usr', 'lib', 'local', 'johnd'),
66
- '/usr/lib/local/johnd'
67
-
68
- simple.equal 48, mkpath('\\usr\\lib', 'johnd'), '/usr/lib/johnd'
69
- simple.equal 49, mkpath("c:", 'local\\user'), 'c:/local/user'
70
- simple.equal 50, mkpath('\\usr', 'lib', 'local', 'johnd'),
71
- '/usr/lib/local/johnd'
72
-
73
- simple.equal 55, mkpath('C:\\Users\\johnd', 'cielo'), 'c:/Users/johnd/cielo'
74
-
75
- # ---------------------------------------------------------------------------
76
- # test getFullPath()
77
-
78
- # --- current working directory is the root dir, i.e. parent of this directory
79
- wd = mkpath(process.cwd())
80
-
81
- myfname = 'fs.test.coffee'
82
- mypath = mkpath(dir, myfname)
83
- rootdir = mkpath(resolve(dir, '..'))
84
- assert rootdir == wd, "#{rootdir} should equal #{wd}"
85
-
86
- debug "Current Working Directory = '#{wd}'"
87
- debug "dir = '#{dir}'"
88
- debug "myfname = '#{myfname}'"
89
- debug "mypath = '#{mypath}'"
90
- debug "rootdir = '#{rootdir}'"
91
-
92
- # --- given a full path, only change \ to /
93
- simple.equal 72, getFullPath(mypath), mypath
94
-
95
- # --- given a simple file name, prepend the current working directory
96
- simple.equal 75, getFullPath(myfname), mkpath(rootdir, myfname)
97
-
98
- # --- leading . should be resolved
99
- simple.equal 78, getFullPath("./#{myfname}"), mkpath(rootdir, myfname)
100
-
101
- # --- leading .. should be resolved
102
- simple.equal 81, getFullPath("./test/../#{myfname}"), mkpath(rootdir, myfname)
103
-
104
- simple.equal 86, parseSource('unit test'), {
105
- filename: 'unit test'
106
- stub: 'unit test'
107
- }
108
-
109
- simple.equal 91, parseSource("c:/Users/johnd/oz/src/test.js"), {
110
- dir: 'c:/Users/johnd/oz/src'
111
- fullpath: 'c:/Users/johnd/oz/src/test.js'
112
- filename: 'test.js'
113
- stub: 'test'
114
- ext: '.js'
115
- }
116
-
117
- simple.equal 91, parseSource("c:\\Users\\johnd\\oz\\src\\test.js"), {
118
- dir: 'c:/Users/johnd/oz/src'
119
- fullpath: 'c:/Users/johnd/oz/src/test.js'
120
- filename: 'test.js'
121
- stub: 'test'
122
- ext: '.js'
123
- }
124
-
125
- if process.platform == 'win32'
126
- simple.truthy 108, isDir('c:/Users')
127
- simple.truthy 109, isDir('c:/Program Files')
128
- simple.falsy 110, isFile('c:/Users')
129
- simple.falsy 111, isFile('c:/Program Files')
130
-
131
- simple.falsy 113, isDir('c:/Windows/notepad.exe')
132
- simple.falsy 114, isDir(
133
- 'c:/Program Files/Windows Media Player/wmplayer.exe'
134
- )
135
- simple.truthy 115, isFile('c:/Windows/notepad.exe')
136
- simple.truthy 116, isFile(
137
- 'c:/Program Files/Windows Media Player/wmplayer.exe'
138
- )
139
-
140
- simple.truthy 118, isSimpleFileName('notepad.exe')
141
- simple.falsy 119, isSimpleFileName(
142
- 'c:/Program Files/Windows Media Player/wmplayer.exe'
143
- )
144
-
145
- simple.equal 121, fileExt('file.txt'), '.txt'
146
- simple.equal 122, fileExt('file.'), ''
147
- simple.equal 123, fileExt('file.99'), '.99'
148
- simple.equal 124, fileExt('file._txt'), '._txt'
package/.save/fs.test.js DELETED
@@ -1,191 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // fs.test.coffee
3
- var dir, hOpt, myfname, mypath, rootdir, simple, wd;
4
-
5
- import assert from 'assert';
6
-
7
- import {
8
- dirname,
9
- resolve
10
- } from 'path';
11
-
12
- import {
13
- fileURLToPath
14
- } from 'url';
15
-
16
- import {
17
- existsSync,
18
- copyFileSync,
19
- readFileSync,
20
- writeFileSync
21
- } from 'fs';
22
-
23
- import {
24
- UnitTester
25
- } from '@jdeighan/coffee-utils/test';
26
-
27
- import {
28
- say,
29
- undef
30
- } from '@jdeighan/coffee-utils';
31
-
32
- import {
33
- debug
34
- } from '@jdeighan/coffee-utils/debug';
35
-
36
- import {
37
- mydir,
38
- mkpath,
39
- isFile,
40
- isDir,
41
- isSimpleFileName,
42
- getSubDirs,
43
- pathTo,
44
- getFullPath,
45
- parseSource,
46
- fileExt,
47
- withExt,
48
- withUnderScore
49
- } from '@jdeighan/coffee-utils/fs';
50
-
51
- simple = new UnitTester();
52
-
53
- dir = mydir(import.meta.url);
54
-
55
- assert(existsSync(dir));
56
-
57
- // ---------------------------------------------------------------------------
58
- hOpt = {
59
- removeLeadingUnderScore: true
60
- };
61
-
62
- simple.equal(21, withExt('file.py', 'svelte'), 'file.svelte');
63
-
64
- simple.equal(21, withExt('file.py', 'svelte', hOpt), 'file.svelte');
65
-
66
- simple.equal(21, withExt('_file.py', 'svelte', hOpt), 'file.svelte');
67
-
68
- simple.equal(21, withExt('/bin/file.py', 'svelte'), '/bin/file.svelte');
69
-
70
- simple.equal(21, withExt('/bin/file.py', 'svelte', hOpt), '/bin/file.svelte');
71
-
72
- simple.equal(21, withExt('/bin/_file.py', 'svelte', hOpt), '/bin/file.svelte');
73
-
74
- simple.equal(21, withUnderScore('file.py', 'svelte'), '_file.py');
75
-
76
- simple.equal(21, withUnderScore('_file.py', 'svelte'), '__file.py');
77
-
78
- simple.equal(21, withUnderScore('/bin/file.py', 'svelte'), '/bin/_file.py');
79
-
80
- simple.equal(21, withUnderScore('/bin/_file.py', 'svelte'), '/bin/__file.py');
81
-
82
- // ---------------------------------------------------------------------------
83
- (function() {
84
- var fname;
85
- fname = 'debug.test.coffee';
86
- simple.truthy(29, existsSync(`${dir}/${fname}`));
87
- simple.falsy(30, existsSync(`${dir}/nosuchfile.test.coffee`));
88
- return simple.equal(31, pathTo(`${fname}`, dir), `${dir}/${fname}`);
89
- })();
90
-
91
- // ---------------------------------------------------------------------------
92
-
93
- // --- dirs are returned in alphabetical order
94
- simple.equal(37, getSubDirs(dir), ['data', 'markdown', 'subdirectory']);
95
-
96
- simple.equal(39, pathTo('test.txt', dir), `${dir}/subdirectory/test.txt`);
97
-
98
- // ---------------------------------------------------------------------------
99
- simple.equal(44, mkpath('/usr/lib', 'johnd'), '/usr/lib/johnd');
100
-
101
- simple.equal(48, mkpath('', '/usr/lib', undef, 'johnd'), '/usr/lib/johnd');
102
-
103
- simple.equal(45, mkpath("c:", 'local/user'), 'c:/local/user');
104
-
105
- simple.equal(46, mkpath('/usr', 'lib', 'local', 'johnd'), '/usr/lib/local/johnd');
106
-
107
- simple.equal(48, mkpath('\\usr\\lib', 'johnd'), '/usr/lib/johnd');
108
-
109
- simple.equal(49, mkpath("c:", 'local\\user'), 'c:/local/user');
110
-
111
- simple.equal(50, mkpath('\\usr', 'lib', 'local', 'johnd'), '/usr/lib/local/johnd');
112
-
113
- simple.equal(55, mkpath('C:\\Users\\johnd', 'cielo'), 'c:/Users/johnd/cielo');
114
-
115
- // ---------------------------------------------------------------------------
116
- // test getFullPath()
117
-
118
- // --- current working directory is the root dir, i.e. parent of this directory
119
- wd = mkpath(process.cwd());
120
-
121
- myfname = 'fs.test.coffee';
122
-
123
- mypath = mkpath(dir, myfname);
124
-
125
- rootdir = mkpath(resolve(dir, '..'));
126
-
127
- assert(rootdir === wd, `${rootdir} should equal ${wd}`);
128
-
129
- debug(`Current Working Directory = '${wd}'`);
130
-
131
- debug(`dir = '${dir}'`);
132
-
133
- debug(`myfname = '${myfname}'`);
134
-
135
- debug(`mypath = '${mypath}'`);
136
-
137
- debug(`rootdir = '${rootdir}'`);
138
-
139
- // --- given a full path, only change \ to /
140
- simple.equal(72, getFullPath(mypath), mypath);
141
-
142
- // --- given a simple file name, prepend the current working directory
143
- simple.equal(75, getFullPath(myfname), mkpath(rootdir, myfname));
144
-
145
- // --- leading . should be resolved
146
- simple.equal(78, getFullPath(`./${myfname}`), mkpath(rootdir, myfname));
147
-
148
- // --- leading .. should be resolved
149
- simple.equal(81, getFullPath(`./test/../${myfname}`), mkpath(rootdir, myfname));
150
-
151
- simple.equal(86, parseSource('unit test'), {
152
- filename: 'unit test',
153
- stub: 'unit test'
154
- });
155
-
156
- simple.equal(91, parseSource("c:/Users/johnd/oz/src/test.js"), {
157
- dir: 'c:/Users/johnd/oz/src',
158
- fullpath: 'c:/Users/johnd/oz/src/test.js',
159
- filename: 'test.js',
160
- stub: 'test',
161
- ext: '.js'
162
- });
163
-
164
- simple.equal(91, parseSource("c:\\Users\\johnd\\oz\\src\\test.js"), {
165
- dir: 'c:/Users/johnd/oz/src',
166
- fullpath: 'c:/Users/johnd/oz/src/test.js',
167
- filename: 'test.js',
168
- stub: 'test',
169
- ext: '.js'
170
- });
171
-
172
- if (process.platform === 'win32') {
173
- simple.truthy(108, isDir('c:/Users'));
174
- simple.truthy(109, isDir('c:/Program Files'));
175
- simple.falsy(110, isFile('c:/Users'));
176
- simple.falsy(111, isFile('c:/Program Files'));
177
- simple.falsy(113, isDir('c:/Windows/notepad.exe'));
178
- simple.falsy(114, isDir('c:/Program Files/Windows Media Player/wmplayer.exe'));
179
- simple.truthy(115, isFile('c:/Windows/notepad.exe'));
180
- simple.truthy(116, isFile('c:/Program Files/Windows Media Player/wmplayer.exe'));
181
- simple.truthy(118, isSimpleFileName('notepad.exe'));
182
- simple.falsy(119, isSimpleFileName('c:/Program Files/Windows Media Player/wmplayer.exe'));
183
- }
184
-
185
- simple.equal(121, fileExt('file.txt'), '.txt');
186
-
187
- simple.equal(122, fileExt('file.'), '');
188
-
189
- simple.equal(123, fileExt('file.99'), '.99');
190
-
191
- simple.equal(124, fileExt('file._txt'), '._txt');