|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +import assert from 'assert'; |
| 5 | +import getSuggestion from '../../../src/util/getSuggestion'; |
| 6 | + |
| 7 | +describe('spell check suggestion API', () => { |
| 8 | + it('should return no suggestions given empty word and no dictionary', () => { |
| 9 | + const word = ''; |
| 10 | + const expected = []; |
| 11 | + const actual = getSuggestion(word); |
| 12 | + |
| 13 | + assert.deepEqual(expected, actual); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should return no suggestions given real word and no dictionary', () => { |
| 17 | + const word = 'foo'; |
| 18 | + const expected = []; |
| 19 | + const actual = getSuggestion(word); |
| 20 | + |
| 21 | + assert.deepEqual(expected, actual); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return correct suggestion given real word and a dictionary', () => { |
| 25 | + const word = 'fo'; |
| 26 | + const dictionary = [ 'foo', 'bar', 'baz' ]; |
| 27 | + const expected = [ 'foo' ]; |
| 28 | + const actual = getSuggestion(word, dictionary); |
| 29 | + |
| 30 | + assert.deepEqual(expected, actual); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should return multiple correct suggestions given real word and a dictionary', () => { |
| 34 | + const word = 'theer'; |
| 35 | + const dictionary = [ 'there', 'their', 'foo', 'bar' ]; |
| 36 | + const expected = [ 'their', 'there' ]; |
| 37 | + const actual = getSuggestion(word, dictionary); |
| 38 | + |
| 39 | + assert.deepEqual(expected, actual); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should return one correct suggestion given real word and a dictionary and a limit of 1', () => { |
| 43 | + const word = 'theer'; |
| 44 | + const dictionary = [ 'there', 'their', 'foo', 'bar' ]; |
| 45 | + const expected = [ 'their' ]; |
| 46 | + const actual = getSuggestion(word, dictionary, 1); |
| 47 | + |
| 48 | + assert.deepEqual(expected, actual); |
| 49 | + }); |
| 50 | +}); |
0 commit comments