@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.
- package/package.json +3 -2
- package/src/block_utils.coffee +4 -0
- package/src/block_utils.js +5 -0
- package/src/coffee_utils.coffee +28 -0
- package/src/coffee_utils.js +31 -0
- package/src/debug_utils.coffee +1 -0
- package/src/debug_utils.js +1 -0
- package/src/fs_utils.coffee +21 -1
- package/src/fs_utils.js +24 -0
- package/src/indent_utils.coffee +4 -1
- package/src/indent_utils.js +9 -4
- package/.save/block.test.coffee +0 -185
- package/.save/block.test.js +0 -129
- package/.save/block2.test.coffee +0 -47
- package/.save/block2.test.js +0 -64
- package/.save/debug.test.coffee +0 -290
- package/.save/debug.test.js +0 -242
- package/.save/fs.test.coffee +0 -148
- package/.save/fs.test.js +0 -191
- package/.save/indent.test.coffee +0 -130
- package/.save/indent.test.js +0 -136
- package/.save/log.test.coffee +0 -315
- package/.save/log.test.js +0 -336
- package/.save/privenv.test.coffee +0 -38
- package/.save/privenv.test.js +0 -54
- package/.save/temp.coffee +0 -19
- package/.save/temp.js +0 -28
- package/.save/tester.test.coffee +0 -75
- package/.save/tester.test.js +0 -93
- package/.save/utils.test.coffee +0 -214
- package/.save/utils.test.js +0 -319
package/.save/fs.test.coffee
DELETED
|
@@ -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');
|
package/.save/indent.test.coffee
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
# indent.test.coffee
|
|
2
|
-
|
|
3
|
-
import assert from 'assert'
|
|
4
|
-
|
|
5
|
-
import {UnitTester} from '@jdeighan/coffee-utils/test'
|
|
6
|
-
import {isInteger} from '@jdeighan/coffee-utils'
|
|
7
|
-
import {
|
|
8
|
-
indentLevel, indentation, undented, splitLine,
|
|
9
|
-
indented, tabify, untabify,
|
|
10
|
-
} from '@jdeighan/coffee-utils/indent'
|
|
11
|
-
|
|
12
|
-
simple = new UnitTester()
|
|
13
|
-
|
|
14
|
-
# ---------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
simple.equal 16, indentLevel("abc"), 0
|
|
17
|
-
simple.equal 17, indentLevel("\tabc"), 1
|
|
18
|
-
simple.equal 18, indentLevel("\t\tabc"), 2
|
|
19
|
-
|
|
20
|
-
# ---------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
simple.equal 22, indentation(0), ''
|
|
23
|
-
simple.equal 23, indentation(1), "\t"
|
|
24
|
-
simple.equal 24, indentation(2), "\t\t"
|
|
25
|
-
|
|
26
|
-
# ---------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
simple.equal 28, undented("abc"), "abc"
|
|
29
|
-
simple.equal 29, undented("\tabc"), "abc"
|
|
30
|
-
simple.equal 30, undented("\t\tabc"), "abc"
|
|
31
|
-
simple.equal 31, undented("\t\tabc", 0), "\t\tabc"
|
|
32
|
-
simple.equal 32, undented("\t\tabc", 1), "\tabc"
|
|
33
|
-
simple.equal 33, undented("\t\tabc", 2), "abc"
|
|
34
|
-
|
|
35
|
-
# ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
simple.equal 37, undented("\t\tfirst\n\t\tsecond\n\t\t\tthird\n"),
|
|
38
|
-
"first\nsecond\n\tthird\n",
|
|
39
|
-
|
|
40
|
-
# ---------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
simple.equal 42, splitLine("abc"), [0, "abc"]
|
|
43
|
-
simple.equal 43, splitLine("\tabc"), [1, "abc"]
|
|
44
|
-
simple.equal 44, splitLine("\t\tabc"), [2, "abc"]
|
|
45
|
-
simple.equal 45, splitLine("\t\t\t"), [0, ""]
|
|
46
|
-
|
|
47
|
-
# ---------------------------------------------------------------------------
|
|
48
|
-
|
|
49
|
-
simple.equal 49, indented("abc", 0), "abc"
|
|
50
|
-
simple.equal 50, indented("abc", 1), "\tabc"
|
|
51
|
-
simple.equal 51, indented("abc", 2), "\t\tabc"
|
|
52
|
-
|
|
53
|
-
# --- empty lines, indented, should just be empty lines
|
|
54
|
-
simple.equal 54, indented("abc\n\ndef", 2), "\t\tabc\n\n\t\tdef"
|
|
55
|
-
|
|
56
|
-
(() ->
|
|
57
|
-
str = "main\n\toverflow: auto\n\nnav\n\toverflow: auto"
|
|
58
|
-
exp = "\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto"
|
|
59
|
-
simple.equal 59, indented(str, 1), exp
|
|
60
|
-
)()
|
|
61
|
-
|
|
62
|
-
# --- indented also handles arrays, so test them, too
|
|
63
|
-
|
|
64
|
-
# --- empty lines, indented, should just be empty lines
|
|
65
|
-
simple.equal 65, indented(['abc','','def'], 2), '\t\tabc\n\n\t\tdef'
|
|
66
|
-
|
|
67
|
-
(() ->
|
|
68
|
-
lLines = ['main','\toverflow: auto','','nav','\toverflow: auto']
|
|
69
|
-
lExp = '\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto'
|
|
70
|
-
simple.equal 70, indented(lLines, 1), lExp
|
|
71
|
-
)()
|
|
72
|
-
|
|
73
|
-
# ---------------------------------------------------------------------------
|
|
74
|
-
|
|
75
|
-
(() ->
|
|
76
|
-
prefix = ' ' # 3 spaces
|
|
77
|
-
|
|
78
|
-
simple.equal 78, tabify("""
|
|
79
|
-
first line
|
|
80
|
-
#{prefix}second line
|
|
81
|
-
#{prefix}#{prefix}third line
|
|
82
|
-
""", 3), """
|
|
83
|
-
first line
|
|
84
|
-
\tsecond line
|
|
85
|
-
\t\tthird line
|
|
86
|
-
"""
|
|
87
|
-
)()
|
|
88
|
-
|
|
89
|
-
# ---------------------------------------------------------------------------
|
|
90
|
-
# you don't need to tell it number of spaces
|
|
91
|
-
|
|
92
|
-
(() ->
|
|
93
|
-
prefix = ' ' # 3 spaces
|
|
94
|
-
|
|
95
|
-
simple.equal 95, tabify("""
|
|
96
|
-
first line
|
|
97
|
-
#{prefix}second line
|
|
98
|
-
#{prefix}#{prefix}third line
|
|
99
|
-
"""), """
|
|
100
|
-
first line
|
|
101
|
-
\tsecond line
|
|
102
|
-
\t\tthird line
|
|
103
|
-
"""
|
|
104
|
-
)()
|
|
105
|
-
|
|
106
|
-
# ---------------------------------------------------------------------------
|
|
107
|
-
|
|
108
|
-
(() ->
|
|
109
|
-
prefix = ' ' # 3 spaces
|
|
110
|
-
|
|
111
|
-
simple.equal 111, untabify("""
|
|
112
|
-
first line
|
|
113
|
-
\tsecond line
|
|
114
|
-
\t\tthird line
|
|
115
|
-
""", 3), """
|
|
116
|
-
first line
|
|
117
|
-
#{prefix}second line
|
|
118
|
-
#{prefix}#{prefix}third line
|
|
119
|
-
"""
|
|
120
|
-
)()
|
|
121
|
-
|
|
122
|
-
# ---------------------------------------------------------------------------
|
|
123
|
-
|
|
124
|
-
simple.equal 124, indented("export name = undef", 1), "\texport name = undef"
|
|
125
|
-
simple.equal 125, indented("export name = undef", 2), "\t\texport name = undef"
|
|
126
|
-
|
|
127
|
-
# ---------------------------------------------------------------------------
|
|
128
|
-
# make sure indentLevel() works for blocks
|
|
129
|
-
|
|
130
|
-
simple.equal 130, indentLevel("\t\tabc\n\t\tdef\n\t\t\tghi"), 2
|
package/.save/indent.test.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 2.6.1
|
|
2
|
-
// indent.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
|
-
isInteger
|
|
13
|
-
} from '@jdeighan/coffee-utils';
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
indentLevel,
|
|
17
|
-
indentation,
|
|
18
|
-
undented,
|
|
19
|
-
splitLine,
|
|
20
|
-
indented,
|
|
21
|
-
tabify,
|
|
22
|
-
untabify
|
|
23
|
-
} from '@jdeighan/coffee-utils/indent';
|
|
24
|
-
|
|
25
|
-
simple = new UnitTester();
|
|
26
|
-
|
|
27
|
-
// ---------------------------------------------------------------------------
|
|
28
|
-
simple.equal(16, indentLevel("abc"), 0);
|
|
29
|
-
|
|
30
|
-
simple.equal(17, indentLevel("\tabc"), 1);
|
|
31
|
-
|
|
32
|
-
simple.equal(18, indentLevel("\t\tabc"), 2);
|
|
33
|
-
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
simple.equal(22, indentation(0), '');
|
|
36
|
-
|
|
37
|
-
simple.equal(23, indentation(1), "\t");
|
|
38
|
-
|
|
39
|
-
simple.equal(24, indentation(2), "\t\t");
|
|
40
|
-
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
simple.equal(28, undented("abc"), "abc");
|
|
43
|
-
|
|
44
|
-
simple.equal(29, undented("\tabc"), "abc");
|
|
45
|
-
|
|
46
|
-
simple.equal(30, undented("\t\tabc"), "abc");
|
|
47
|
-
|
|
48
|
-
simple.equal(31, undented("\t\tabc", 0), "\t\tabc");
|
|
49
|
-
|
|
50
|
-
simple.equal(32, undented("\t\tabc", 1), "\tabc");
|
|
51
|
-
|
|
52
|
-
simple.equal(33, undented("\t\tabc", 2), "abc");
|
|
53
|
-
|
|
54
|
-
// ---------------------------------------------------------------------------
|
|
55
|
-
simple.equal(37, undented("\t\tfirst\n\t\tsecond\n\t\t\tthird\n"), "first\nsecond\n\tthird\n");
|
|
56
|
-
|
|
57
|
-
// ---------------------------------------------------------------------------
|
|
58
|
-
simple.equal(42, splitLine("abc"), [0, "abc"]);
|
|
59
|
-
|
|
60
|
-
simple.equal(43, splitLine("\tabc"), [1, "abc"]);
|
|
61
|
-
|
|
62
|
-
simple.equal(44, splitLine("\t\tabc"), [2, "abc"]);
|
|
63
|
-
|
|
64
|
-
simple.equal(45, splitLine("\t\t\t"), [0, ""]);
|
|
65
|
-
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
simple.equal(49, indented("abc", 0), "abc");
|
|
68
|
-
|
|
69
|
-
simple.equal(50, indented("abc", 1), "\tabc");
|
|
70
|
-
|
|
71
|
-
simple.equal(51, indented("abc", 2), "\t\tabc");
|
|
72
|
-
|
|
73
|
-
// --- empty lines, indented, should just be empty lines
|
|
74
|
-
simple.equal(54, indented("abc\n\ndef", 2), "\t\tabc\n\n\t\tdef");
|
|
75
|
-
|
|
76
|
-
(function() {
|
|
77
|
-
var exp, str;
|
|
78
|
-
str = "main\n\toverflow: auto\n\nnav\n\toverflow: auto";
|
|
79
|
-
exp = "\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto";
|
|
80
|
-
return simple.equal(59, indented(str, 1), exp);
|
|
81
|
-
})();
|
|
82
|
-
|
|
83
|
-
// --- indented also handles arrays, so test them, too
|
|
84
|
-
|
|
85
|
-
// --- empty lines, indented, should just be empty lines
|
|
86
|
-
simple.equal(65, indented(['abc', '', 'def'], 2), '\t\tabc\n\n\t\tdef');
|
|
87
|
-
|
|
88
|
-
(function() {
|
|
89
|
-
var lExp, lLines;
|
|
90
|
-
lLines = ['main', '\toverflow: auto', '', 'nav', '\toverflow: auto'];
|
|
91
|
-
lExp = '\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto';
|
|
92
|
-
return simple.equal(70, indented(lLines, 1), lExp);
|
|
93
|
-
})();
|
|
94
|
-
|
|
95
|
-
// ---------------------------------------------------------------------------
|
|
96
|
-
(function() {
|
|
97
|
-
var prefix;
|
|
98
|
-
prefix = ' '; // 3 spaces
|
|
99
|
-
return simple.equal(78, tabify(`first line
|
|
100
|
-
${prefix}second line
|
|
101
|
-
${prefix}${prefix}third line`, 3), `first line
|
|
102
|
-
\tsecond line
|
|
103
|
-
\t\tthird line`);
|
|
104
|
-
})();
|
|
105
|
-
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
// you don't need to tell it number of spaces
|
|
108
|
-
(function() {
|
|
109
|
-
var prefix;
|
|
110
|
-
prefix = ' '; // 3 spaces
|
|
111
|
-
return simple.equal(95, tabify(`first line
|
|
112
|
-
${prefix}second line
|
|
113
|
-
${prefix}${prefix}third line`), `first line
|
|
114
|
-
\tsecond line
|
|
115
|
-
\t\tthird line`);
|
|
116
|
-
})();
|
|
117
|
-
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
(function() {
|
|
120
|
-
var prefix;
|
|
121
|
-
prefix = ' '; // 3 spaces
|
|
122
|
-
return simple.equal(111, untabify(`first line
|
|
123
|
-
\tsecond line
|
|
124
|
-
\t\tthird line`, 3), `first line
|
|
125
|
-
${prefix}second line
|
|
126
|
-
${prefix}${prefix}third line`);
|
|
127
|
-
})();
|
|
128
|
-
|
|
129
|
-
// ---------------------------------------------------------------------------
|
|
130
|
-
simple.equal(124, indented("export name = undef", 1), "\texport name = undef");
|
|
131
|
-
|
|
132
|
-
simple.equal(125, indented("export name = undef", 2), "\t\texport name = undef");
|
|
133
|
-
|
|
134
|
-
// ---------------------------------------------------------------------------
|
|
135
|
-
// make sure indentLevel() works for blocks
|
|
136
|
-
simple.equal(130, indentLevel("\t\tabc\n\t\tdef\n\t\t\tghi"), 2);
|