michael@0: /* michael@0: * Copyright (c) 2009 Panagiotis Astithas michael@0: * Permission to use, copy, modify, and distribute this software for any michael@0: * purpose with or without fee is hereby granted, provided that the above michael@0: * copyright notice and this permission notice appear in all copies. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES michael@0: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF michael@0: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY michael@0: * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES michael@0: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION michael@0: * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN michael@0: * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. michael@0: */ michael@0: michael@0: 'use strict'; michael@0: // michael@0: michael@0: // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT michael@0: // DO NOT EDIT IT DIRECTLY michael@0: michael@0: var exports = {}; michael@0: michael@0: var TEST_URI = "data:text/html;charset=utf-8,

gcli-testSpell.js

"; michael@0: michael@0: function test() { michael@0: return Task.spawn(function() { michael@0: let options = yield helpers.openTab(TEST_URI); michael@0: yield helpers.openToolbar(options); michael@0: gcli.addItems(mockCommands.items); michael@0: michael@0: yield helpers.runTests(options, exports); michael@0: michael@0: gcli.removeItems(mockCommands.items); michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: }).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: // michael@0: michael@0: // var assert = require('../testharness/assert'); michael@0: var spell = require('gcli/util/spell'); michael@0: michael@0: exports.testSpellerSimple = function(options) { michael@0: var alternatives = [ michael@0: 'window', 'document', 'InstallTrigger', 'requirejs', 'require','define', michael@0: 'console', 'location', 'constructor', 'getInterface', 'external', 'sidebar' michael@0: ]; michael@0: michael@0: assert.is(spell.correct('document', alternatives), 'document'); michael@0: assert.is(spell.correct('documen', alternatives), 'document'); michael@0: assert.is(spell.correct('ocument', alternatives), 'document'); michael@0: assert.is(spell.correct('odcument', alternatives), 'document'); michael@0: michael@0: assert.is(spell.correct('=========', alternatives), undefined); michael@0: }; michael@0: michael@0: exports.testRank = function(options) { michael@0: var distances = spell.rank('fred', [ 'banana', 'fred', 'ed', 'red', 'FRED' ]); michael@0: michael@0: assert.is(distances.length, 5, 'rank length'); michael@0: michael@0: assert.is(distances[0].name, 'fred', 'fred name #0'); michael@0: assert.is(distances[1].name, 'FRED', 'FRED name #1'); michael@0: assert.is(distances[2].name, 'red', 'red name #2'); michael@0: assert.is(distances[3].name, 'ed', 'ed name #3'); michael@0: assert.is(distances[4].name, 'banana', 'banana name #4'); michael@0: michael@0: assert.is(distances[0].dist, 0, 'fred dist 0'); michael@0: assert.is(distances[1].dist, 4, 'FRED dist 4'); michael@0: assert.is(distances[2].dist, 10, 'red dist 10'); michael@0: assert.is(distances[3].dist, 20, 'ed dist 20'); michael@0: assert.is(distances[4].dist, 100, 'banana dist 100'); michael@0: }; michael@0: michael@0: exports.testRank2 = function(options) { michael@0: var distances = spell.rank('caps', [ 'CAPS', 'false' ]); michael@0: assert.is(JSON.stringify(distances), michael@0: '[{"name":"CAPS","dist":4},{"name":"false","dist":50}]', michael@0: 'spell.rank("caps", [ "CAPS", "false" ]'); michael@0: }; michael@0: michael@0: exports.testDistancePrefix = function(options) { michael@0: assert.is(spell.distancePrefix('fred', 'freddy'), 0, 'distancePrefix fred'); michael@0: assert.is(spell.distancePrefix('FRED', 'freddy'), 4, 'distancePrefix FRED'); michael@0: };