|
1 /* |
|
2 * Copyright (c) 2009 Panagiotis Astithas |
|
3 * Permission to use, copy, modify, and distribute this software for any |
|
4 * purpose with or without fee is hereby granted, provided that the above |
|
5 * copyright notice and this permission notice appear in all copies. |
|
6 * |
|
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
|
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
|
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
14 */ |
|
15 |
|
16 'use strict'; |
|
17 // <INJECTED SOURCE:START> |
|
18 |
|
19 // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT |
|
20 // DO NOT EDIT IT DIRECTLY |
|
21 |
|
22 var exports = {}; |
|
23 |
|
24 var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testSpell.js</p>"; |
|
25 |
|
26 function test() { |
|
27 return Task.spawn(function() { |
|
28 let options = yield helpers.openTab(TEST_URI); |
|
29 yield helpers.openToolbar(options); |
|
30 gcli.addItems(mockCommands.items); |
|
31 |
|
32 yield helpers.runTests(options, exports); |
|
33 |
|
34 gcli.removeItems(mockCommands.items); |
|
35 yield helpers.closeToolbar(options); |
|
36 yield helpers.closeTab(options); |
|
37 }).then(finish, helpers.handleError); |
|
38 } |
|
39 |
|
40 // <INJECTED SOURCE:END> |
|
41 |
|
42 // var assert = require('../testharness/assert'); |
|
43 var spell = require('gcli/util/spell'); |
|
44 |
|
45 exports.testSpellerSimple = function(options) { |
|
46 var alternatives = [ |
|
47 'window', 'document', 'InstallTrigger', 'requirejs', 'require','define', |
|
48 'console', 'location', 'constructor', 'getInterface', 'external', 'sidebar' |
|
49 ]; |
|
50 |
|
51 assert.is(spell.correct('document', alternatives), 'document'); |
|
52 assert.is(spell.correct('documen', alternatives), 'document'); |
|
53 assert.is(spell.correct('ocument', alternatives), 'document'); |
|
54 assert.is(spell.correct('odcument', alternatives), 'document'); |
|
55 |
|
56 assert.is(spell.correct('=========', alternatives), undefined); |
|
57 }; |
|
58 |
|
59 exports.testRank = function(options) { |
|
60 var distances = spell.rank('fred', [ 'banana', 'fred', 'ed', 'red', 'FRED' ]); |
|
61 |
|
62 assert.is(distances.length, 5, 'rank length'); |
|
63 |
|
64 assert.is(distances[0].name, 'fred', 'fred name #0'); |
|
65 assert.is(distances[1].name, 'FRED', 'FRED name #1'); |
|
66 assert.is(distances[2].name, 'red', 'red name #2'); |
|
67 assert.is(distances[3].name, 'ed', 'ed name #3'); |
|
68 assert.is(distances[4].name, 'banana', 'banana name #4'); |
|
69 |
|
70 assert.is(distances[0].dist, 0, 'fred dist 0'); |
|
71 assert.is(distances[1].dist, 4, 'FRED dist 4'); |
|
72 assert.is(distances[2].dist, 10, 'red dist 10'); |
|
73 assert.is(distances[3].dist, 20, 'ed dist 20'); |
|
74 assert.is(distances[4].dist, 100, 'banana dist 100'); |
|
75 }; |
|
76 |
|
77 exports.testRank2 = function(options) { |
|
78 var distances = spell.rank('caps', [ 'CAPS', 'false' ]); |
|
79 assert.is(JSON.stringify(distances), |
|
80 '[{"name":"CAPS","dist":4},{"name":"false","dist":50}]', |
|
81 'spell.rank("caps", [ "CAPS", "false" ]'); |
|
82 }; |
|
83 |
|
84 exports.testDistancePrefix = function(options) { |
|
85 assert.is(spell.distancePrefix('fred', 'freddy'), 0, 'distancePrefix fred'); |
|
86 assert.is(spell.distancePrefix('FRED', 'freddy'), 4, 'distancePrefix FRED'); |
|
87 }; |