spell 1.0.0 → 1.0.1

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