fable 3.0.31 → 3.0.32
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/README.md +33 -63
- package/debug/Harness.js +16 -2
- package/dist/fable.compatible.js +312 -271
- package/dist/fable.compatible.min.js +21 -21
- package/dist/fable.compatible.min.js.map +1 -1
- package/dist/fable.js +278 -237
- package/dist/fable.min.js +20 -20
- package/dist/fable.min.js.map +1 -1
- package/package.json +1 -1
- package/source/Fable.js +2 -2
- package/source/services/Fable-Service-DataFormat.js +638 -0
- package/source/services/Fable-Service-RestClient.js +81 -3
- package/source/services/Fable-Service-Utility.js +70 -0
- package/test/DataFormat-StringDateFormatting_tests.js +109 -0
- package/test/{FableDataArithmatic_tests.js → DataFormat-StringManipulation_tests.js} +88 -46
- package/test/DataFormat-StringNumberFormatting_tests.js +110 -0
- package/test/DataFormat-StringTokenization_tests.js +167 -0
- package/test/RestClient_test.js +54 -0
- package/test/{FableUtility_tests.js → Utility_tests.js} +13 -0
- /package/test/{FableOperations_tests.js → FableOperation_tests.js} +0 -0
- /package/test/{FableMetaTemplating_tests.js → MetaTemplating_tests.js} +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for DataArithmatic
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var libFable = require('../source/Fable.js');
|
|
10
|
+
|
|
11
|
+
var Chai = require("chai");
|
|
12
|
+
var Expect = Chai.expect;
|
|
13
|
+
|
|
14
|
+
suite
|
|
15
|
+
(
|
|
16
|
+
'DataArithmatic String Tokenization',
|
|
17
|
+
function()
|
|
18
|
+
{
|
|
19
|
+
setup (()=> {} );
|
|
20
|
+
|
|
21
|
+
suite
|
|
22
|
+
(
|
|
23
|
+
'Manipulate Strings',
|
|
24
|
+
()=>
|
|
25
|
+
{
|
|
26
|
+
test
|
|
27
|
+
(
|
|
28
|
+
'Test getting a string before a match',
|
|
29
|
+
(fTestComplete)=>
|
|
30
|
+
{
|
|
31
|
+
let testFable = new libFable({LogStreams: false});
|
|
32
|
+
let _DataFormat = testFable.defaultServices.DataFormat;
|
|
33
|
+
Expect(_DataFormat
|
|
34
|
+
.stringBeforeMatch('Dogs are cool', 'are'))
|
|
35
|
+
.to.equal('Dogs ');
|
|
36
|
+
Expect(_DataFormat
|
|
37
|
+
.stringBeforeMatch('These.Are.All.Words', '.'))
|
|
38
|
+
.to.equal('These');
|
|
39
|
+
Expect(_DataFormat
|
|
40
|
+
.stringBeforeMatch('These.Are.All.Words', 'NoMatchesHere'))
|
|
41
|
+
.to.equal('These.Are.All.Words');
|
|
42
|
+
return fTestComplete();
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
test
|
|
46
|
+
(
|
|
47
|
+
'Test getting a string after a match',
|
|
48
|
+
(fTestComplete)=>
|
|
49
|
+
{
|
|
50
|
+
let testFable = new libFable({LogStreams: false});
|
|
51
|
+
let _DataFormat = testFable.defaultServices.DataFormat;
|
|
52
|
+
Expect(_DataFormat
|
|
53
|
+
.stringAfterMatch('Dogs are cool', 'are'))
|
|
54
|
+
.to.equal(' cool');
|
|
55
|
+
Expect(_DataFormat
|
|
56
|
+
.stringAfterMatch('These.Are.All.Words', '.'))
|
|
57
|
+
.to.equal('Are.All.Words');
|
|
58
|
+
Expect(_DataFormat
|
|
59
|
+
.stringAfterMatch('These.Are.All.Words', 'NoMatchesHere'))
|
|
60
|
+
.to.equal('');
|
|
61
|
+
return fTestComplete();
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
test
|
|
65
|
+
(
|
|
66
|
+
'Test counting enclosures',
|
|
67
|
+
(fTestComplete)=>
|
|
68
|
+
{
|
|
69
|
+
let testFable = new libFable({LogStreams: false});
|
|
70
|
+
let _DataFormat = testFable.defaultServices.DataFormat;
|
|
71
|
+
Expect(_DataFormat
|
|
72
|
+
.stringCountEnclosures('Dogs (are) cool'))
|
|
73
|
+
.to.equal(1);
|
|
74
|
+
Expect(_DataFormat
|
|
75
|
+
.stringCountEnclosures('Dogs are cool'))
|
|
76
|
+
.to.equal(0);
|
|
77
|
+
// It should not count nested enclosures.
|
|
78
|
+
// Although with getEnclosureValueByIndex and recalling this, you can recursively get them.
|
|
79
|
+
Expect(_DataFormat
|
|
80
|
+
.stringCountEnclosures('There (are (many)) of these (things)'))
|
|
81
|
+
.to.equal(2);
|
|
82
|
+
Expect(_DataFormat
|
|
83
|
+
.stringCountEnclosures('There [are (many)] of these (things)'))
|
|
84
|
+
.to.equal(2);
|
|
85
|
+
// You can also specify the enclosure characters
|
|
86
|
+
Expect(_DataFormat
|
|
87
|
+
.stringCountEnclosures('There [are (many)] of these (things)', '[', ']'))
|
|
88
|
+
.to.equal(1);
|
|
89
|
+
// It does not *require* a closing character and still counts the enclosure.
|
|
90
|
+
// Hotly debated topic. A setting could be added to change this behavior.
|
|
91
|
+
Expect(_DataFormat
|
|
92
|
+
.stringCountEnclosures('There [are (many) of these (things)', '[', ']'))
|
|
93
|
+
.to.equal(1);
|
|
94
|
+
return fTestComplete();
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
test
|
|
98
|
+
(
|
|
99
|
+
'Test getting an enclosure value by index',
|
|
100
|
+
(fTestComplete)=>
|
|
101
|
+
{
|
|
102
|
+
let testFable = new libFable({LogStreams: false});
|
|
103
|
+
let _DataFormat = testFable.defaultServices.DataFormat;
|
|
104
|
+
Expect(_DataFormat
|
|
105
|
+
.stringGetEnclosureValueByIndex('Dogs (are) cool', 0))
|
|
106
|
+
.to.equal('are');
|
|
107
|
+
Expect(_DataFormat
|
|
108
|
+
.stringGetEnclosureValueByIndex('Dogs are cool', 0))
|
|
109
|
+
.to.equal('');
|
|
110
|
+
Expect(_DataFormat
|
|
111
|
+
.stringGetEnclosureValueByIndex('There (are (many)) of these (things)', 0))
|
|
112
|
+
.to.equal('are (many)');
|
|
113
|
+
Expect(_DataFormat
|
|
114
|
+
.stringGetEnclosureValueByIndex('There [are (many)] of these (things)', 1))
|
|
115
|
+
.to.equal('things');
|
|
116
|
+
Expect(_DataFormat
|
|
117
|
+
.stringGetEnclosureValueByIndex('There [are (many)] of these (things)', 2))
|
|
118
|
+
.to.equal('');
|
|
119
|
+
Expect(_DataFormat
|
|
120
|
+
.stringGetEnclosureValueByIndex('(This enclosure is the whole string)', 0))
|
|
121
|
+
.to.equal('This enclosure is the whole string');
|
|
122
|
+
// You can also specify the enclosure characters
|
|
123
|
+
Expect(_DataFormat
|
|
124
|
+
.stringGetEnclosureValueByIndex('There [are (many)] of these (things)', 0, '[', ']'))
|
|
125
|
+
.to.equal('are (many)');
|
|
126
|
+
Expect(_DataFormat
|
|
127
|
+
.stringGetEnclosureValueByIndex('There [are (many) of these (things)', 0, '[', ']'))
|
|
128
|
+
.to.equal('are (many) of these (things)');
|
|
129
|
+
return fTestComplete();
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
test
|
|
133
|
+
(
|
|
134
|
+
'Test removing an enclosure',
|
|
135
|
+
(fTestComplete)=>
|
|
136
|
+
{
|
|
137
|
+
let testFable = new libFable({LogStreams: false});
|
|
138
|
+
let _DataFormat = testFable.defaultServices.DataFormat;
|
|
139
|
+
Expect(_DataFormat
|
|
140
|
+
.stringRemoveEnclosureByIndex('Dogs (are) cool', 0))
|
|
141
|
+
.to.equal('Dogs cool');
|
|
142
|
+
Expect(_DataFormat
|
|
143
|
+
.stringRemoveEnclosureByIndex('Dogs are cool', 0))
|
|
144
|
+
.to.equal('Dogs are cool');
|
|
145
|
+
Expect(_DataFormat
|
|
146
|
+
.stringRemoveEnclosureByIndex('There (are (many)) of these (things)', 0))
|
|
147
|
+
.to.equal('There of these (things)');
|
|
148
|
+
Expect(_DataFormat
|
|
149
|
+
.stringRemoveEnclosureByIndex('There [are (many)] of these (things)', 1))
|
|
150
|
+
.to.equal('There [are (many)] of these ');
|
|
151
|
+
Expect(_DataFormat
|
|
152
|
+
.stringRemoveEnclosureByIndex('There [are (many)] of these (things)', 2))
|
|
153
|
+
.to.equal('There [are (many)] of these (things)');
|
|
154
|
+
// You can also specify the enclosure characters
|
|
155
|
+
Expect(_DataFormat
|
|
156
|
+
.stringRemoveEnclosureByIndex('There [are (many)] of these (things)', 0, '[', ']'))
|
|
157
|
+
.to.equal('There of these (things)');
|
|
158
|
+
Expect(_DataFormat
|
|
159
|
+
.stringRemoveEnclosureByIndex('There [are (many) of these (things)', 0, '[', ']'))
|
|
160
|
+
.to.equal('There ');
|
|
161
|
+
return fTestComplete();
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Fable simple-get RestClient
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var libFable = require('../source/Fable.js');
|
|
10
|
+
|
|
11
|
+
var Chai = require("chai");
|
|
12
|
+
var Expect = Chai.expect;
|
|
13
|
+
|
|
14
|
+
// https://en.wiktionary.org/w/api.php?action=parse&prop=wikitext&format=json&page=dog
|
|
15
|
+
|
|
16
|
+
suite
|
|
17
|
+
(
|
|
18
|
+
'Fable RestClient',
|
|
19
|
+
function()
|
|
20
|
+
{
|
|
21
|
+
setup
|
|
22
|
+
(
|
|
23
|
+
function() { }
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
suite
|
|
27
|
+
(
|
|
28
|
+
'Basic Requests',
|
|
29
|
+
function()
|
|
30
|
+
{
|
|
31
|
+
test
|
|
32
|
+
(
|
|
33
|
+
'Perform a GET request.',
|
|
34
|
+
function(fTestComplete)
|
|
35
|
+
{
|
|
36
|
+
let testFable = new libFable();
|
|
37
|
+
// Instantiate the RestClient Service Provider
|
|
38
|
+
let tmpRestClient = testFable.serviceManager.instantiateServiceProvider('RestClient', {TraceLog: true}, 'RestClient-99');
|
|
39
|
+
|
|
40
|
+
// Download the wiktionary entry for dog!
|
|
41
|
+
tmpRestClient.getJSON('https://en.wiktionary.org/w/api.php?action=parse&prop=wikitext&format=json&page=dog',
|
|
42
|
+
(pError, pResponse, pBody)=>
|
|
43
|
+
{
|
|
44
|
+
Expect(pBody).to.be.an('object');
|
|
45
|
+
Expect(pBody.hasOwnProperty('parse')).to.equal(true);
|
|
46
|
+
Expect(pBody.parse.title).to.equal('dog');
|
|
47
|
+
fTestComplete();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
@@ -182,6 +182,19 @@ suite
|
|
|
182
182
|
}
|
|
183
183
|
);
|
|
184
184
|
test
|
|
185
|
+
(
|
|
186
|
+
'isoStringToDate should parse well-formed ISO date strings',
|
|
187
|
+
function(fDone)
|
|
188
|
+
{
|
|
189
|
+
testFable = new libFable();
|
|
190
|
+
Expect(testFable.defaultServices.Utility.isoStringToDate('2022-11-04T11:34:45.000Z').getTime()).to.equal(1667561685000);
|
|
191
|
+
Expect(testFable.defaultServices.Utility.isoStringToDate('2022-11-04T11:34:46.000Z').getTime()).to.equal(1667561686000);
|
|
192
|
+
Expect(testFable.defaultServices.Utility.isoStringToDate('1986-06-11T09:34:46.012Z').getTime()).to.equal(518866486012);
|
|
193
|
+
Expect(testFable.defaultServices.Utility.isoStringToDate('1986-06-11T09:34:46.012Z+0200').getTime()).to.equal(519586486012);
|
|
194
|
+
fDone();
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
test
|
|
185
198
|
(
|
|
186
199
|
'waterfall should be passed in from async',
|
|
187
200
|
function(fDone)
|
|
File without changes
|
|
File without changes
|