latex-linter.test.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. import { assert } from 'chai'
  2. import LintWorker from '../../../../../../frontend/js/features/source-editor/languages/latex/linter/latex-linter.worker.js'
  3. import { errorsToDiagnostics } from '../../../../../../frontend/js/features/source-editor/languages/latex/linter/errors-to-diagnostics'
  4. import { Diagnostic } from '@codemirror/lint'
  5. import { mergeCompatibleOverlappingDiagnostics } from '../../../../../../frontend/js/features/source-editor/languages/latex/linter/merge-overlapping-diagnostics'
  6. const { Parse } = new LintWorker()
  7. describe('LatexLinter', function () {
  8. it('should accept a simple environment match without errors', function () {
  9. const { errors } = Parse('\\begin{foo}\n' + '\\end{foo}\n')
  10. assert.equal(errors.length, 0)
  11. })
  12. it('should accept an invalid \\it* command', function () {
  13. const { errors } = Parse('\\it*hello\n' + '\\bye\n')
  14. assert.equal(errors.length, 0)
  15. })
  16. it('should accept newcomlumntype', function () {
  17. const { errors } = Parse(
  18. 'hello\n' +
  19. '\\newcolumntype{M}[1]{>{\\begin{varwidth}[t]{#1}}l<{\\end{varwidth}}}\n' +
  20. 'bye'
  21. )
  22. assert.equal(errors.length, 0)
  23. })
  24. it('should accept newenvironment', function () {
  25. const { errors } = Parse(
  26. '\\newenvironment{Algorithm}[2][tbh]%\n' +
  27. '{\\begin{myalgo}[#1]\n' +
  28. '\\centering\n' +
  29. '\\part{title}\\begin{minipage}{#2}\n' +
  30. '\\begin{algorithm}[H]}%\n' +
  31. '{\\end{algorithm}\n' +
  32. '\\end{minipage}\n' +
  33. '\\end{myalgo}}'
  34. )
  35. assert.equal(errors.length, 0)
  36. })
  37. it('should accept newenvironment II', function () {
  38. const { errors } = Parse(
  39. '\\newenvironment{claimproof}[1][\\myproofname]{\\begin{proof}[#1]\\renewcommand*{\\qedsymbol}{\\(\\diamondsuit\\)}}{\\end{proof}}'
  40. )
  41. assert.equal(errors.length, 0)
  42. })
  43. it('should accept superscript inside math mode', function () {
  44. const { errors } = Parse('this is $a^b$ test')
  45. assert.equal(errors.length, 0)
  46. })
  47. it('should accept subscript inside math mode', function () {
  48. const { errors } = Parse('this is $a_b$ test')
  49. assert.equal(errors.length, 0)
  50. })
  51. it('should return an error for superscript outside math mode', function () {
  52. const { errors } = Parse('this is a^b test')
  53. assert.equal(errors.length, 1)
  54. assert.equal(errors[0].text, '^ must be inside math mode')
  55. assert.equal(errors[0].type, 'error')
  56. })
  57. it('should return an error subscript outside math mode', function () {
  58. const { errors } = Parse('this is a_b test')
  59. assert.equal(errors.length, 1)
  60. assert.equal(errors[0].text, '_ must be inside math mode')
  61. assert.equal(errors[0].type, 'error')
  62. })
  63. it('should accept math mode inside \\hbox outside math mode', function () {
  64. const { errors } = Parse('this is \\hbox{for every $bar$}')
  65. assert.equal(errors.length, 0)
  66. })
  67. it('should accept math mode inside \\hbox inside math mode', function () {
  68. const { errors } = Parse('this is $foo = \\hbox{for every $bar$}$ test')
  69. assert.equal(errors.length, 0)
  70. })
  71. it('should accept math mode inside \\text inside math mode', function () {
  72. const { errors } = Parse('this is $foo = \\text{for every $bar$}$ test')
  73. assert.equal(errors.length, 0)
  74. })
  75. it('should accept verbatim', function () {
  76. const { errors } = Parse(
  77. 'this is text\n' +
  78. '\\begin{verbatim}\n' +
  79. 'this is verbatim\n' +
  80. '\\end{verbatim}\n' +
  81. 'this is more text\n'
  82. )
  83. assert.equal(errors.length, 0)
  84. })
  85. it('should accept verbatim with environment inside', function () {
  86. const { errors } = Parse(
  87. 'this is text\n' +
  88. '\\begin{verbatim}\n' +
  89. 'this is verbatim\n' +
  90. '\\begin{foo}\n' +
  91. 'this is verbatim too\n' +
  92. '\\end{foo}\n' +
  93. '\\end{verbatim}\n' +
  94. 'this is more text\n'
  95. )
  96. assert.equal(errors.length, 0)
  97. })
  98. it('should accept verbatim with \\begin{verbatim} inside', function () {
  99. const { errors } = Parse(
  100. 'this is text\n' +
  101. '\\begin{verbatim}\n' +
  102. 'this is verbatim\n' +
  103. '\\begin{verbatim}\n' +
  104. 'this is verbatim too\n' +
  105. '\\end{verbatim}\n' +
  106. 'this is more text\n'
  107. )
  108. assert.equal(errors.length, 0)
  109. })
  110. it('should accept equation', function () {
  111. const { errors } = Parse(
  112. 'this is text\n' +
  113. '\\begin{equation}\n' +
  114. '\\alpha^2 + b^2 = c^2\n' +
  115. '\\end{equation}\n' +
  116. 'this is more text\n'
  117. )
  118. assert.equal(errors.length, 0)
  119. })
  120. it('should accept $$', function () {
  121. const { errors } = Parse(
  122. 'this is text\n' +
  123. '$$\n' +
  124. '\\alpha^2 + b^2 = c^2\n' +
  125. '$$\n' +
  126. 'this is more text\n'
  127. )
  128. assert.equal(errors.length, 0)
  129. })
  130. it('should accept $', function () {
  131. const { errors } = Parse(
  132. 'this is text $\\alpha^2 + b^2 = c^2$' + ' this is more text\n'
  133. )
  134. assert.equal(errors.length, 0)
  135. })
  136. it('should accept \\[', function () {
  137. const { errors } = Parse(
  138. 'this is text\n' +
  139. '\\[\n' +
  140. '\\alpha^2 + b^2 = c^2\n' +
  141. '\\]\n' +
  142. 'this is more text\n'
  143. )
  144. assert.equal(errors.length, 0)
  145. })
  146. it('should accept \\(', function () {
  147. const { errors } = Parse(
  148. 'this is text \\(\\alpha^2 + b^2 = c^2\\)' + ' this is more text\n'
  149. )
  150. assert.equal(errors.length, 0)
  151. })
  152. it('should accept \\begin{foo}', function () {
  153. const { errors } = Parse(
  154. 'this is text\n' +
  155. '\\begin{foo}\n' +
  156. 'this is foo\n' +
  157. '\\end{foo}\n' +
  158. 'this is more text\n'
  159. )
  160. assert.equal(errors.length, 0)
  161. })
  162. it('should accept \\begin{foo_bar}', function () {
  163. const { errors } = Parse(
  164. 'this is text\n' +
  165. '\\begin{foo_bar}\n' +
  166. 'this is foo bar\n' +
  167. '\\end{foo_bar}\n' +
  168. 'this is more text\n'
  169. )
  170. assert.equal(errors.length, 0)
  171. })
  172. it('should accept \\begin{foo} \\begin{bar}', function () {
  173. const { errors } = Parse(
  174. 'this is text\n' +
  175. '\\begin{foo}\n' +
  176. '\\begin{bar}\n' +
  177. '\\begin{baz}\n' +
  178. 'this is foo bar baz\n' +
  179. '\\end{baz}\n' +
  180. '\\end{bar}\n' +
  181. '\\end{foo}\n' +
  182. 'this is more text\n'
  183. )
  184. assert.equal(errors.length, 0)
  185. })
  186. it('should accept \\verb|...|', function () {
  187. const { errors } = Parse('this is text \\verb|hello| and more\n')
  188. assert.equal(errors.length, 0)
  189. })
  190. it('should accept \\verb|...| with special chars', function () {
  191. const { errors } = Parse('this is text \\verb|{}()^_@$xhello| and more\n')
  192. assert.equal(errors.length, 0)
  193. })
  194. it('should accept \\url|...|', function () {
  195. const { errors } = Parse(
  196. 'this is text \\url|http://www.sharelatex.com/| and more\n'
  197. )
  198. assert.equal(errors.length, 0)
  199. })
  200. it('should accept \\url{...}', function () {
  201. const { errors } = Parse(
  202. 'this is text \\url{http://www.sharelatex.com/} and more\n'
  203. )
  204. assert.equal(errors.length, 0)
  205. })
  206. it('should accept \\url{...} with % chars', function () {
  207. const { errors } = Parse(
  208. 'this is text \\url{http://www.sharelatex.com/hello%20world} and more\n'
  209. )
  210. assert.equal(errors.length, 0)
  211. })
  212. it('should accept \\left( and \\right)', function () {
  213. const { errors } = Parse('math $\\left( x + y \\right) = y + x$ and more\n')
  214. assert.equal(errors.length, 0)
  215. })
  216. it('should accept \\left( and \\right.', function () {
  217. const { errors } = Parse('math $\\left( x + y \\right. = y + x$ and more\n')
  218. assert.equal(errors.length, 0)
  219. })
  220. it('should accept \\left. and \\right)', function () {
  221. const { errors } = Parse('math $\\left. x + y \\right) = y + x$ and more\n')
  222. assert.equal(errors.length, 0)
  223. })
  224. it('should accept complex math nesting', function () {
  225. const { errors } = Parse(
  226. 'math $\\left( {x + {y + z} + x} \\right\\} = \\left[y + x\\right.$ and more\n'
  227. )
  228. assert.equal(errors.length, 0)
  229. })
  230. it('should accept math toggling $a$$b$', function () {
  231. const { errors } = Parse('math $a$$b$ and more\n')
  232. assert.equal(errors.length, 0)
  233. })
  234. it('should accept math toggling $$display$$$inline$', function () {
  235. const { errors } = Parse('math $$display$$$inline$ and more\n')
  236. assert.equal(errors.length, 0)
  237. })
  238. it('should accept math definition commands', function () {
  239. const { errors } = Parse(
  240. '\\let\\originalleft\\left\n' +
  241. '\\let\\originalright\\right\n' +
  242. '\\renewcommand{\\left}{\\mathopen{}\\mathclose\\bgroup\\originalleft}\n' +
  243. '\\renewcommand{\\right}{\\aftergroup\\egroup\\originalright}\n'
  244. )
  245. assert.equal(errors.length, 0)
  246. })
  247. it('should accept math reflectbox commands', function () {
  248. const { errors } = Parse('$\\reflectbox{$alpha$}$\n')
  249. assert.equal(errors.length, 0)
  250. })
  251. it('should accept math scalebox commands', function () {
  252. const { errors } = Parse('$\\scalebox{2}{$alpha$}$\n')
  253. assert.equal(errors.length, 0)
  254. })
  255. it('should accept math rotatebox commands', function () {
  256. const { errors } = Parse('$\\rotatebox{60}{$alpha$}$\n')
  257. assert.equal(errors.length, 0)
  258. })
  259. it('should accept math resizebox commands', function () {
  260. const { errors } = Parse('$\\resizebox{2}{3}{$alpha$}$\n')
  261. assert.equal(errors.length, 0)
  262. })
  263. it('should accept all math box commands', function () {
  264. const { errors } = Parse(
  265. '\\[ \\left(\n' +
  266. '\\shiftright{2ex}{\\raisebox{-2ex}{\\scalebox{2}{$\\ast$}}}\n' +
  267. '\\reflectbox{$ddots$}\n' +
  268. '\\right). \\]\n'
  269. )
  270. assert.equal(errors.length, 0)
  271. })
  272. it('should accept math tag commands', function () {
  273. const { errors } = Parse('$\\tag{$alpha$}$\n')
  274. assert.equal(errors.length, 0)
  275. })
  276. it('should accept math \\def commands', function () {
  277. const { errors } = Parse(
  278. '\\def\\peb[#1]{{\\left\\lfloor #1\\right\\rfloor}}'
  279. )
  280. assert.equal(errors.length, 0)
  281. })
  282. it('should accept math \\def commands II', function () {
  283. const { errors } = Parse('\\def\\foo#1{\\gamma^#1}')
  284. assert.equal(errors.length, 0)
  285. })
  286. it('should accept DeclareMathOperator', function () {
  287. const { errors } = Parse('\\DeclareMathOperator{\\var}{\\Delta^2\\!}')
  288. assert.equal(errors.length, 0)
  289. })
  290. it('should accept DeclarePairedDelimiter', function () {
  291. const { errors } = Parse(
  292. '\\DeclarePairedDelimiter{\\spro}{\\left(}{\\right)^{\\ast}}'
  293. )
  294. assert.equal(errors.length, 0)
  295. })
  296. it('should accept nested user-defined math commands', function () {
  297. const { errors } = Parse(
  298. '$\\foo{$\\alpha \\bar{x^y}{\\cite{hello}}$}{\\gamma}{$\\beta\\baz{\\alpha}$}{\\cite{foo}}$'
  299. )
  300. assert.equal(errors.length, 0)
  301. })
  302. it('should accept nested user-defined math commands II', function () {
  303. const { errors } = Parse(
  304. '\\foo{$\\alpha \\bar{x^y}{\\cite{hello}}$}{\\gamma}{$\\beta\\baz{\\alpha}$}{\\cite{foo}}'
  305. )
  306. assert.equal(errors.length, 0)
  307. })
  308. it('should accept newenvironment with multiple parameters', function () {
  309. const { errors } = Parse(
  310. '\\newenvironment{case}[1][\\textsc{Case}]\n' +
  311. '{\\begin{trivlist}\\item[\\hskip \\labelsep {\\textsc{#1}}]}{\\end{trivlist}}'
  312. )
  313. assert.equal(errors.length, 0)
  314. })
  315. it('should accept newenvironment with no parameters', function () {
  316. const { errors } = Parse(
  317. '\\newenvironment{case}{\\begin{trivlist}\\item[\\hskip \\labelsep {\\textsc{#1}}]}{\\end{trivlist}}'
  318. )
  319. assert.equal(errors.length, 0)
  320. })
  321. it('should accept tikzfeynman', function () {
  322. const { errors } = Parse(
  323. '\\begin{equation*}\n' +
  324. '\\feynmandiagram[layered layout, medium, horizontal=a to b] {\n' +
  325. ' a [particle=\\(H\\)] -- [scalar] b [dot] -- [photon] f1 [particle=\\(W^{\\pm}\\)],\n' +
  326. ' b -- [boson, edge label=\\(W^{\\mp}\\)] c [dot],\n' +
  327. ' c -- [fermion] f2 [particle=\\(f\\)],\n' +
  328. " c -- [anti fermion] f3 [particle=\\(\\bar{f}'\\)],\n" +
  329. ' };this is a change\n' +
  330. '\\end{equation*}'
  331. )
  332. assert.equal(errors.length, 0)
  333. })
  334. it('should return errors from malformed \\end', function () {
  335. const { errors } = Parse(
  336. 'this is text\n' +
  337. '\\begin{foo}\n' +
  338. '\\begin{bar}\n' +
  339. 'this is foo bar baz\n' +
  340. '\\end{bar\n' +
  341. '\\end{foo}\n' +
  342. 'this is more text\n'
  343. )
  344. assert.equal(errors.length, 4)
  345. assert.equal(errors[0].text, 'unclosed \\begin{bar} found at \\end{foo}')
  346. assert.equal(errors[1].text, 'invalid environment command \\end{bar')
  347. assert.equal(errors[2].text, 'unclosed open group { found at \\end{foo}')
  348. assert.equal(errors[3].text, 'unexpected \\end{foo} after \\begin{bar}')
  349. })
  350. it('should accept \\newcommand*', function () {
  351. const { errors } = Parse('\\newcommand*{\\foo}{\\bar}')
  352. assert.equal(errors.length, 0)
  353. })
  354. it('should accept incomplete \\newcommand*', function () {
  355. const { errors } = Parse('\\newcommand*{\\beq' + '}')
  356. assert.equal(errors.length, 0)
  357. })
  358. // %novalidate
  359. // %begin novalidate
  360. // %end novalidate
  361. // \begin{foo}
  362. // \begin{new_theorem}
  363. // \begin{foo invalid environment command
  364. // \newcommand{\foo}{\bar}
  365. // \newcommand[1]{\foo}{\bar #1}
  366. // \renewcommand...
  367. // \def
  368. // \DeclareRobustCommand
  369. // \newcolumntype
  370. // \newenvironment
  371. // \renewenvironment
  372. // \verb|....|
  373. // \url|...|
  374. // \url{...}
  375. // \left( \right)
  376. // \left. \right.
  377. // $...$
  378. // $$....$$
  379. // $...$$...$
  380. // $a^b$ vs a^b
  381. // $$a^b$$ vs a^b
  382. // Matrix for envs for {} left/right \[ \] \( \) $ $$ begin end
  383. // begin equation
  384. // align(*)
  385. // equation(*)
  386. // ]
  387. // array(*)
  388. // eqnarray(*)
  389. // split
  390. // aligned
  391. // cases
  392. // pmatrix
  393. // gathered
  394. // matrix
  395. // alignedat
  396. // smallmatrix
  397. // subarray
  398. // vmatrix
  399. // shortintertext
  400. it('should return math mode contexts', function () {
  401. const { contexts } = Parse(
  402. '\\begin{document}\n' +
  403. '$$\n' +
  404. '\\begin{array}\n' +
  405. '\\left( \\foo{bar} \\right] & 2\n' +
  406. '\\end{array}\n' +
  407. '$$\n' +
  408. '\\end{document}'
  409. )
  410. assert.equal(contexts.length, 1)
  411. assert.equal(contexts[0].type, 'math')
  412. assert.equal(contexts[0].range.start.row, 1)
  413. assert.equal(contexts[0].range.start.column, 0)
  414. assert.equal(contexts[0].range.end.row, 5)
  415. assert.equal(contexts[0].range.end.column, 2)
  416. })
  417. it('should remove error when cursor is inside incomplete command', function () {
  418. const { errors } = Parse('\\begin{}')
  419. const diagnostics = errorsToDiagnostics(errors, 7, 9)
  420. assert.equal(errors.length, 1)
  421. assert.equal(diagnostics.length, 0)
  422. })
  423. it('should show an error when cursor is outside incomplete command', function () {
  424. const { errors } = Parse('\\begin{}')
  425. const diagnostics = errorsToDiagnostics(errors, 6, 9)
  426. assert.equal(errors.length, 1)
  427. assert.equal(diagnostics.length, 1)
  428. assert.equal(diagnostics[0].from, 0)
  429. assert.equal(diagnostics[0].to, 6)
  430. })
  431. it('should adjust an error range when the cursor is inside that range', function () {
  432. const { errors } = Parse('\\begin{}')
  433. const diagnostics = errorsToDiagnostics(errors, 4, 7)
  434. assert.equal(errors.length, 1)
  435. assert.equal(errors[0].startPos, 0)
  436. assert.equal(errors[0].endPos, 7)
  437. assert.equal(diagnostics.length, 1)
  438. assert.equal(diagnostics[0].from, 0)
  439. assert.equal(diagnostics[0].to, 4)
  440. })
  441. it('should reject an error when part of the error range is outside of the document boundaries', function () {
  442. const { errors } = Parse('\\begin{}')
  443. const diagnostics = errorsToDiagnostics(errors, 8, 6)
  444. assert.equal(errors.length, 1)
  445. assert.equal(diagnostics.length, 0)
  446. })
  447. it('should merge two overlapping identical diagnostics', function () {
  448. const diagnostics: Diagnostic[] = [
  449. {
  450. from: 0,
  451. to: 2,
  452. message: 'Message 1',
  453. severity: 'error',
  454. },
  455. {
  456. from: 1,
  457. to: 3,
  458. message: 'Message 1',
  459. severity: 'error',
  460. },
  461. ]
  462. const mergedDiagnostics = mergeCompatibleOverlappingDiagnostics(diagnostics)
  463. assert.deepEqual(mergedDiagnostics, [
  464. {
  465. from: 0,
  466. to: 3,
  467. message: 'Message 1',
  468. severity: 'error',
  469. },
  470. ])
  471. })
  472. it('should merge two touching identical diagnostics', function () {
  473. const diagnostics: Diagnostic[] = [
  474. {
  475. from: 0,
  476. to: 2,
  477. message: 'Message 1',
  478. severity: 'error',
  479. },
  480. {
  481. from: 2,
  482. to: 3,
  483. message: 'Message 1',
  484. severity: 'error',
  485. },
  486. ]
  487. const mergedDiagnostics = mergeCompatibleOverlappingDiagnostics(diagnostics)
  488. assert.deepEqual(mergedDiagnostics, [
  489. {
  490. from: 0,
  491. to: 3,
  492. message: 'Message 1',
  493. severity: 'error',
  494. },
  495. ])
  496. })
  497. it('should not merge two overlapping diagnostics with different messages', function () {
  498. const diagnostics: Diagnostic[] = [
  499. {
  500. from: 0,
  501. to: 2,
  502. message: 'Message 1',
  503. severity: 'error',
  504. },
  505. {
  506. from: 1,
  507. to: 3,
  508. message: 'Message 2',
  509. severity: 'error',
  510. },
  511. ]
  512. const mergedDiagnostics = mergeCompatibleOverlappingDiagnostics(diagnostics)
  513. assert.deepEqual(diagnostics, mergedDiagnostics)
  514. })
  515. it('should not merge two overlapping diagnostics with different severities', function () {
  516. const diagnostics: Diagnostic[] = [
  517. {
  518. from: 0,
  519. to: 2,
  520. message: 'Message 1',
  521. severity: 'error',
  522. },
  523. {
  524. from: 1,
  525. to: 3,
  526. message: 'Message 1',
  527. severity: 'warning',
  528. },
  529. ]
  530. const mergedDiagnostics = mergeCompatibleOverlappingDiagnostics(diagnostics)
  531. assert.deepEqual(diagnostics, mergedDiagnostics)
  532. })
  533. it('should merge three overlapping identical diagnostics', function () {
  534. const diagnostics: Diagnostic[] = [
  535. {
  536. from: 0,
  537. to: 2,
  538. message: 'Message 1',
  539. severity: 'error',
  540. },
  541. {
  542. from: 1,
  543. to: 4,
  544. message: 'Message 1',
  545. severity: 'error',
  546. },
  547. {
  548. from: 3,
  549. to: 5,
  550. message: 'Message 1',
  551. severity: 'error',
  552. },
  553. ]
  554. const mergedDiagnostics = mergeCompatibleOverlappingDiagnostics(diagnostics)
  555. assert.deepEqual(mergedDiagnostics, [
  556. {
  557. from: 0,
  558. to: 5,
  559. message: 'Message 1',
  560. severity: 'error',
  561. },
  562. ])
  563. })
  564. it('should merge two separate sets of overlapping identical diagnostics', function () {
  565. const diagnostics: Diagnostic[] = [
  566. {
  567. from: 0,
  568. to: 2,
  569. message: 'Message 1',
  570. severity: 'error',
  571. },
  572. {
  573. from: 2,
  574. to: 3,
  575. message: 'Message 1',
  576. severity: 'error',
  577. },
  578. {
  579. from: 2,
  580. to: 5,
  581. message: 'Message 2',
  582. severity: 'error',
  583. },
  584. {
  585. from: 4,
  586. to: 6,
  587. message: 'Message 3',
  588. severity: 'error',
  589. },
  590. {
  591. from: 5,
  592. to: 7,
  593. message: 'Message 3',
  594. severity: 'error',
  595. },
  596. ]
  597. const mergedDiagnostics = mergeCompatibleOverlappingDiagnostics(diagnostics)
  598. assert.deepEqual(mergedDiagnostics, [
  599. {
  600. from: 0,
  601. to: 3,
  602. message: 'Message 1',
  603. severity: 'error',
  604. },
  605. {
  606. from: 2,
  607. to: 5,
  608. message: 'Message 2',
  609. severity: 'error',
  610. },
  611. {
  612. from: 4,
  613. to: 7,
  614. message: 'Message 3',
  615. severity: 'error',
  616. },
  617. ])
  618. })
  619. })