autoflow-spec.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. describe("Autoflow package", () => {
  2. let [autoflow, editor, editorElement] = [];
  3. const tabLength = 4;
  4. describe("autoflow:reflow-selection", () => {
  5. beforeEach(() => {
  6. let activationPromise = null;
  7. waitsForPromise(() => atom.workspace.open());
  8. runs(() => {
  9. editor = atom.workspace.getActiveTextEditor();
  10. editorElement = atom.views.getView(editor);
  11. atom.config.set('editor.preferredLineLength', 30);
  12. atom.config.set('editor.tabLength', tabLength);
  13. activationPromise = atom.packages.activatePackage('autoflow');
  14. atom.commands.dispatch(editorElement, 'autoflow:reflow-selection');
  15. });
  16. waitsForPromise(() => activationPromise);
  17. });
  18. it("uses the preferred line length based on the editor's scope", () => {
  19. atom.config.set('editor.preferredLineLength', 4, {scopeSelector: '.text.plain.null-grammar'});
  20. editor.setText("foo bar");
  21. editor.selectAll();
  22. atom.commands.dispatch(editorElement, 'autoflow:reflow-selection');
  23. expect(editor.getText()).toBe(`\
  24. foo
  25. bar\
  26. `
  27. );
  28. });
  29. it("rearranges line breaks in the current selection to ensure lines are shorter than config.editor.preferredLineLength honoring tabLength", () => {
  30. editor.setText("\t\tThis is the first paragraph and it is longer than the preferred line length so it should be reflowed.\n\n\t\tThis is a short paragraph.\n\n\t\tAnother long paragraph, it should also be reflowed with the use of this single command.");
  31. editor.selectAll();
  32. atom.commands.dispatch(editorElement, 'autoflow:reflow-selection');
  33. const exedOut = editor.getText().replace(/\t/g, Array(tabLength+1).join('X'));
  34. expect(exedOut).toBe("XXXXXXXXThis is the first\nXXXXXXXXparagraph and it is\nXXXXXXXXlonger than the\nXXXXXXXXpreferred line length\nXXXXXXXXso it should be\nXXXXXXXXreflowed.\n\nXXXXXXXXThis is a short\nXXXXXXXXparagraph.\n\nXXXXXXXXAnother long\nXXXXXXXXparagraph, it should\nXXXXXXXXalso be reflowed with\nXXXXXXXXthe use of this single\nXXXXXXXXcommand.");
  35. });
  36. it("rearranges line breaks in the current selection to ensure lines are shorter than config.editor.preferredLineLength", () => {
  37. editor.setText(`\
  38. This is the first paragraph and it is longer than the preferred line length so it should be reflowed.
  39. This is a short paragraph.
  40. Another long paragraph, it should also be reflowed with the use of this single command.\
  41. `
  42. );
  43. editor.selectAll();
  44. atom.commands.dispatch(editorElement, 'autoflow:reflow-selection');
  45. expect(editor.getText()).toBe(`\
  46. This is the first paragraph
  47. and it is longer than the
  48. preferred line length so it
  49. should be reflowed.
  50. This is a short paragraph.
  51. Another long paragraph, it
  52. should also be reflowed with
  53. the use of this single
  54. command.\
  55. `
  56. );
  57. });
  58. it("is not confused when the selection boundary is between paragraphs", () => {
  59. editor.setText(`\
  60. v--- SELECTION STARTS AT THE BEGINNING OF THE NEXT LINE (pos 1,0)
  61. The preceding newline should not be considered part of this paragraph.
  62. The newline at the end of this paragraph should be preserved and not
  63. converted into a space.
  64. ^--- SELECTION ENDS AT THE BEGINNING OF THE PREVIOUS LINE (pos 6,0)\
  65. `
  66. );
  67. editor.setCursorBufferPosition([1, 0]);
  68. editor.selectToBufferPosition([6, 0]);
  69. atom.commands.dispatch(editorElement, 'autoflow:reflow-selection');
  70. expect(editor.getText()).toBe(`\
  71. v--- SELECTION STARTS AT THE BEGINNING OF THE NEXT LINE (pos 1,0)
  72. The preceding newline should
  73. not be considered part of this
  74. paragraph.
  75. The newline at the end of this
  76. paragraph should be preserved
  77. and not converted into a
  78. space.
  79. ^--- SELECTION ENDS AT THE BEGINNING OF THE PREVIOUS LINE (pos 6,0)\
  80. `
  81. );
  82. });
  83. it("reflows the current paragraph if nothing is selected", () => {
  84. editor.setText(`\
  85. This is a preceding paragraph, which shouldn't be modified by a reflow of the following paragraph.
  86. The quick brown fox jumps over the lazy
  87. dog. The preceding sentence contains every letter
  88. in the entire English alphabet, which has absolutely no relevance
  89. to this test.
  90. This is a following paragraph, which shouldn't be modified by a reflow of the preciding paragraph.
  91. \
  92. `
  93. );
  94. editor.setCursorBufferPosition([3, 5]);
  95. atom.commands.dispatch(editorElement, 'autoflow:reflow-selection');
  96. expect(editor.getText()).toBe(`\
  97. This is a preceding paragraph, which shouldn't be modified by a reflow of the following paragraph.
  98. The quick brown fox jumps over
  99. the lazy dog. The preceding
  100. sentence contains every letter
  101. in the entire English
  102. alphabet, which has absolutely
  103. no relevance to this test.
  104. This is a following paragraph, which shouldn't be modified by a reflow of the preciding paragraph.
  105. \
  106. `
  107. );
  108. });
  109. it("allows for single words that exceed the preferred wrap column length", () => {
  110. editor.setText("this-is-a-super-long-word-that-shouldn't-break-autoflow and these are some smaller words");
  111. editor.selectAll();
  112. atom.commands.dispatch(editorElement, 'autoflow:reflow-selection');
  113. expect(editor.getText()).toBe(`\
  114. this-is-a-super-long-word-that-shouldn't-break-autoflow
  115. and these are some smaller
  116. words\
  117. `
  118. );
  119. });
  120. });
  121. describe("reflowing text", () => {
  122. beforeEach(() => autoflow = require("../lib/autoflow"));
  123. it('respects current paragraphs', () => {
  124. const text = `\
  125. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh id magna ullamcorper sagittis. Maecenas
  126. et enim eu orci tincidunt adipiscing
  127. aliquam ligula.
  128. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  129. Phasellus gravida
  130. nibh id magna ullamcorper
  131. tincidunt adipiscing lacinia a dui. Etiam quis erat dolor.
  132. rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum.\
  133. `;
  134. const res = `\
  135. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh
  136. id magna ullamcorper sagittis. Maecenas et enim eu orci tincidunt adipiscing
  137. aliquam ligula.
  138. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh
  139. id magna ullamcorper tincidunt adipiscing lacinia a dui. Etiam quis erat dolor.
  140. rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum.\
  141. `;
  142. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  143. });
  144. it('respects indentation', () => {
  145. const text = `\
  146. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh id magna ullamcorper sagittis. Maecenas
  147. et enim eu orci tincidunt adipiscing
  148. aliquam ligula.
  149. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  150. Phasellus gravida
  151. nibh id magna ullamcorper
  152. tincidunt adipiscing lacinia a dui. Etiam quis erat dolor.
  153. rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum\
  154. `;
  155. const res = `\
  156. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh
  157. id magna ullamcorper sagittis. Maecenas et enim eu orci tincidunt adipiscing
  158. aliquam ligula.
  159. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida
  160. nibh id magna ullamcorper tincidunt adipiscing lacinia a dui. Etiam quis
  161. erat dolor. rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis
  162. fermentum\
  163. `;
  164. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  165. });
  166. it('respects prefixed text (comments!)', () => {
  167. const text = `\
  168. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh id magna ullamcorper sagittis. Maecenas
  169. et enim eu orci tincidunt adipiscing
  170. aliquam ligula.
  171. # Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  172. # Phasellus gravida
  173. # nibh id magna ullamcorper
  174. # tincidunt adipiscing lacinia a dui. Etiam quis erat dolor.
  175. # rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum\
  176. `;
  177. const res = `\
  178. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh
  179. id magna ullamcorper sagittis. Maecenas et enim eu orci tincidunt adipiscing
  180. aliquam ligula.
  181. # Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida
  182. # nibh id magna ullamcorper tincidunt adipiscing lacinia a dui. Etiam quis
  183. # erat dolor. rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis
  184. # fermentum\
  185. `;
  186. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  187. });
  188. it('respects multiple prefixes (js/c comments)', () => {
  189. const text = `\
  190. // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida
  191. et enim eu orci tincidunt adipiscing
  192. aliquam ligula.\
  193. `;
  194. const res = `\
  195. // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida et
  196. // enim eu orci tincidunt adipiscing aliquam ligula.\
  197. `;
  198. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  199. });
  200. it('properly handles * prefix', () => {
  201. const text = `\
  202. * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida
  203. et enim eu orci tincidunt adipiscing
  204. aliquam ligula.
  205. * soidjfiojsoidj foi\
  206. `;
  207. const res = `\
  208. * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida et
  209. * enim eu orci tincidunt adipiscing aliquam ligula.
  210. * soidjfiojsoidj foi\
  211. `;
  212. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  213. });
  214. it("does not throw invalid regular expression errors (regression)", () => {
  215. const text = `\
  216. *** Lorem ipsum dolor sit amet\
  217. `;
  218. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(text);
  219. });
  220. it('handles different initial indentation', () => {
  221. const text = `\
  222. Magna ea magna fugiat nisi minim in id duis. Culpa sit sint consequat quis elit magna pariatur incididunt
  223. proident laborum deserunt est aliqua reprehenderit. Occaecat et ex non do Lorem irure adipisicing mollit excepteur
  224. eu ullamco consectetur. Ex ex Lorem duis labore quis ad exercitation elit dolor non adipisicing. Pariatur commodo ullamco
  225. culpa dolor sunt enim. Ullamco dolore do ea nulla ut commodo minim consequat cillum ad velit quis.\
  226. `;
  227. const res = `\
  228. Magna ea magna fugiat nisi minim in id duis. Culpa sit sint consequat quis elit
  229. magna pariatur incididunt proident laborum deserunt est aliqua reprehenderit.
  230. Occaecat et ex non do Lorem irure adipisicing mollit excepteur eu ullamco
  231. consectetur. Ex ex Lorem duis labore quis ad exercitation elit dolor non
  232. adipisicing. Pariatur commodo ullamco culpa dolor sunt enim. Ullamco dolore do
  233. ea nulla ut commodo minim consequat cillum ad velit quis.\
  234. `;
  235. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  236. });
  237. it('properly handles CRLF', () => {
  238. const text = "This is the first line and it is longer than the preferred line length so it should be reflowed.\r\nThis is a short line which should\r\nbe reflowed with the following line.\rAnother long line, it should also be reflowed with everything above it when it is all reflowed.";
  239. const res =
  240. `\
  241. This is the first line and it is longer than the preferred line length so it
  242. should be reflowed. This is a short line which should be reflowed with the
  243. following line. Another long line, it should also be reflowed with everything
  244. above it when it is all reflowed.\
  245. `;
  246. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  247. });
  248. it('handles cyrillic text', () => {
  249. const text = `\
  250. В начале июля, в чрезвычайно жаркое время, под вечер, один молодой человек вышел из своей каморки, которую нанимал от жильцов в С-м переулке, на улицу и медленно, как бы в нерешимости, отправился к К-ну мосту.\
  251. `;
  252. const res = `\
  253. В начале июля, в чрезвычайно жаркое время, под вечер, один молодой человек вышел
  254. из своей каморки, которую нанимал от жильцов в С-м переулке, на улицу и
  255. медленно, как бы в нерешимости, отправился к К-ну мосту.\
  256. `;
  257. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  258. });
  259. it('handles `yo` character properly', () => {
  260. // Because there're known problems with this character in major regex engines
  261. const text = 'Ё Ё Ё';
  262. const res = `\
  263. Ё
  264. Ё
  265. Ё\
  266. `;
  267. expect(autoflow.reflow(text, {wrapColumn: 2})).toEqual(res);
  268. });
  269. it('properly reflows // comments ', () => {
  270. const text =
  271. `\
  272. // Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  273. `;
  274. const res =
  275. `\
  276. // Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard
  277. // sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  278. // fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest
  279. // quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro
  280. // actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia
  281. // sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher
  282. // direct trade, tacos pickled fanny pack literally meh pinterest slow-carb.
  283. // Meditation microdosing distillery 8-bit humblebrag migas.\
  284. `;
  285. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  286. });
  287. it('properly reflows /* comments ', () => {
  288. const text =
  289. `\
  290. /* Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas. */\
  291. `;
  292. const res =
  293. `\
  294. /* Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard
  295. sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  296. fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest
  297. quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro
  298. actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia
  299. sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher
  300. direct trade, tacos pickled fanny pack literally meh pinterest slow-carb.
  301. Meditation microdosing distillery 8-bit humblebrag migas. */\
  302. `;
  303. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  304. });
  305. it('properly reflows pound comments ', () => {
  306. const text =
  307. `\
  308. # Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  309. `;
  310. const res =
  311. `\
  312. # Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha
  313. # banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  314. # fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa
  315. # leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually
  316. # aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial
  317. # letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade,
  318. # tacos pickled fanny pack literally meh pinterest slow-carb. Meditation
  319. # microdosing distillery 8-bit humblebrag migas.\
  320. `;
  321. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  322. });
  323. it('properly reflows - list items ', () => {
  324. const text =
  325. `\
  326. - Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  327. `;
  328. const res =
  329. `\
  330. - Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha
  331. banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  332. fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa
  333. leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually
  334. aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial
  335. letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade,
  336. tacos pickled fanny pack literally meh pinterest slow-carb. Meditation
  337. microdosing distillery 8-bit humblebrag migas.\
  338. `;
  339. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  340. });
  341. it('properly reflows % comments ', () => {
  342. const text =
  343. `\
  344. % Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  345. `;
  346. const res =
  347. `\
  348. % Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha
  349. % banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  350. % fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa
  351. % leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually
  352. % aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial
  353. % letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade,
  354. % tacos pickled fanny pack literally meh pinterest slow-carb. Meditation
  355. % microdosing distillery 8-bit humblebrag migas.\
  356. `;
  357. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  358. });
  359. it("properly reflows roxygen comments ", () => {
  360. const text =
  361. `\
  362. #' Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  363. `;
  364. const res =
  365. `\
  366. #' Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard
  367. #' sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  368. #' fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest
  369. #' quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro
  370. #' actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia
  371. #' sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher
  372. #' direct trade, tacos pickled fanny pack literally meh pinterest slow-carb.
  373. #' Meditation microdosing distillery 8-bit humblebrag migas.\
  374. `;
  375. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  376. });
  377. it("properly reflows -- comments ", () => {
  378. const text =
  379. `\
  380. -- Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  381. `;
  382. const res =
  383. `\
  384. -- Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard
  385. -- sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  386. -- fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest
  387. -- quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro
  388. -- actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia
  389. -- sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher
  390. -- direct trade, tacos pickled fanny pack literally meh pinterest slow-carb.
  391. -- Meditation microdosing distillery 8-bit humblebrag migas.\
  392. `;
  393. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  394. });
  395. it("properly reflows ||| comments ", () => {
  396. const text =
  397. `\
  398. ||| Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  399. `;
  400. const res =
  401. `\
  402. ||| Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard
  403. ||| sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  404. ||| fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest
  405. ||| quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro
  406. ||| actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia
  407. ||| sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher
  408. ||| direct trade, tacos pickled fanny pack literally meh pinterest slow-carb.
  409. ||| Meditation microdosing distillery 8-bit humblebrag migas.\
  410. `;
  411. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  412. });
  413. it('properly reflows ;; comments ', () => {
  414. const text =
  415. `\
  416. ;; Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  417. `;
  418. const res =
  419. `\
  420. ;; Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard
  421. ;; sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  422. ;; fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest
  423. ;; quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro
  424. ;; actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia
  425. ;; sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher
  426. ;; direct trade, tacos pickled fanny pack literally meh pinterest slow-carb.
  427. ;; Meditation microdosing distillery 8-bit humblebrag migas.\
  428. `;
  429. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  430. });
  431. it('does not treat lines starting with a single semicolon as ;; comments', () => {
  432. const text =
  433. `\
  434. ;! Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  435. `;
  436. const res =
  437. `\
  438. ;! Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard
  439. sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  440. fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa
  441. leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually
  442. aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial
  443. letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade,
  444. tacos pickled fanny pack literally meh pinterest slow-carb. Meditation
  445. microdosing distillery 8-bit humblebrag migas.\
  446. `;
  447. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  448. });
  449. it('properly reflows > ascii email inclusions ', () => {
  450. const text =
  451. `\
  452. > Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha banh mi, cold-pressed retro whatever ethical man braid asymmetrical fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade, tacos pickled fanny pack literally meh pinterest slow-carb. Meditation microdosing distillery 8-bit humblebrag migas.\
  453. `;
  454. const res =
  455. `\
  456. > Beard pinterest actually brunch brooklyn jean shorts YOLO. Knausgaard sriracha
  457. > banh mi, cold-pressed retro whatever ethical man braid asymmetrical
  458. > fingerstache narwhal. Intelligentsia wolf photo booth, tumblr pinterest quinoa
  459. > leggings four loko poutine. DIY tattooed drinking vinegar, wolf retro actually
  460. > aesthetic austin keffiyeh marfa beard. Marfa trust fund salvia sartorial
  461. > letterpress, keffiyeh plaid butcher. Swag try-hard dreamcatcher direct trade,
  462. > tacos pickled fanny pack literally meh pinterest slow-carb. Meditation
  463. > microdosing distillery 8-bit humblebrag migas.\
  464. `;
  465. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  466. });
  467. it("doesn't allow special characters to surpass wrapColumn", () => {
  468. const test =
  469. `\
  470. Imagine that I'm writing some LaTeX code. I start a comment, but change my mind. %
  471. Now I'm just kind of trucking along, doing some math and stuff. For instance, $3 + 4 = 7$. But maybe I'm getting really crazy and I use subtraction. It's kind of an obscure technique, but often it goes a bit like this: let $x = 2 + 2$, so $x - 1 = 3$ (quick maths).
  472. That's OK I guess, but now look at this cool thing called set theory: $\\{n + 42 : n \\in \\mathbb{N}\\}$. Wow. Neat. But we all know why we're really here. If you peer deep down into your heart, and you stare into the depths of yourself: is $P = NP$? Beware, though; many have tried and failed to answer this question. It is by no means for the faint of heart.\
  473. `;
  474. const res =
  475. `\
  476. Imagine that I'm writing some LaTeX code. I start a comment, but change my mind.
  477. %
  478. Now I'm just kind of trucking along, doing some math and stuff. For instance, $3
  479. + 4 = 7$. But maybe I'm getting really crazy and I use subtraction. It's kind of
  480. an obscure technique, but often it goes a bit like this: let $x = 2 + 2$, so $x
  481. - 1 = 3$ (quick maths).
  482. That's OK I guess, but now look at this cool thing called set theory: $\\{n + 42
  483. : n \\in \\mathbb{N}\\}$. Wow. Neat. But we all know why we're really here. If you
  484. peer deep down into your heart, and you stare into the depths of yourself: is $P
  485. = NP$? Beware, though; many have tried and failed to answer this question. It is
  486. by no means for the faint of heart.\
  487. `;
  488. expect(autoflow.reflow(test, {wrapColumn: 80})).toEqual(res);
  489. });
  490. describe('LaTeX', () => {
  491. it('properly reflows text around LaTeX tags', () => {
  492. const text =
  493. `\
  494. \\begin{verbatim}
  495. Lorem ipsum dolor sit amet, nisl odio amet, et tempor netus neque at at blandit, vel vestibulum libero dolor, semper lobortis ligula praesent. Eget condimentum integer, porta sagittis nam, fusce vitae a vitae augue. Nec semper quis sed ut, est porttitor praesent. Nisl velit quam dolore velit quam, elementum neque pellentesque pulvinar et vestibulum.
  496. \\end{verbatim}\
  497. `;
  498. const res =
  499. `\
  500. \\begin{verbatim}
  501. Lorem ipsum dolor sit amet, nisl odio amet, et tempor netus neque at at
  502. blandit, vel vestibulum libero dolor, semper lobortis ligula praesent. Eget
  503. condimentum integer, porta sagittis nam, fusce vitae a vitae augue. Nec
  504. semper quis sed ut, est porttitor praesent. Nisl velit quam dolore velit
  505. quam, elementum neque pellentesque pulvinar et vestibulum.
  506. \\end{verbatim}\
  507. `;
  508. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  509. });
  510. it('properly reflows text inside LaTeX tags', () => {
  511. const text =
  512. `\
  513. \\item{
  514. Lorem ipsum dolor sit amet, nisl odio amet, et tempor netus neque at at blandit, vel vestibulum libero dolor, semper lobortis ligula praesent. Eget condimentum integer, porta sagittis nam, fusce vitae a vitae augue. Nec semper quis sed ut, est porttitor praesent. Nisl velit quam dolore velit quam, elementum neque pellentesque pulvinar et vestibulum.
  515. }\
  516. `;
  517. const res =
  518. `\
  519. \\item{
  520. Lorem ipsum dolor sit amet, nisl odio amet, et tempor netus neque at at
  521. blandit, vel vestibulum libero dolor, semper lobortis ligula praesent. Eget
  522. condimentum integer, porta sagittis nam, fusce vitae a vitae augue. Nec
  523. semper quis sed ut, est porttitor praesent. Nisl velit quam dolore velit
  524. quam, elementum neque pellentesque pulvinar et vestibulum.
  525. }\
  526. `;
  527. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  528. });
  529. it('properly reflows text inside nested LaTeX tags', () => {
  530. const text =
  531. `\
  532. \\begin{enumerate}[label=(\\alph*)]
  533. \\item{
  534. Lorem ipsum dolor sit amet, nisl odio amet, et tempor netus neque at at blandit, vel vestibulum libero dolor, semper lobortis ligula praesent. Eget condimentum integer, porta sagittis nam, fusce vitae a vitae augue. Nec semper quis sed ut, est porttitor praesent. Nisl velit quam dolore velit quam, elementum neque pellentesque pulvinar et vestibulum.
  535. }
  536. \\end{enumerate}\
  537. `;
  538. const res =
  539. `\
  540. \\begin{enumerate}[label=(\\alph*)]
  541. \\item{
  542. Lorem ipsum dolor sit amet, nisl odio amet, et tempor netus neque at at
  543. blandit, vel vestibulum libero dolor, semper lobortis ligula praesent.
  544. Eget condimentum integer, porta sagittis nam, fusce vitae a vitae augue.
  545. Nec semper quis sed ut, est porttitor praesent. Nisl velit quam dolore
  546. velit quam, elementum neque pellentesque pulvinar et vestibulum.
  547. }
  548. \\end{enumerate}\
  549. `;
  550. expect(autoflow.reflow(text, {wrapColumn: 80})).toEqual(res);
  551. });
  552. it('does not attempt to reflow a selection that contains only LaTeX tags and nothing else', () => {
  553. const text =
  554. `\
  555. \\begin{enumerate}
  556. \\end{enumerate}\
  557. `;
  558. expect(autoflow.reflow(text, {wrapColumn: 5})).toEqual(text);
  559. });
  560. });
  561. });
  562. });