spell 0.3.0 → 0.8.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.
- package/README.md +38 -145
- package/package.json +24 -21
- package/.npmignore +0 -4
- package/.travis.yml +0 -6
- package/LICENSE +0 -14
- package/spell.js +0 -347
- package/test/css/mocha.css +0 -110
- package/test/index.html +0 -34
- package/test/lib/JSONStream/.npmignore +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 -295
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
var server = require('./server')
|
|
2
|
-
, events = require('events')
|
|
3
|
-
, stream = require('stream')
|
|
4
|
-
, assert = require('assert')
|
|
5
|
-
, fs = require('fs')
|
|
6
|
-
, request = require('../main.js')
|
|
7
|
-
, path = require('path')
|
|
8
|
-
, util = require('util')
|
|
9
|
-
;
|
|
10
|
-
|
|
11
|
-
var s = server.createServer(3453);
|
|
12
|
-
|
|
13
|
-
function ValidationStream(str) {
|
|
14
|
-
this.str = str
|
|
15
|
-
this.buf = ''
|
|
16
|
-
this.on('data', function (data) {
|
|
17
|
-
this.buf += data
|
|
18
|
-
})
|
|
19
|
-
this.on('end', function () {
|
|
20
|
-
assert.equal(this.str, this.buf)
|
|
21
|
-
})
|
|
22
|
-
this.writable = true
|
|
23
|
-
}
|
|
24
|
-
util.inherits(ValidationStream, stream.Stream)
|
|
25
|
-
ValidationStream.prototype.write = function (chunk) {
|
|
26
|
-
this.emit('data', chunk)
|
|
27
|
-
}
|
|
28
|
-
ValidationStream.prototype.end = function (chunk) {
|
|
29
|
-
if (chunk) emit('data', chunk)
|
|
30
|
-
this.emit('end')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
s.listen(s.port, function () {
|
|
34
|
-
counter = 0;
|
|
35
|
-
|
|
36
|
-
var check = function () {
|
|
37
|
-
counter = counter - 1
|
|
38
|
-
if (counter === 0) {
|
|
39
|
-
console.log('All tests passed.')
|
|
40
|
-
setTimeout(function () {
|
|
41
|
-
process.exit();
|
|
42
|
-
}, 500)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Test pipeing to a request object
|
|
47
|
-
s.once('/push', server.createPostValidator("mydata"));
|
|
48
|
-
|
|
49
|
-
var mydata = new stream.Stream();
|
|
50
|
-
mydata.readable = true
|
|
51
|
-
|
|
52
|
-
counter++
|
|
53
|
-
var r1 = request.put({url:'http://localhost:3453/push'}, function () {
|
|
54
|
-
check();
|
|
55
|
-
})
|
|
56
|
-
mydata.pipe(r1)
|
|
57
|
-
|
|
58
|
-
mydata.emit('data', 'mydata');
|
|
59
|
-
mydata.emit('end');
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// Test pipeing from a request object.
|
|
63
|
-
s.once('/pull', server.createGetResponse("mypulldata"));
|
|
64
|
-
|
|
65
|
-
var mypulldata = new stream.Stream();
|
|
66
|
-
mypulldata.writable = true
|
|
67
|
-
|
|
68
|
-
counter++
|
|
69
|
-
request({url:'http://localhost:3453/pull'}).pipe(mypulldata)
|
|
70
|
-
|
|
71
|
-
var d = '';
|
|
72
|
-
|
|
73
|
-
mypulldata.write = function (chunk) {
|
|
74
|
-
d += chunk;
|
|
75
|
-
}
|
|
76
|
-
mypulldata.end = function () {
|
|
77
|
-
assert.equal(d, 'mypulldata');
|
|
78
|
-
check();
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
s.on('/cat', function (req, resp) {
|
|
83
|
-
if (req.method === "GET") {
|
|
84
|
-
resp.writeHead(200, {'content-type':'text/plain-test', 'content-length':4});
|
|
85
|
-
resp.end('asdf')
|
|
86
|
-
} else if (req.method === "PUT") {
|
|
87
|
-
assert.equal(req.headers['content-type'], 'text/plain-test');
|
|
88
|
-
assert.equal(req.headers['content-length'], 4)
|
|
89
|
-
var validate = '';
|
|
90
|
-
|
|
91
|
-
req.on('data', function (chunk) {validate += chunk})
|
|
92
|
-
req.on('end', function () {
|
|
93
|
-
resp.writeHead(201);
|
|
94
|
-
resp.end();
|
|
95
|
-
assert.equal(validate, 'asdf');
|
|
96
|
-
check();
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
s.on('/pushjs', function (req, resp) {
|
|
101
|
-
if (req.method === "PUT") {
|
|
102
|
-
assert.equal(req.headers['content-type'], 'text/javascript');
|
|
103
|
-
check();
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
s.on('/catresp', function (req, resp) {
|
|
107
|
-
request.get('http://localhost:3453/cat').pipe(resp)
|
|
108
|
-
})
|
|
109
|
-
s.on('/doodle', function (req, resp) {
|
|
110
|
-
if (req.headers['x-oneline-proxy']) {
|
|
111
|
-
resp.setHeader('x-oneline-proxy', 'yup')
|
|
112
|
-
}
|
|
113
|
-
resp.writeHead('200', {'content-type':'image/png'})
|
|
114
|
-
fs.createReadStream(path.join(__dirname, 'googledoodle.png')).pipe(resp)
|
|
115
|
-
})
|
|
116
|
-
s.on('/onelineproxy', function (req, resp) {
|
|
117
|
-
var x = request('http://localhost:3453/doodle')
|
|
118
|
-
req.pipe(x)
|
|
119
|
-
x.pipe(resp)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
counter++
|
|
123
|
-
fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs'))
|
|
124
|
-
|
|
125
|
-
counter++
|
|
126
|
-
request.get('http://localhost:3453/cat').pipe(request.put('http://localhost:3453/cat'))
|
|
127
|
-
|
|
128
|
-
counter++
|
|
129
|
-
request.get('http://localhost:3453/catresp', function (e, resp, body) {
|
|
130
|
-
assert.equal(resp.headers['content-type'], 'text/plain-test');
|
|
131
|
-
assert.equal(resp.headers['content-length'], 4)
|
|
132
|
-
check();
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.png'))
|
|
136
|
-
|
|
137
|
-
counter++
|
|
138
|
-
request.get('http://localhost:3453/doodle').pipe(doodleWrite)
|
|
139
|
-
|
|
140
|
-
doodleWrite.on('close', function () {
|
|
141
|
-
assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.png')), fs.readFileSync(path.join(__dirname, 'test.png')))
|
|
142
|
-
check()
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
process.on('exit', function () {
|
|
146
|
-
fs.unlinkSync(path.join(__dirname, 'test.png'))
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
counter++
|
|
150
|
-
request.get({uri:'http://localhost:3453/onelineproxy', headers:{'x-oneline-proxy':'nope'}}, function (err, resp, body) {
|
|
151
|
-
assert.equal(resp.headers['x-oneline-proxy'], 'yup')
|
|
152
|
-
check()
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
s.on('/afterresponse', function (req, resp) {
|
|
156
|
-
resp.write('d')
|
|
157
|
-
resp.end()
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
counter++
|
|
161
|
-
var afterresp = request.post('http://localhost:3453/afterresponse').on('response', function () {
|
|
162
|
-
var v = new ValidationStream('d')
|
|
163
|
-
afterresp.pipe(v)
|
|
164
|
-
v.on('end', check)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
var server = require('./server')
|
|
2
|
-
, events = require('events')
|
|
3
|
-
, stream = require('stream')
|
|
4
|
-
, assert = require('assert')
|
|
5
|
-
, fs = require('fs')
|
|
6
|
-
, request = require('../main.js')
|
|
7
|
-
, path = require('path')
|
|
8
|
-
, util = require('util')
|
|
9
|
-
;
|
|
10
|
-
|
|
11
|
-
var port = 6768
|
|
12
|
-
, called = false
|
|
13
|
-
, proxiedHost = 'google.com'
|
|
14
|
-
;
|
|
15
|
-
|
|
16
|
-
var s = server.createServer(port)
|
|
17
|
-
s.listen(port, function () {
|
|
18
|
-
s.on('http://google.com/', function (req, res) {
|
|
19
|
-
called = true
|
|
20
|
-
assert.equal(req.headers.host, proxiedHost)
|
|
21
|
-
res.writeHeader(200)
|
|
22
|
-
res.end()
|
|
23
|
-
})
|
|
24
|
-
request ({
|
|
25
|
-
url: 'http://'+proxiedHost,
|
|
26
|
-
proxy: 'http://localhost:'+port
|
|
27
|
-
/*
|
|
28
|
-
//should behave as if these arguments where passed:
|
|
29
|
-
url: 'http://localhost:'+port,
|
|
30
|
-
headers: {host: proxiedHost}
|
|
31
|
-
//*/
|
|
32
|
-
}, function (err, res, body) {
|
|
33
|
-
s.close()
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
process.on('exit', function () {
|
|
38
|
-
assert.ok(called, 'the request must be made to the proxy server')
|
|
39
|
-
})
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
var server = require('./server')
|
|
2
|
-
, events = require('events')
|
|
3
|
-
, stream = require('stream')
|
|
4
|
-
, assert = require('assert')
|
|
5
|
-
, request = require('../main.js')
|
|
6
|
-
;
|
|
7
|
-
|
|
8
|
-
var s = server.createServer();
|
|
9
|
-
var expectedBody = "waited";
|
|
10
|
-
var remainingTests = 5;
|
|
11
|
-
|
|
12
|
-
s.listen(s.port, function () {
|
|
13
|
-
// Request that waits for 200ms
|
|
14
|
-
s.on('/timeout', function (req, resp) {
|
|
15
|
-
setTimeout(function(){
|
|
16
|
-
resp.writeHead(200, {'content-type':'text/plain'})
|
|
17
|
-
resp.write(expectedBody)
|
|
18
|
-
resp.end()
|
|
19
|
-
}, 200);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Scenario that should timeout
|
|
23
|
-
var shouldTimeout = {
|
|
24
|
-
url: s.url + "/timeout",
|
|
25
|
-
timeout:100
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
request(shouldTimeout, function (err, resp, body) {
|
|
30
|
-
assert.equal(err.code, "ETIMEDOUT");
|
|
31
|
-
checkDone();
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Scenario that shouldn't timeout
|
|
36
|
-
var shouldntTimeout = {
|
|
37
|
-
url: s.url + "/timeout",
|
|
38
|
-
timeout:300
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
request(shouldntTimeout, function (err, resp, body) {
|
|
42
|
-
assert.equal(err, null);
|
|
43
|
-
assert.equal(expectedBody, body)
|
|
44
|
-
checkDone();
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// Scenario with no timeout set, so shouldn't timeout
|
|
48
|
-
var noTimeout = {
|
|
49
|
-
url: s.url + "/timeout"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
request(noTimeout, function (err, resp, body) {
|
|
53
|
-
assert.equal(err);
|
|
54
|
-
assert.equal(expectedBody, body)
|
|
55
|
-
checkDone();
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// Scenario with a negative timeout value, should be treated a zero or the minimum delay
|
|
59
|
-
var negativeTimeout = {
|
|
60
|
-
url: s.url + "/timeout",
|
|
61
|
-
timeout:-1000
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
request(negativeTimeout, function (err, resp, body) {
|
|
65
|
-
assert.equal(err.code, "ETIMEDOUT");
|
|
66
|
-
checkDone();
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
// Scenario with a float timeout value, should be rounded by setTimeout anyway
|
|
70
|
-
var floatTimeout = {
|
|
71
|
-
url: s.url + "/timeout",
|
|
72
|
-
timeout: 100.76
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
request(floatTimeout, function (err, resp, body) {
|
|
76
|
-
assert.equal(err.code, "ETIMEDOUT");
|
|
77
|
-
checkDone();
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
function checkDone() {
|
|
81
|
-
if(--remainingTests == 0) {
|
|
82
|
-
s.close();
|
|
83
|
-
console.log("All tests passed.");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
|
package/test/lib/request/uuid.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module.exports = function () {
|
|
2
|
-
var s = [], itoh = '0123456789ABCDEF';
|
|
3
|
-
|
|
4
|
-
// Make array of random hex digits. The UUID only has 32 digits in it, but we
|
|
5
|
-
// allocate an extra items to make room for the '-'s we'll be inserting.
|
|
6
|
-
for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);
|
|
7
|
-
|
|
8
|
-
// Conform to RFC-4122, section 4.4
|
|
9
|
-
s[14] = 4; // Set 4 high bits of time_high field to version
|
|
10
|
-
s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
|
|
11
|
-
|
|
12
|
-
// Convert to hex chars
|
|
13
|
-
for (var i = 0; i <36; i++) s[i] = itoh[s[i]];
|
|
14
|
-
|
|
15
|
-
// Insert '-'s
|
|
16
|
-
s[8] = s[13] = s[18] = s[23] = '-';
|
|
17
|
-
|
|
18
|
-
return s.join('');
|
|
19
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Tobi - Cookie
|
|
3
|
-
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Module dependencies.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
var url = require('url');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Initialize a new `Cookie` with the given cookie `str` and `req`.
|
|
15
|
-
*
|
|
16
|
-
* @param {String} str
|
|
17
|
-
* @param {IncomingRequest} req
|
|
18
|
-
* @api private
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
var Cookie = exports = module.exports = function Cookie(str, req) {
|
|
22
|
-
this.str = str;
|
|
23
|
-
|
|
24
|
-
// First key is the name
|
|
25
|
-
this.name = str.substr(0, str.indexOf('='));
|
|
26
|
-
|
|
27
|
-
// Map the key/val pairs
|
|
28
|
-
str.split(/ *; */).reduce(function(obj, pair){
|
|
29
|
-
pair = pair.split(/ *= */);
|
|
30
|
-
obj[pair[0].toLowerCase()] = pair[1] || true;
|
|
31
|
-
return obj;
|
|
32
|
-
}, this);
|
|
33
|
-
|
|
34
|
-
// Assign value
|
|
35
|
-
this.value = this[this.name];
|
|
36
|
-
|
|
37
|
-
// Expires
|
|
38
|
-
this.expires = this.expires
|
|
39
|
-
? new Date(this.expires)
|
|
40
|
-
: Infinity;
|
|
41
|
-
|
|
42
|
-
// Default or trim path
|
|
43
|
-
this.path = this.path || '/';
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Return the original cookie string.
|
|
48
|
-
*
|
|
49
|
-
* @return {String}
|
|
50
|
-
* @api public
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
Cookie.prototype.toString = function(){
|
|
54
|
-
return this.str;
|
|
55
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Tobi - CookieJar
|
|
3
|
-
* Copyright(c) 2010 LearnBoost <dev@learnboost.com>
|
|
4
|
-
* MIT Licensed
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Module dependencies.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
var url = require('url');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Initialize a new `CookieJar`.
|
|
15
|
-
*
|
|
16
|
-
* @api private
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
var CookieJar = exports = module.exports = function CookieJar() {
|
|
20
|
-
this.cookies = [];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Add the given `cookie` to the jar.
|
|
25
|
-
*
|
|
26
|
-
* @param {Cookie} cookie
|
|
27
|
-
* @api private
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
CookieJar.prototype.add = function(cookie){
|
|
31
|
-
this.cookies = this.cookies.filter(function(c){
|
|
32
|
-
// Avoid duplication (same path, same name)
|
|
33
|
-
return !(c.name == cookie.name && c.path == cookie.path);
|
|
34
|
-
});
|
|
35
|
-
this.cookies.push(cookie);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get cookies for the given `req`.
|
|
40
|
-
*
|
|
41
|
-
* @param {IncomingRequest} req
|
|
42
|
-
* @return {Array}
|
|
43
|
-
* @api private
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
CookieJar.prototype.get = function(req){
|
|
47
|
-
var path = url.parse(req.url).pathname
|
|
48
|
-
, now = new Date
|
|
49
|
-
, specificity = {};
|
|
50
|
-
return this.cookies.filter(function(cookie){
|
|
51
|
-
if (0 == path.indexOf(cookie.path) && now < cookie.expires
|
|
52
|
-
&& cookie.path.length > (specificity[cookie.name] || 0))
|
|
53
|
-
return specificity[cookie.name] = cookie.path.length;
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Return Cookie string for the given `req`.
|
|
59
|
-
*
|
|
60
|
-
* @param {IncomingRequest} req
|
|
61
|
-
* @return {String}
|
|
62
|
-
* @api private
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
CookieJar.prototype.cookieString = function(req){
|
|
66
|
-
var cookies = this.get(req);
|
|
67
|
-
if (cookies.length) {
|
|
68
|
-
return cookies.map(function(cookie){
|
|
69
|
-
return cookie.name + '=' + cookie.value;
|
|
70
|
-
}).join('; ');
|
|
71
|
-
}
|
|
72
|
-
};
|
package/test/perf.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var spell = require('../spell.js')
|
|
3
|
-
, fs = require('fs')
|
|
4
|
-
, dict = spell()
|
|
5
|
-
, set1 = require('./resources/perf1')
|
|
6
|
-
, set2 = require('./resources/perf2')
|
|
7
|
-
, n = 0
|
|
8
|
-
, bad = 0
|
|
9
|
-
, unknown = 0
|
|
10
|
-
, start
|
|
11
|
-
, tests = process.argv[2] === '2' ? set2 : set1
|
|
12
|
-
, exported
|
|
13
|
-
;
|
|
14
|
-
|
|
15
|
-
dict.load(
|
|
16
|
-
{corpus: JSON.parse(fs.readFileSync(__dirname + '/resources/big.json')) });
|
|
17
|
-
exported = dict.export();
|
|
18
|
-
start = new Date();
|
|
19
|
-
|
|
20
|
-
for (target in tests) {
|
|
21
|
-
if (tests.hasOwnProperty(target)) {
|
|
22
|
-
var wrongs = tests[target];
|
|
23
|
-
wrongs.split(/\s+/).forEach(function(wrong) {
|
|
24
|
-
n++;
|
|
25
|
-
var w = dict.lucky(wrong);
|
|
26
|
-
if (w !== target) {
|
|
27
|
-
bad++;
|
|
28
|
-
if (!exported.hasOwnProperty(target)) {
|
|
29
|
-
unknown++;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
console.log(
|
|
37
|
-
{ "bad" : bad
|
|
38
|
-
, "n" : n
|
|
39
|
-
, "bias" : 0
|
|
40
|
-
, "pct" : ((100-100*bad/n)).toFixed(0)
|
|
41
|
-
, "unknown" : unknown
|
|
42
|
-
, "secs" : ((new Date()-start)/1000).toFixed(0)
|
|
43
|
-
}
|
|
44
|
-
);
|
package/test/resources/big.js
DELETED