mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-09 20:58:12 +08:00
fix(spellcheck): add tests and merge in Linux changes
This commit is contained in:
parent
ddb4716706
commit
e928f85cd7
2 changed files with 55 additions and 8 deletions
|
@ -40,6 +40,34 @@ describe "NylasSpellchecker", ->
|
||||||
spyOn(@spellchecker, "getAvailableDictionaries").andReturn @fullDictList
|
spyOn(@spellchecker, "getAvailableDictionaries").andReturn @fullDictList
|
||||||
expect(@spellchecker.isLanguageAvailable("en")).toBe true
|
expect(@spellchecker.isLanguageAvailable("en")).toBe true
|
||||||
|
|
||||||
|
it "sets the correct default dictionary", ->
|
||||||
|
nodeSpellchecker = require('spellchecker')
|
||||||
|
spyOn(nodeSpellchecker, "setDictionary")
|
||||||
|
@spellchecker.setDictionary("en_US")
|
||||||
|
expect(nodeSpellchecker.setDictionary).toHaveBeenCalled()
|
||||||
|
expect(nodeSpellchecker.setDictionary.calls[0].args[0]).toBe "en_US"
|
||||||
|
dict = nodeSpellchecker.setDictionary.calls[0].args[1]
|
||||||
|
if process.platform is "darwin"
|
||||||
|
expect(dict.length).toBe 0
|
||||||
|
else if process.platform is "win32"
|
||||||
|
expect(dict.length).toBe 0
|
||||||
|
else if process.platform is "linux"
|
||||||
|
expect(dict.length).toBeGreaterThan 0
|
||||||
|
|
||||||
|
it "uses the passed-in dictionary", ->
|
||||||
|
nodeSpellchecker = require('spellchecker')
|
||||||
|
spyOn(nodeSpellchecker, "setDictionary")
|
||||||
|
@spellchecker.setDictionary("fr", "/path/to/dict")
|
||||||
|
expect(nodeSpellchecker.setDictionary).toHaveBeenCalled()
|
||||||
|
expect(nodeSpellchecker.setDictionary.calls[0].args[0]).toBe "fr"
|
||||||
|
dict = nodeSpellchecker.setDictionary.calls[0].args[1]
|
||||||
|
if process.platform is "darwin"
|
||||||
|
expect(dict).toBe "/path/to/dict"
|
||||||
|
else if process.platform is "win32"
|
||||||
|
expect(dict).toBe "/path/to/dict"
|
||||||
|
else if process.platform is "linux"
|
||||||
|
expect(dict).toBe "/path/to/dict"
|
||||||
|
|
||||||
describe "when we don't recognize the language", ->
|
describe "when we don't recognize the language", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
spyOn(@spellchecker, "getAvailableDictionaries").andReturn ["foo"]
|
spyOn(@spellchecker, "getAvailableDictionaries").andReturn ["foo"]
|
||||||
|
@ -87,12 +115,11 @@ describe "NylasSpellchecker", ->
|
||||||
|
|
||||||
it "provides options for misspelled words", ->
|
it "provides options for misspelled words", ->
|
||||||
expect(@spellchecker.getCorrectionsForMisspelling("")).toEqual []
|
expect(@spellchecker.getCorrectionsForMisspelling("")).toEqual []
|
||||||
# TODO: Determine the reason OS X and/or Windows return an empty array
|
|
||||||
# for the string. -mbilker
|
|
||||||
if process.platform is 'linux'
|
if process.platform is 'linux'
|
||||||
expect(@spellchecker.getCorrectionsForMisspelling("asdfk")).toEqual ['asked', 'acidify', 'Assad']
|
expect(@spellchecker.getCorrectionsForMisspelling("asdfk")).toEqual ['asked', 'acidify', 'Assad']
|
||||||
else
|
else if process.platofrm is "darwin"
|
||||||
expect(@spellchecker.getCorrectionsForMisspelling("asdfk")).toEqual []
|
expect(@spellchecker.getCorrectionsForMisspelling("testt")).toEqual [ 'test', 'tests', 'testy', 'testa' ]
|
||||||
|
|
||||||
it "still provides options for correctly spelled workds", ->
|
it "still provides options for correctly spelled workds", ->
|
||||||
expect(@spellchecker.getCorrectionsForMisspelling("hello").length).toBeGreaterThan 1
|
expect(@spellchecker.getCorrectionsForMisspelling("hello").length).toBeGreaterThan 1
|
||||||
|
|
|
@ -16,7 +16,7 @@ class NylasSpellchecker
|
||||||
|
|
||||||
isSpelledCorrectly: (args...) => not @isMisspelled(args...)
|
isSpelledCorrectly: (args...) => not @isMisspelled(args...)
|
||||||
|
|
||||||
setLanguage: (lang="", dict=@_getDictionaryPath()) ->
|
setLanguage: (lang="", dict="") ->
|
||||||
@languageAvailable = @isLanguageAvailable(lang)
|
@languageAvailable = @isLanguageAvailable(lang)
|
||||||
if @languageAvailable
|
if @languageAvailable
|
||||||
spellCheck = @isSpelledCorrectly
|
spellCheck = @isSpelledCorrectly
|
||||||
|
@ -28,15 +28,35 @@ class NylasSpellchecker
|
||||||
if lang.length is 0 then lang = "en-US"
|
if lang.length is 0 then lang = "en-US"
|
||||||
|
|
||||||
@_setWebframeSpellchecker(lang, spellCheck)
|
@_setWebframeSpellchecker(lang, spellCheck)
|
||||||
|
|
||||||
|
if process.platform is "linux"
|
||||||
|
dictionaryPath = @_getHunspellDictionary()
|
||||||
|
else
|
||||||
|
# On Mac we defer to NSSpellChecker
|
||||||
|
# On Windows we use the Windows Spell Check API
|
||||||
|
#
|
||||||
|
# Both of those automatically provide a set of dictionaries based on
|
||||||
|
# the language string.
|
||||||
|
#
|
||||||
|
# On Windows 10 you can see the dictionaries that are available by
|
||||||
|
# looking in: C:\Users\YourName\AppData\Roaming\Microsoft\Spelling
|
||||||
|
#
|
||||||
|
# The `dictionaryPath` parameter is ignored on Mac & Windows by
|
||||||
|
# node-spellchecker
|
||||||
|
dictionaryPath = ""
|
||||||
|
|
||||||
|
if dict.length is 0 then dict = dictionaryPath
|
||||||
|
|
||||||
spellchecker.setDictionary(lang, dict)
|
spellchecker.setDictionary(lang, dict)
|
||||||
|
|
||||||
# Separate method for testing
|
# Separate method for testing
|
||||||
_setWebframeSpellchecker: (lang, spellCheck) ->
|
_setWebframeSpellchecker: (lang, spellCheck) ->
|
||||||
require('web-frame').setSpellCheckProvider(lang, false, {spellCheck})
|
require('web-frame').setSpellCheckProvider(lang, false, {spellCheck})
|
||||||
|
|
||||||
# node-spellchecker's method for resolving the builtin hunspell dictionaries for Linux
|
# node-spellchecker's method for resolving the builtin hunspell
|
||||||
# (From https://github.com/atom/node-spellchecker/blob/master/lib/spellchecker.js#L50-L61)
|
# dictionaries for Linux (From
|
||||||
_getDictionaryPath: ->
|
# https://github.com/atom/node-spellchecker/blob/master/lib/spellchecker.js#L50-L61)
|
||||||
|
_getHunspellDictionary: ->
|
||||||
dict = path.join(require.resolve('spellchecker'), '..', '..', 'vendor', 'hunspell_dictionaries')
|
dict = path.join(require.resolve('spellchecker'), '..', '..', 'vendor', 'hunspell_dictionaries')
|
||||||
try
|
try
|
||||||
# HACK: Special case being in an asar archive
|
# HACK: Special case being in an asar archive
|
||||||
|
|
Loading…
Add table
Reference in a new issue