spell 0.1.0 → 0.8.0
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 +35 -136
- package/package.json +24 -21
- package/.gitignore +0 -4
- package/.travis.yml +0 -6
- package/spell.js +0 -338
- package/test/css/mocha.css +0 -110
- package/test/index.html +0 -34
- package/test/lib/JSONStream/.gitignore +0 -3
- package/test/lib/JSONStream/bench.js +0 -35
- package/test/lib/JSONStream/examples/all_docs.js +0 -13
- package/test/lib/JSONStream/index.js +0 -118
- package/test/lib/JSONStream/package.json +0 -13
- package/test/lib/JSONStream/readme.markdown +0 -120
- package/test/lib/JSONStream/test/fixtures/all_docs_include.json +0 -4245
- package/test/lib/JSONStream/test/fixtures/all_npm.json +0 -4030
- package/test/lib/JSONStream/test/parsejson.js +0 -25
- package/test/lib/JSONStream/test/stringify.js +0 -41
- package/test/lib/JSONStream/test/test.js +0 -35
- package/test/lib/JSONStream/test/test2.js +0 -29
- package/test/lib/JSONStream/test/two-ways.js +0 -41
- package/test/lib/jquery-1.7.1.min.js +0 -4
- package/test/lib/json2.js +0 -487
- package/test/lib/mocha-0.3.6.js +0 -2672
- package/test/lib/request/LICENSE +0 -55
- package/test/lib/request/README.md +0 -285
- package/test/lib/request/main.js +0 -618
- package/test/lib/request/mimetypes.js +0 -146
- package/test/lib/request/oauth.js +0 -34
- package/test/lib/request/package.json +0 -15
- package/test/lib/request/tests/googledoodle.png +0 -0
- package/test/lib/request/tests/run.sh +0 -6
- package/test/lib/request/tests/server.js +0 -57
- package/test/lib/request/tests/test-body.js +0 -90
- package/test/lib/request/tests/test-cookie.js +0 -29
- package/test/lib/request/tests/test-cookiejar.js +0 -90
- package/test/lib/request/tests/test-errors.js +0 -30
- package/test/lib/request/tests/test-oauth.js +0 -109
- package/test/lib/request/tests/test-pipes.js +0 -167
- package/test/lib/request/tests/test-proxy.js +0 -39
- package/test/lib/request/tests/test-timeout.js +0 -87
- package/test/lib/request/uuid.js +0 -19
- package/test/lib/request/vendor/cookie/index.js +0 -55
- package/test/lib/request/vendor/cookie/jar.js +0 -72
- package/test/perf.js +0 -44
- package/test/resources/big.js +0 -9
- package/test/resources/big.json +0 -29159
- package/test/resources/big.txt +0 -128457
- package/test/resources/big_browser.js +0 -29159
- package/test/resources/npm.js +0 -26
- package/test/resources/npm.json +0 -84701
- package/test/resources/perf1.js +0 -144
- package/test/resources/perf2.js +0 -366
- package/test/spell.js +0 -276
package/test/spell.js
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
if (!spell) { // node
|
|
2
|
-
var spell = require('../spell.js')
|
|
3
|
-
, assert = require('assert')
|
|
4
|
-
, fs = require('fs')
|
|
5
|
-
, big = JSON.parse(fs.readFileSync(__dirname + '/resources/big.json'))
|
|
6
|
-
, PERF1 = require('./resources/perf1')
|
|
7
|
-
, PERF2 = require('./resources/perf2')
|
|
8
|
-
;
|
|
9
|
-
} else {
|
|
10
|
-
var big = BIG;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function quality(name) {
|
|
14
|
-
var dict = spell()
|
|
15
|
-
, n = 0
|
|
16
|
-
, bad = 0
|
|
17
|
-
, unknown = 0
|
|
18
|
-
, tests = (name === '2') ? PERF2 : PERF1
|
|
19
|
-
, target
|
|
20
|
-
, start
|
|
21
|
-
, exported
|
|
22
|
-
;
|
|
23
|
-
|
|
24
|
-
dict.load({ corpus: big });
|
|
25
|
-
exported = dict.export();
|
|
26
|
-
|
|
27
|
-
for (target in tests) {
|
|
28
|
-
if (tests.hasOwnProperty(target)) {
|
|
29
|
-
var wrongs = tests[target];
|
|
30
|
-
wrongs.split(/\s+/).forEach(function(wrong) {
|
|
31
|
-
n++;
|
|
32
|
-
var w = dict.lucky(wrong);
|
|
33
|
-
if (w !== target) {
|
|
34
|
-
bad++;
|
|
35
|
-
if (!exported.hasOwnProperty(target)) {
|
|
36
|
-
unknown++;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return { "bad": bad, "n": n, "unknown" : unknown };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
describe('spell', function(){
|
|
47
|
-
var readme;
|
|
48
|
-
|
|
49
|
-
readme = spell();
|
|
50
|
-
readme.load("I am going to the park with Theo today." +
|
|
51
|
-
"It's going to be the bomb.");
|
|
52
|
-
|
|
53
|
-
describe('#export()', function(){
|
|
54
|
-
it('[readme] should be export the load', function() {
|
|
55
|
-
var exported = readme["export"]();
|
|
56
|
-
assert(exported.i === 1);
|
|
57
|
-
assert(exported.am === 1);
|
|
58
|
-
assert(exported.going === 2);
|
|
59
|
-
assert(exported.to === 2);
|
|
60
|
-
assert(exported.the === 2);
|
|
61
|
-
assert(exported.park === 1);
|
|
62
|
-
assert(exported.be === 1);
|
|
63
|
-
assert(exported.bomb === 1);
|
|
64
|
-
assert(exported.theo === 1);
|
|
65
|
-
assert(exported["with"] === 1);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('#load()', function(){
|
|
70
|
-
it('[readme] should be able to read json', function() {
|
|
71
|
-
var dict = spell()
|
|
72
|
-
, exported
|
|
73
|
-
;
|
|
74
|
-
dict.load(
|
|
75
|
-
{ corpus:
|
|
76
|
-
{ "I" : 1
|
|
77
|
-
, "am" : 1
|
|
78
|
-
, "going" : 1
|
|
79
|
-
, "to" : 2
|
|
80
|
-
, "the" : 1
|
|
81
|
-
, "park" : 1
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
exported = dict["export"]();
|
|
85
|
-
assert(exported.i === 1);
|
|
86
|
-
assert(exported.am === 1);
|
|
87
|
-
assert(exported.going === 1);
|
|
88
|
-
assert(exported.to === 2);
|
|
89
|
-
assert(exported.the === 1);
|
|
90
|
-
assert(exported.park === 1);
|
|
91
|
-
});
|
|
92
|
-
it('[readme] load without reseting', function() {
|
|
93
|
-
var dict = spell()
|
|
94
|
-
, exported
|
|
95
|
-
;
|
|
96
|
-
dict.load("One Two Three.");
|
|
97
|
-
dict.load({"corpus": "four", "reset": false });
|
|
98
|
-
exported = dict["export"]();
|
|
99
|
-
assert(exported.one === 1);
|
|
100
|
-
assert(exported.two === 1);
|
|
101
|
-
assert(exported.three === 1);
|
|
102
|
-
assert(exported.four === 1);
|
|
103
|
-
});
|
|
104
|
-
it('[readme] load with reseting', function() {
|
|
105
|
-
var dict = spell()
|
|
106
|
-
, exported
|
|
107
|
-
;
|
|
108
|
-
dict.load("One Two Three.");
|
|
109
|
-
dict.load({"corpus": "four", "reset": true });
|
|
110
|
-
exported = dict["export"]();
|
|
111
|
-
assert(exported.one !== 1);
|
|
112
|
-
assert(exported.two !== 1);
|
|
113
|
-
assert(exported.three !== 1);
|
|
114
|
-
assert(exported.four === 1);
|
|
115
|
-
});
|
|
116
|
-
it('[readme] load with first param string', function() {
|
|
117
|
-
var dict = spell()
|
|
118
|
-
, exported
|
|
119
|
-
;
|
|
120
|
-
dict.load("One Two Three.");
|
|
121
|
-
dict.load("four", { "reset": false });
|
|
122
|
-
exported = dict["export"]();
|
|
123
|
-
assert(exported.one === 1);
|
|
124
|
-
assert(exported.two === 1);
|
|
125
|
-
assert(exported.three === 1);
|
|
126
|
-
assert(exported.four === 1);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('#add_word()', function(){
|
|
131
|
-
it('[readme] basic usage', function() {
|
|
132
|
-
var dict = spell()
|
|
133
|
-
, exported
|
|
134
|
-
;
|
|
135
|
-
dict.load("One Two Three.");
|
|
136
|
-
dict.add_word("Four");
|
|
137
|
-
exported = dict["export"]();
|
|
138
|
-
assert(exported.one === 1);
|
|
139
|
-
assert(exported.two === 1);
|
|
140
|
-
assert(exported.three === 1);
|
|
141
|
-
assert(exported.four === 1);
|
|
142
|
-
});
|
|
143
|
-
it('[readme] setting score', function() {
|
|
144
|
-
var dict = spell()
|
|
145
|
-
, exported
|
|
146
|
-
;
|
|
147
|
-
dict.add_word("Four", {score: 500});
|
|
148
|
-
exported = dict["export"]();
|
|
149
|
-
assert(exported.four === 500);
|
|
150
|
-
});
|
|
151
|
-
it('[readme] add word with integer', function() {
|
|
152
|
-
var dict = spell()
|
|
153
|
-
, exported
|
|
154
|
-
;
|
|
155
|
-
dict.add_word("test", 500);
|
|
156
|
-
exported = dict["export"]();
|
|
157
|
-
assert(exported.test === 500);
|
|
158
|
-
});
|
|
159
|
-
it('[readme] add word with string', function() {
|
|
160
|
-
var dict = spell()
|
|
161
|
-
, exported
|
|
162
|
-
;
|
|
163
|
-
dict.add_word("test", "500");
|
|
164
|
-
exported = dict["export"]();
|
|
165
|
-
assert(exported.test === 500);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('#remove_word()', function(){
|
|
170
|
-
it('[readme] removing word', function() {
|
|
171
|
-
var dict = spell()
|
|
172
|
-
, exported
|
|
173
|
-
;
|
|
174
|
-
dict.load('the game');
|
|
175
|
-
dict.remove_word("the");
|
|
176
|
-
exported = dict["export"]();
|
|
177
|
-
assert(exported.game === 1);
|
|
178
|
-
assert(exported.the === undefined);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('#reset()', function(){
|
|
183
|
-
it('[readme] reset should clean contents of dict', function() {
|
|
184
|
-
var dict = spell()
|
|
185
|
-
, exported
|
|
186
|
-
;
|
|
187
|
-
dict.load({corpus: readme["export"]()});
|
|
188
|
-
dict.reset();
|
|
189
|
-
exported = JSON.stringify(dict["export"]());
|
|
190
|
-
assert(exported === '{}');
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe('#suggest()', function(){
|
|
195
|
-
it('[readme] `suggest` `the` for `thew`', function() {
|
|
196
|
-
var suggest = readme.suggest("thew");
|
|
197
|
-
assert(suggest[0].word === "the");
|
|
198
|
-
assert(suggest[0].score === 2);
|
|
199
|
-
assert(suggest[1].word === "theo");
|
|
200
|
-
assert(suggest[1].score === 1);
|
|
201
|
-
});
|
|
202
|
-
it('[readme] correct word that exists should return the word', function(){
|
|
203
|
-
var suggest = readme.suggest("the");
|
|
204
|
-
assert(suggest[0].word === "the");
|
|
205
|
-
assert(suggest[0].score === 2);
|
|
206
|
-
assert(suggest.length === 1);
|
|
207
|
-
});
|
|
208
|
-
it('[readme] first `suggest` should match `lucky`', function(){
|
|
209
|
-
var suggest = readme.suggest("thew")
|
|
210
|
-
, lucky = readme.lucky("the")
|
|
211
|
-
;
|
|
212
|
-
assert(suggest[0].word === readme.lucky("the"));
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe('#lucky()', function(){
|
|
217
|
-
it('[readme] with empty dict', function() {
|
|
218
|
-
var dict = spell()
|
|
219
|
-
, lucky = dict.lucky("testing")
|
|
220
|
-
;
|
|
221
|
-
assert(lucky === undefined);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
describe('#storage', function () {
|
|
226
|
-
it('[readme] should be able to store and load from storage', function(){
|
|
227
|
-
var err
|
|
228
|
-
, dict
|
|
229
|
-
, dict_clone
|
|
230
|
-
, dict_not_clone
|
|
231
|
-
, exported
|
|
232
|
-
, exported_not_clone
|
|
233
|
-
, node = (typeof exports !== 'undefined')
|
|
234
|
-
, global_var = node ? global : window
|
|
235
|
-
, storage =
|
|
236
|
-
{ "get" : function () {
|
|
237
|
-
try { return JSON.parse(global_var._test_spell); }
|
|
238
|
-
catch (err) { return {}; }
|
|
239
|
-
}
|
|
240
|
-
, "store" : function (dict,after_store) {
|
|
241
|
-
try { global_var._test_spell = JSON.stringify(dict); }
|
|
242
|
-
catch (err) { return {}; }
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
;
|
|
246
|
-
dict = spell(storage);
|
|
247
|
-
dict.load("tucano second skin", {store: true});
|
|
248
|
-
dict_clone = spell(storage);
|
|
249
|
-
dict_not_clone = spell();
|
|
250
|
-
exported = dict_clone["export"]();
|
|
251
|
-
exported_not_clone = dict_not_clone["export"]();
|
|
252
|
-
assert(exported.tucano === 1);
|
|
253
|
-
assert(exported.second === 1);
|
|
254
|
-
assert(exported.skin === 1);
|
|
255
|
-
assert(exported_not_clone.tucano !== 1);
|
|
256
|
-
assert(exported_not_clone.second !== 1);
|
|
257
|
-
assert(exported_not_clone.skin !== 1);
|
|
258
|
-
delete global_var._test_spell; // clean up
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
describe('#quality', function(){
|
|
263
|
-
it('[perf1] less than 68 bad, 15 unknown', function() {
|
|
264
|
-
var results = quality('1');
|
|
265
|
-
assert(results.bad < 69);
|
|
266
|
-
assert(results.unknown < 16);
|
|
267
|
-
assert(results.n === 270);
|
|
268
|
-
});
|
|
269
|
-
it('[perf2] less than 130 bad, 43 unknown', function() {
|
|
270
|
-
var results = quality('2');
|
|
271
|
-
assert(results.bad < 131);
|
|
272
|
-
assert(results.unknown < 44);
|
|
273
|
-
assert(results.n === 400);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
});
|