@jdeighan/coffee-utils 4.1.1 → 4.1.5
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -2
- package/src/UnitTester.coffee +3 -6
- package/src/UnitTester.js +4 -7
- package/src/coffee_utils.coffee +11 -3
- package/src/coffee_utils.js +12 -3
- package/src/debug_utils.coffee +1 -1
- package/src/debug_utils.js +1 -1
- package/src/log_utils.coffee +17 -3
- package/src/log_utils.js +17 -3
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "4.1.
|
4
|
+
"version": "4.1.5",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -42,6 +42,7 @@
|
|
42
42
|
"dependencies": {
|
43
43
|
"ava": "^3.15.0",
|
44
44
|
"cross-env": "^7.0.3",
|
45
|
-
"js-yaml": "^4.1.0"
|
45
|
+
"js-yaml": "^4.1.0",
|
46
|
+
"readline-sync": "^1.4.10"
|
46
47
|
}
|
47
48
|
}
|
package/src/UnitTester.coffee
CHANGED
@@ -14,9 +14,9 @@ import {debug, debugging, setDebugging} from '@jdeighan/coffee-utils/debug'
|
|
14
14
|
|
15
15
|
export class UnitTester
|
16
16
|
|
17
|
-
constructor: (
|
17
|
+
constructor: (@file='unknown file') ->
|
18
18
|
@hFound = {}
|
19
|
-
@
|
19
|
+
@whichTest = 'deepEqual'
|
20
20
|
@justshow = false
|
21
21
|
@testing = true
|
22
22
|
@maxLineNum = undef
|
@@ -180,7 +180,7 @@ export class UnitTester
|
|
180
180
|
@lineNum = lineNum # set an object property
|
181
181
|
|
182
182
|
if (lineNum < 0) && process.env.FINALTEST
|
183
|
-
error "Negative line numbers not allowed in FINALTEST"
|
183
|
+
error "Negative line numbers not allowed in FINALTEST in #{@file}"
|
184
184
|
|
185
185
|
if ! @testing || (@maxLineNum && (lineNum > @maxLineNum))
|
186
186
|
return
|
@@ -242,9 +242,6 @@ export class UnitTester
|
|
242
242
|
|
243
243
|
getLineNum: (lineNum) ->
|
244
244
|
|
245
|
-
if @fulltest && (lineNum < 0)
|
246
|
-
error "UnitTester(): negative line number during full test!!!"
|
247
|
-
|
248
245
|
# --- patch lineNum to avoid duplicates
|
249
246
|
while @hFound[lineNum]
|
250
247
|
if lineNum < 0
|
package/src/UnitTester.js
CHANGED
@@ -32,10 +32,10 @@ import {
|
|
32
32
|
|
33
33
|
// ---------------------------------------------------------------------------
|
34
34
|
export var UnitTester = class UnitTester {
|
35
|
-
constructor(
|
36
|
-
this.
|
35
|
+
constructor(file = 'unknown file') {
|
36
|
+
this.file = file;
|
37
37
|
this.hFound = {};
|
38
|
-
this.
|
38
|
+
this.whichTest = 'deepEqual';
|
39
39
|
this.justshow = false;
|
40
40
|
this.testing = true;
|
41
41
|
this.maxLineNum = undef;
|
@@ -189,7 +189,7 @@ export var UnitTester = class UnitTester {
|
|
189
189
|
this.initialize();
|
190
190
|
this.lineNum = lineNum; // set an object property
|
191
191
|
if ((lineNum < 0) && process.env.FINALTEST) {
|
192
|
-
error(
|
192
|
+
error(`Negative line numbers not allowed in FINALTEST in ${this.file}`);
|
193
193
|
}
|
194
194
|
if (!this.testing || (this.maxLineNum && (lineNum > this.maxLineNum))) {
|
195
195
|
return;
|
@@ -256,9 +256,6 @@ export var UnitTester = class UnitTester {
|
|
256
256
|
|
257
257
|
// ........................................................................
|
258
258
|
getLineNum(lineNum) {
|
259
|
-
if (this.fulltest && (lineNum < 0)) {
|
260
|
-
error("UnitTester(): negative line number during full test!!!");
|
261
|
-
}
|
262
259
|
// --- patch lineNum to avoid duplicates
|
263
260
|
while (this.hFound[lineNum]) {
|
264
261
|
if (lineNum < 0) {
|
package/src/coffee_utils.coffee
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coffee_utils.coffee
|
2
2
|
|
3
|
+
import getline from 'readline-sync'
|
3
4
|
import {log} from '@jdeighan/coffee-utils/log'
|
4
5
|
|
5
6
|
export sep_dash = '-'.repeat(42)
|
@@ -201,6 +202,12 @@ export isInteger = (x) ->
|
|
201
202
|
else
|
202
203
|
return false
|
203
204
|
|
205
|
+
# ---------------------------------------------------------------------------
|
206
|
+
|
207
|
+
export uniq = (lItems) ->
|
208
|
+
|
209
|
+
return [...new Set(lItems)]
|
210
|
+
|
204
211
|
# ---------------------------------------------------------------------------
|
205
212
|
# warn - issue a warning
|
206
213
|
|
@@ -212,9 +219,9 @@ export warn = (message) ->
|
|
212
219
|
# say - print to the console (for now)
|
213
220
|
# later, on a web page, call alert(str)
|
214
221
|
|
215
|
-
export say = (str
|
222
|
+
export say = (str) ->
|
216
223
|
|
217
|
-
log str
|
224
|
+
console.log str
|
218
225
|
return
|
219
226
|
|
220
227
|
# ---------------------------------------------------------------------------
|
@@ -223,7 +230,8 @@ export say = (str, obj=undef) ->
|
|
223
230
|
|
224
231
|
export ask = (prompt) ->
|
225
232
|
|
226
|
-
|
233
|
+
answer = getline.question("{prompt}? ")
|
234
|
+
return answer
|
227
235
|
|
228
236
|
# ---------------------------------------------------------------------------
|
229
237
|
|
package/src/coffee_utils.js
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
// coffee_utils.coffee
|
3
3
|
var commentRegExp;
|
4
4
|
|
5
|
+
import getline from 'readline-sync';
|
6
|
+
|
5
7
|
import {
|
6
8
|
log
|
7
9
|
} from '@jdeighan/coffee-utils/log';
|
@@ -208,6 +210,11 @@ export var isInteger = function(x) {
|
|
208
210
|
}
|
209
211
|
};
|
210
212
|
|
213
|
+
// ---------------------------------------------------------------------------
|
214
|
+
export var uniq = function(lItems) {
|
215
|
+
return [...new Set(lItems)];
|
216
|
+
};
|
217
|
+
|
211
218
|
// ---------------------------------------------------------------------------
|
212
219
|
// warn - issue a warning
|
213
220
|
export var warn = function(message) {
|
@@ -217,15 +224,17 @@ export var warn = function(message) {
|
|
217
224
|
// ---------------------------------------------------------------------------
|
218
225
|
// say - print to the console (for now)
|
219
226
|
// later, on a web page, call alert(str)
|
220
|
-
export var say = function(str
|
221
|
-
log(str
|
227
|
+
export var say = function(str) {
|
228
|
+
console.log(str);
|
222
229
|
};
|
223
230
|
|
224
231
|
// ---------------------------------------------------------------------------
|
225
232
|
// ask - ask a question
|
226
233
|
// later, on a web page, prompt the user for answer to question
|
227
234
|
export var ask = function(prompt) {
|
228
|
-
|
235
|
+
var answer;
|
236
|
+
answer = getline.question("{prompt}? ");
|
237
|
+
return answer;
|
229
238
|
};
|
230
239
|
|
231
240
|
// ---------------------------------------------------------------------------
|
package/src/debug_utils.coffee
CHANGED
package/src/debug_utils.js
CHANGED
package/src/log_utils.coffee
CHANGED
@@ -25,7 +25,6 @@ export setLogger = (func) ->
|
|
25
25
|
return orgLogger
|
26
26
|
|
27
27
|
# ---------------------------------------------------------------------------
|
28
|
-
# the default stringifier
|
29
28
|
|
30
29
|
export tamlStringify = (obj) ->
|
31
30
|
|
@@ -39,9 +38,24 @@ export tamlStringify = (obj) ->
|
|
39
38
|
str = str.replace(/\t/g, ' ') # fr***ing Windows Terminal
|
40
39
|
return str
|
41
40
|
|
41
|
+
# ---------------------------------------------------------------------------
|
42
|
+
# the default stringifier
|
43
|
+
|
44
|
+
export orderedStringify = (obj) ->
|
45
|
+
|
46
|
+
str = yaml.dump(obj, {
|
47
|
+
skipInvalid: true
|
48
|
+
indent: 1
|
49
|
+
sortKeys: true
|
50
|
+
lineWidth: -1
|
51
|
+
})
|
52
|
+
str = "---\n" + tabify(str)
|
53
|
+
str = str.replace(/\t/g, ' ') # fr***ing Windows Terminal
|
54
|
+
return str
|
55
|
+
|
42
56
|
# ---------------------------------------------------------------------------
|
43
57
|
|
44
|
-
export stringify =
|
58
|
+
export stringify = orderedStringify # for non-strings
|
45
59
|
|
46
60
|
# ---------------------------------------------------------------------------
|
47
61
|
|
@@ -51,7 +65,7 @@ export setStringifier = (func) ->
|
|
51
65
|
assert isFunction(func), "setStringifier() not a function"
|
52
66
|
stringify = func
|
53
67
|
else
|
54
|
-
stringify =
|
68
|
+
stringify = orderedStringify
|
55
69
|
return
|
56
70
|
|
57
71
|
# ---------------------------------------------------------------------------
|
package/src/log_utils.js
CHANGED
@@ -41,7 +41,6 @@ export var setLogger = function(func) {
|
|
41
41
|
};
|
42
42
|
|
43
43
|
// ---------------------------------------------------------------------------
|
44
|
-
// the default stringifier
|
45
44
|
export var tamlStringify = function(obj) {
|
46
45
|
var str;
|
47
46
|
str = yaml.dump(obj, {
|
@@ -56,7 +55,22 @@ export var tamlStringify = function(obj) {
|
|
56
55
|
};
|
57
56
|
|
58
57
|
// ---------------------------------------------------------------------------
|
59
|
-
|
58
|
+
// the default stringifier
|
59
|
+
export var orderedStringify = function(obj) {
|
60
|
+
var str;
|
61
|
+
str = yaml.dump(obj, {
|
62
|
+
skipInvalid: true,
|
63
|
+
indent: 1,
|
64
|
+
sortKeys: true,
|
65
|
+
lineWidth: -1
|
66
|
+
});
|
67
|
+
str = "---\n" + tabify(str);
|
68
|
+
str = str.replace(/\t/g, ' '); // fr***ing Windows Terminal
|
69
|
+
return str;
|
70
|
+
};
|
71
|
+
|
72
|
+
// ---------------------------------------------------------------------------
|
73
|
+
export var stringify = orderedStringify; // for non-strings
|
60
74
|
|
61
75
|
|
62
76
|
// ---------------------------------------------------------------------------
|
@@ -65,7 +79,7 @@ export var setStringifier = function(func) {
|
|
65
79
|
assert(isFunction(func), "setStringifier() not a function");
|
66
80
|
stringify = func;
|
67
81
|
} else {
|
68
|
-
stringify =
|
82
|
+
stringify = orderedStringify;
|
69
83
|
}
|
70
84
|
};
|
71
85
|
|