spell-check-spec.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. const SpellCheckTask = require('../lib/spell-check-task');
  2. const env = require('../lib/checker-env');
  3. const { sep } = require('path');
  4. const {
  5. it,
  6. fit,
  7. ffit,
  8. beforeEach,
  9. afterEach,
  10. conditionPromise,
  11. timeoutPromise,
  12. } = require('./async-spec-helpers');
  13. describe('Spell check', function () {
  14. let workspaceElement, editor, editorElement, spellCheckModule;
  15. const textForMarker = (marker) =>
  16. editor.getTextInBufferRange(marker.getBufferRange());
  17. const getMisspellingMarkers = () =>
  18. spellCheckModule.misspellingMarkersForEditor(editor);
  19. beforeEach(async function () {
  20. jasmine.useRealClock();
  21. workspaceElement = atom.views.getView(atom.workspace);
  22. await atom.packages.activatePackage('language-text');
  23. await atom.packages.activatePackage('language-javascript');
  24. await atom.workspace.open(`${__dirname}${sep}sample.js`);
  25. const pack = await atom.packages.activatePackage('spell-check');
  26. spellCheckModule = pack.mainModule;
  27. // Disable the grammers so nothing is done until we turn it back on.
  28. atom.config.set('spell-check.grammars', []);
  29. // Set the settings to a specific setting to avoid side effects.
  30. atom.config.set('spell-check.useSystem', false);
  31. atom.config.set('spell-check.useLocales', false);
  32. atom.config.set('spell-check.locales', ['en-US']);
  33. // Attach everything and ready to test.
  34. jasmine.attachToDOM(workspaceElement);
  35. editor = atom.workspace.getActiveTextEditor();
  36. editorElement = atom.views.getView(editor);
  37. });
  38. afterEach(() => SpellCheckTask.clear());
  39. it('decorates all misspelled words', async function () {
  40. atom.config.set('spell-check.useLocales', true);
  41. editor.insertText(
  42. 'This middle of thiss\nsentencts\n\nhas issues and the "edn" \'dsoe\' too'
  43. );
  44. atom.config.set('spell-check.grammars', ['source.js']);
  45. await conditionPromise(() => getMisspellingMarkers().length === 4);
  46. const misspellingMarkers = getMisspellingMarkers();
  47. expect(textForMarker(misspellingMarkers[0])).toEqual('thiss');
  48. expect(textForMarker(misspellingMarkers[1])).toEqual('sentencts');
  49. expect(textForMarker(misspellingMarkers[2])).toEqual('edn');
  50. expect(textForMarker(misspellingMarkers[3])).toEqual('dsoe');
  51. });
  52. it('decorates misspelled words with a leading space', async function () {
  53. atom.config.set('spell-check.useLocales', true);
  54. editor.setText('\nchok bok');
  55. atom.config.set('spell-check.grammars', ['source.js']);
  56. await conditionPromise(() => getMisspellingMarkers().length === 2);
  57. const misspellingMarkers = getMisspellingMarkers();
  58. expect(textForMarker(misspellingMarkers[0])).toEqual('chok');
  59. expect(textForMarker(misspellingMarkers[1])).toEqual('bok');
  60. });
  61. it('allows certains scopes to be excluded from spell checking', async function () {
  62. editor.setText(
  63. 'speledWrong = 5;\n' +
  64. 'function speledWrong() {}\n' +
  65. 'class SpeledWrong {}'
  66. );
  67. atom.config.set('spell-check.useLocales', true);
  68. atom.config.set('spell-check.grammars', [
  69. 'source.js',
  70. 'text.plain.null-grammar',
  71. ]);
  72. atom.config.set('spell-check.excludedScopes', ['.function.entity']);
  73. {
  74. await conditionPromise(() => getMisspellingMarkers().length > 0);
  75. const markers = getMisspellingMarkers();
  76. expect(markers.map((marker) => marker.getBufferRange())).toEqual([
  77. [
  78. [0, 0],
  79. [0, 11],
  80. ],
  81. [
  82. [2, 6],
  83. [2, 17],
  84. ],
  85. ]);
  86. }
  87. {
  88. atom.config.set('spell-check.excludedScopes', ['.functio.entity']);
  89. await conditionPromise(() => getMisspellingMarkers().length === 3);
  90. const markers = getMisspellingMarkers();
  91. expect(markers.map((marker) => marker.getBufferRange())).toEqual([
  92. [
  93. [0, 0],
  94. [0, 11],
  95. ],
  96. [
  97. [1, 9],
  98. [1, 20],
  99. ],
  100. [
  101. [2, 6],
  102. [2, 17],
  103. ],
  104. ]);
  105. }
  106. {
  107. atom.config.set('spell-check.excludedScopes', ['.meta.class']);
  108. await conditionPromise(() => getMisspellingMarkers().length === 2);
  109. const markers = getMisspellingMarkers();
  110. expect(markers.map((marker) => marker.getBufferRange())).toEqual([
  111. [
  112. [0, 0],
  113. [0, 11],
  114. ],
  115. [
  116. [1, 9],
  117. [1, 20],
  118. ],
  119. ]);
  120. }
  121. {
  122. atom.grammars.assignLanguageMode(editor, null);
  123. await conditionPromise(() => getMisspellingMarkers().length === 3);
  124. const markers = getMisspellingMarkers();
  125. expect(markers.map((marker) => marker.getBufferRange())).toEqual([
  126. [
  127. [0, 0],
  128. [0, 11],
  129. ],
  130. [
  131. [1, 9],
  132. [1, 20],
  133. ],
  134. [
  135. [2, 6],
  136. [2, 17],
  137. ],
  138. ]);
  139. }
  140. });
  141. it('allow entering of known words', async function () {
  142. atom.config.set('spell-check.knownWords', [
  143. 'GitHub',
  144. '!github',
  145. 'codez',
  146. ]);
  147. atom.config.set('spell-check.useLocales', true);
  148. editor.setText('GitHub (aka github): Where codez are builz.');
  149. atom.config.set('spell-check.grammars', ['source.js']);
  150. await conditionPromise(() => getMisspellingMarkers().length === 1);
  151. const misspellingMarkers = getMisspellingMarkers();
  152. expect(textForMarker(misspellingMarkers[0])).toBe('builz');
  153. });
  154. it('hides decorations when a misspelled word is edited', async function () {
  155. editor.setText('notaword');
  156. advanceClock(editor.getBuffer().getStoppedChangingDelay());
  157. atom.config.set('spell-check.useLocales', true);
  158. atom.config.set('spell-check.grammars', ['source.js']);
  159. await conditionPromise(() => getMisspellingMarkers().length === 1);
  160. editor.moveToEndOfLine();
  161. editor.insertText('a');
  162. await conditionPromise(() => {
  163. const misspellingMarkers = getMisspellingMarkers();
  164. return (
  165. misspellingMarkers.length === 1 &&
  166. !misspellingMarkers[0].isValid()
  167. );
  168. });
  169. });
  170. describe('when spell checking for a grammar is removed', () =>
  171. it('removes all the misspellings', async function () {
  172. atom.config.set('spell-check.useLocales', true);
  173. editor.setText('notaword');
  174. atom.config.set('spell-check.grammars', ['source.js']);
  175. await conditionPromise(() => getMisspellingMarkers().length === 1);
  176. atom.config.set('spell-check.grammars', []);
  177. expect(getMisspellingMarkers().length).toBe(0);
  178. }));
  179. describe('when spell checking for a grammar is toggled off', () =>
  180. it('removes all the misspellings', async function () {
  181. atom.config.set('spell-check.useLocales', true);
  182. editor.setText('notaword');
  183. atom.config.set('spell-check.grammars', ['source.js']);
  184. await conditionPromise(() => getMisspellingMarkers().length === 1);
  185. atom.commands.dispatch(workspaceElement, 'spell-check:toggle');
  186. expect(getMisspellingMarkers().length).toBe(0);
  187. }));
  188. describe("when the editor's grammar changes to one that does not have spell check enabled", () =>
  189. it('removes all the misspellings', async function () {
  190. atom.config.set('spell-check.useLocales', true);
  191. editor.setText('notaword');
  192. atom.config.set('spell-check.grammars', ['source.js']);
  193. await conditionPromise(() => getMisspellingMarkers().length === 1);
  194. const misspellingMarkers = getMisspellingMarkers();
  195. editor.setGrammar(atom.grammars.selectGrammar('.txt'));
  196. expect(getMisspellingMarkers().length).toBe(0);
  197. }));
  198. describe("when 'spell-check:correct-misspelling' is triggered on the editor", function () {
  199. describe('when the cursor touches a misspelling that has corrections', () =>
  200. it('displays the corrections for the misspelling and replaces the misspelling when a correction is selected', async function () {
  201. atom.config.set('spell-check.useLocales', true);
  202. editor.setText('tofether');
  203. atom.config.set('spell-check.grammars', ['source.js']);
  204. let correctionsElement = null;
  205. await conditionPromise(
  206. () => getMisspellingMarkers().length === 1
  207. );
  208. expect(getMisspellingMarkers()[0].isValid()).toBe(true);
  209. atom.commands.dispatch(
  210. editorElement,
  211. 'spell-check:correct-misspelling'
  212. );
  213. correctionsElement = editorElement.querySelector(
  214. '.corrections'
  215. );
  216. expect(correctionsElement).toBeDefined();
  217. expect(
  218. correctionsElement.querySelectorAll('li').length
  219. ).toBeGreaterThan(0);
  220. expect(
  221. correctionsElement.querySelectorAll('li')[0].textContent
  222. ).toBe('together');
  223. atom.commands.dispatch(correctionsElement, 'core:confirm');
  224. expect(editor.getText()).toBe('together');
  225. expect(editor.getCursorBufferPosition()).toEqual([0, 8]);
  226. expect(getMisspellingMarkers()[0].isValid()).toBe(false);
  227. expect(editorElement.querySelector('.corrections')).toBeNull();
  228. }));
  229. describe('when the cursor touches a misspelling that has no corrections', () =>
  230. it('displays a message saying no corrections found', async function () {
  231. atom.config.set('spell-check.useLocales', true);
  232. editor.setText('zxcasdfysyadfyasdyfasdfyasdfyasdfyasydfasdf');
  233. atom.config.set('spell-check.grammars', ['source.js']);
  234. await conditionPromise(
  235. () => getMisspellingMarkers().length > 0
  236. );
  237. atom.commands.dispatch(
  238. editorElement,
  239. 'spell-check:correct-misspelling'
  240. );
  241. expect(
  242. editorElement.querySelectorAll('.corrections').length
  243. ).toBe(1);
  244. expect(
  245. editorElement.querySelectorAll('.corrections li').length
  246. ).toBe(0);
  247. expect(
  248. editorElement.querySelector('.corrections').textContent
  249. ).toMatch(/No corrections/);
  250. }));
  251. });
  252. describe('when a right mouse click is triggered on the editor', function () {
  253. describe('when the cursor touches a misspelling that has corrections', () =>
  254. it('displays the context menu items for the misspelling and replaces the misspelling when a correction is selected', async function () {
  255. atom.config.set('spell-check.useLocales', true);
  256. editor.setText('tofether');
  257. advanceClock(editor.getBuffer().getStoppedChangingDelay());
  258. atom.config.set('spell-check.grammars', ['source.js']);
  259. await conditionPromise(
  260. () => getMisspellingMarkers().length === 1
  261. );
  262. expect(getMisspellingMarkers()[0].isValid()).toBe(true);
  263. editorElement.dispatchEvent(new MouseEvent('contextmenu'));
  264. // Check that the proper context menu entries are created for the misspelling.
  265. // A misspelling will have atleast 2 context menu items for the lines separating
  266. // the corrections.
  267. expect(
  268. spellCheckModule.contextMenuEntries.length
  269. ).toBeGreaterThan(2);
  270. const commandName = 'spell-check:correct-misspelling-0';
  271. const menuItemLabel = 'together';
  272. {
  273. const editorCommands = atom.commands.findCommands({
  274. target: editorElement,
  275. });
  276. const correctionCommand = editorCommands.filter(
  277. (command) => command.name === commandName
  278. )[0];
  279. const correctionMenuItem = atom.contextMenu.itemSets.filter(
  280. (item) => item.items[0].label === menuItemLabel
  281. )[0];
  282. expect(correctionCommand).toBeDefined();
  283. expect(correctionMenuItem).toBeDefined();
  284. }
  285. atom.commands.dispatch(editorElement, commandName);
  286. // Check that the misspelling is corrected and the context menu entries are properly disposed.
  287. expect(editor.getText()).toBe('together');
  288. expect(editor.getCursorBufferPosition()).toEqual([0, 8]);
  289. expect(getMisspellingMarkers()[0].isValid()).toBe(false);
  290. expect(spellCheckModule.contextMenuEntries.length).toBe(0);
  291. {
  292. const editorCommands = atom.commands.findCommands({
  293. target: editorElement,
  294. });
  295. const correctionCommand = editorCommands.filter(
  296. (command) => command.name === commandName
  297. )[0];
  298. const correctionMenuItem = atom.contextMenu.itemSets.filter(
  299. (item) => item.items[0].label === menuItemLabel
  300. )[0];
  301. expect(correctionCommand).toBeUndefined();
  302. expect(correctionMenuItem).toBeUndefined();
  303. }
  304. }));
  305. describe('when the cursor touches a misspelling and adding known words is enabled', () =>
  306. it("displays the 'Add to Known Words' option and adds that word when the option is selected", async function () {
  307. atom.config.set('spell-check.useLocales', true);
  308. editor.setText('zxcasdfysyadfyasdyfasdfyasdfyasdfyasydfasdf');
  309. advanceClock(editor.getBuffer().getStoppedChangingDelay());
  310. atom.config.set('spell-check.grammars', ['source.js']);
  311. atom.config.set('spell-check.addKnownWords', true);
  312. expect(atom.config.get('spell-check.knownWords').length).toBe(
  313. 0
  314. );
  315. await conditionPromise(
  316. () => getMisspellingMarkers().length === 1
  317. );
  318. expect(getMisspellingMarkers()[0].isValid()).toBe(true);
  319. editorElement.dispatchEvent(new MouseEvent('contextmenu'));
  320. // Check that the 'Add to Known Words' entry is added to the context menu.
  321. // There should be 1 entry for 'Add to Known Words' and 2 entries for the line separators.
  322. expect(spellCheckModule.contextMenuEntries.length).toBe(3);
  323. const commandName = 'spell-check:correct-misspelling-0';
  324. const menuItemLabel = 'together';
  325. {
  326. const editorCommands = atom.commands.findCommands({
  327. target: editorElement,
  328. });
  329. const correctionCommand = editorCommands.filter(
  330. (command) => command.name === commandName
  331. )[0];
  332. const correctionMenuItem = atom.contextMenu.itemSets.filter(
  333. (item) => item.items[0].label === menuItemLabel
  334. )[0];
  335. expect(correctionCommand).toBeDefined;
  336. expect(correctionMenuItem).toBeDefined;
  337. }
  338. atom.commands.dispatch(editorElement, commandName);
  339. // Check that the misspelling is added as a known word, that there are no more misspelling
  340. // markers in the editor, and that the context menu entries are properly disposed.
  341. waitsFor(() => getMisspellingMarkers().length === 0);
  342. expect(atom.config.get('spell-check.knownWords').length).toBe(
  343. 1
  344. );
  345. expect(spellCheckModule.contextMenuEntries.length).toBe(0);
  346. {
  347. const editorCommands = atom.commands.findCommands({
  348. target: editorElement,
  349. });
  350. const correctionCommand = editorCommands.filter(
  351. (command) => command.name === commandName
  352. )[0];
  353. const correctionMenuItem = atom.contextMenu.itemSets.filter(
  354. (item) => item.items[0].label === menuItemLabel
  355. )[0];
  356. expect(correctionCommand).toBeUndefined();
  357. expect(correctionMenuItem).toBeUndefined();
  358. }
  359. }));
  360. });
  361. describe('when the editor is destroyed', () =>
  362. it('destroys all misspelling markers', async function () {
  363. atom.config.set('spell-check.useLocales', true);
  364. editor.setText('mispelling');
  365. atom.config.set('spell-check.grammars', ['source.js']);
  366. await conditionPromise(() => getMisspellingMarkers().length > 0);
  367. editor.destroy();
  368. expect(getMisspellingMarkers().length).toBe(0);
  369. // Check that all the views have been cleaned up.
  370. expect(spellCheckModule.updateViews().length).toBe(0);
  371. }));
  372. describe('when using checker plugins', function () {
  373. it('no opinion on input means correctly spells', async function () {
  374. spellCheckModule.consumeSpellCheckers(
  375. require.resolve('./known-1-spec-checker')
  376. );
  377. spellCheckModule.consumeSpellCheckers(
  378. require.resolve('./known-2-spec-checker')
  379. );
  380. spellCheckModule.consumeSpellCheckers(
  381. require.resolve('./known-3-spec-checker')
  382. );
  383. spellCheckModule.consumeSpellCheckers(
  384. require.resolve('./known-4-spec-checker')
  385. );
  386. spellCheckModule.consumeSpellCheckers(
  387. require.resolve('./eot-spec-checker')
  388. );
  389. editor.setText('eot');
  390. atom.config.set('spell-check.grammars', ['source.js']);
  391. await conditionPromise(() => getMisspellingMarkers().length === 1);
  392. editor.destroy();
  393. expect(getMisspellingMarkers().length).toBe(0);
  394. });
  395. it('correctly spelling k1a', async function () {
  396. spellCheckModule.consumeSpellCheckers(
  397. require.resolve('./known-1-spec-checker')
  398. );
  399. spellCheckModule.consumeSpellCheckers(
  400. require.resolve('./known-2-spec-checker')
  401. );
  402. spellCheckModule.consumeSpellCheckers(
  403. require.resolve('./known-3-spec-checker')
  404. );
  405. spellCheckModule.consumeSpellCheckers(
  406. require.resolve('./known-4-spec-checker')
  407. );
  408. spellCheckModule.consumeSpellCheckers(
  409. require.resolve('./eot-spec-checker')
  410. );
  411. editor.setText('k1a eot');
  412. atom.config.set('spell-check.grammars', ['source.js']);
  413. await conditionPromise(() => getMisspellingMarkers().length === 1);
  414. editor.destroy();
  415. expect(getMisspellingMarkers().length).toBe(0);
  416. });
  417. it('correctly mispelling k2a', async function () {
  418. spellCheckModule.consumeSpellCheckers(
  419. require.resolve('./known-1-spec-checker')
  420. );
  421. spellCheckModule.consumeSpellCheckers(
  422. require.resolve('./known-2-spec-checker')
  423. );
  424. spellCheckModule.consumeSpellCheckers(
  425. require.resolve('./known-3-spec-checker')
  426. );
  427. spellCheckModule.consumeSpellCheckers(
  428. require.resolve('./known-4-spec-checker')
  429. );
  430. spellCheckModule.consumeSpellCheckers(
  431. require.resolve('./eot-spec-checker')
  432. );
  433. editor.setText('k2a eot');
  434. atom.config.set('spell-check.grammars', ['source.js']);
  435. await conditionPromise(() => getMisspellingMarkers().length === 2);
  436. editor.destroy();
  437. expect(getMisspellingMarkers().length).toBe(0);
  438. });
  439. it('correctly mispelling k2a with text in middle', async function () {
  440. spellCheckModule.consumeSpellCheckers(
  441. require.resolve('./known-1-spec-checker')
  442. );
  443. spellCheckModule.consumeSpellCheckers(
  444. require.resolve('./known-2-spec-checker')
  445. );
  446. spellCheckModule.consumeSpellCheckers(
  447. require.resolve('./known-3-spec-checker')
  448. );
  449. spellCheckModule.consumeSpellCheckers(
  450. require.resolve('./known-4-spec-checker')
  451. );
  452. spellCheckModule.consumeSpellCheckers(
  453. require.resolve('./eot-spec-checker')
  454. );
  455. editor.setText('k2a good eot');
  456. atom.config.set('spell-check.grammars', ['source.js']);
  457. await conditionPromise(() => getMisspellingMarkers().length === 2);
  458. editor.destroy();
  459. expect(getMisspellingMarkers().length).toBe(0);
  460. });
  461. it('word is both correct and incorrect is correct', async function () {
  462. spellCheckModule.consumeSpellCheckers(
  463. require.resolve('./known-1-spec-checker')
  464. );
  465. spellCheckModule.consumeSpellCheckers(
  466. require.resolve('./known-2-spec-checker')
  467. );
  468. spellCheckModule.consumeSpellCheckers(
  469. require.resolve('./known-3-spec-checker')
  470. );
  471. spellCheckModule.consumeSpellCheckers(
  472. require.resolve('./known-4-spec-checker')
  473. );
  474. spellCheckModule.consumeSpellCheckers(
  475. require.resolve('./eot-spec-checker')
  476. );
  477. editor.setText('k0a eot');
  478. atom.config.set('spell-check.grammars', ['source.js']);
  479. await conditionPromise(() => getMisspellingMarkers().length === 1);
  480. editor.destroy();
  481. expect(getMisspellingMarkers().length).toBe(0);
  482. });
  483. it('word is correct twice is correct', async function () {
  484. spellCheckModule.consumeSpellCheckers(
  485. require.resolve('./known-1-spec-checker')
  486. );
  487. spellCheckModule.consumeSpellCheckers(
  488. require.resolve('./known-2-spec-checker')
  489. );
  490. spellCheckModule.consumeSpellCheckers(
  491. require.resolve('./known-3-spec-checker')
  492. );
  493. spellCheckModule.consumeSpellCheckers(
  494. require.resolve('./known-4-spec-checker')
  495. );
  496. spellCheckModule.consumeSpellCheckers(
  497. require.resolve('./eot-spec-checker')
  498. );
  499. editor.setText('k0b eot');
  500. atom.config.set('spell-check.grammars', ['source.js']);
  501. await conditionPromise(() => getMisspellingMarkers().length === 1);
  502. editor.destroy();
  503. expect(getMisspellingMarkers().length).toBe(0);
  504. });
  505. it('word is incorrect twice is incorrect', async function () {
  506. spellCheckModule.consumeSpellCheckers(
  507. require.resolve('./known-1-spec-checker')
  508. );
  509. spellCheckModule.consumeSpellCheckers(
  510. require.resolve('./known-2-spec-checker')
  511. );
  512. spellCheckModule.consumeSpellCheckers(
  513. require.resolve('./known-3-spec-checker')
  514. );
  515. spellCheckModule.consumeSpellCheckers(
  516. require.resolve('./known-4-spec-checker')
  517. );
  518. spellCheckModule.consumeSpellCheckers(
  519. require.resolve('./eot-spec-checker')
  520. );
  521. editor.setText('k0c eot');
  522. atom.config.set('spell-check.grammars', ['source.js']);
  523. await conditionPromise(() => getMisspellingMarkers().length === 2);
  524. editor.destroy();
  525. expect(getMisspellingMarkers().length).toBe(0);
  526. });
  527. it('treats unknown Unicode words as incorrect', async function () {
  528. spellCheckModule.consumeSpellCheckers(
  529. require.resolve('./eot-spec-checker')
  530. );
  531. editor.setText('абырг eot');
  532. atom.config.set('spell-check.grammars', ['source.js']);
  533. expect(atom.config.get('spell-check.knownWords').length).toBe(0);
  534. await conditionPromise(() => getMisspellingMarkers().length > 0);
  535. const markers = getMisspellingMarkers();
  536. expect(markers[0].getBufferRange()).toEqual({
  537. start: { row: 0, column: 6 },
  538. end: { row: 0, column: 9 },
  539. });
  540. editor.destroy();
  541. expect(getMisspellingMarkers().length).toBe(0);
  542. });
  543. it('treats known Unicode words as correct', async function () {
  544. spellCheckModule.consumeSpellCheckers(
  545. require.resolve('./known-unicode-spec-checker')
  546. );
  547. spellCheckModule.consumeSpellCheckers(
  548. require.resolve('./eot-spec-checker')
  549. );
  550. editor.setText('абырг eot');
  551. atom.config.set('spell-check.grammars', ['source.js']);
  552. expect(atom.config.get('spell-check.knownWords').length).toBe(0);
  553. await conditionPromise(() => getMisspellingMarkers().length === 1);
  554. editor.destroy();
  555. expect(getMisspellingMarkers().length).toBe(0);
  556. });
  557. });
  558. // These tests are only run on Macs because the CI for Windows doesn't have
  559. // spelling provided.
  560. if (env.isSystemSupported() && env.isDarwin()) {
  561. describe('when using system checker plugin', function () {
  562. it('marks chzz as not a valid word but cheese is', async function () {
  563. atom.config.set('spell-check.useSystem', true);
  564. editor.setText('cheese chzz');
  565. atom.config.set('spell-check.grammars', ['source.js']);
  566. await conditionPromise(() => {
  567. markers = getMisspellingMarkers();
  568. console.log(markers);
  569. return (
  570. markers.length === 1 &&
  571. markers[0].getBufferRange().start.column === 7 &&
  572. markers[0].getBufferRange().end.column === 11
  573. );
  574. });
  575. editor.destroy();
  576. expect(getMisspellingMarkers().length).toBe(0);
  577. });
  578. it('marks multiple words as wrong', async function () {
  579. atom.config.set('spell-check.useSystem', true);
  580. editor.setText('cheese chz chzz chzzz');
  581. atom.config.set('spell-check.grammars', ['source.js']);
  582. await conditionPromise(() => {
  583. markers = getMisspellingMarkers();
  584. return (
  585. markers.length === 3 &&
  586. markers[0].getBufferRange().start.column === 7 &&
  587. markers[0].getBufferRange().end.column === 10 &&
  588. markers[1].getBufferRange().start.column === 11 &&
  589. markers[1].getBufferRange().end.column === 15 &&
  590. markers[2].getBufferRange().start.column === 16 &&
  591. markers[2].getBufferRange().end.column === 21
  592. );
  593. });
  594. editor.destroy();
  595. expect(getMisspellingMarkers().length).toBe(0);
  596. });
  597. });
  598. } else {
  599. console.log(
  600. "Skipping system checker tests because they don't run on Windows CI or Linux"
  601. );
  602. }
  603. });