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