dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

go-fill-paragraph-test.el (5542B)


      1 ;;; go-fill-paragraph-test.el
      2 
      3 ;; Copyright 2019 The go-mode Authors.  All rights reserved.
      4 ;; Use of this source code is governed by a BSD-style
      5 ;; license that can be found in the LICENSE file.
      6 
      7 (require 'ert)
      8 (require 'go-mode)
      9 
     10 (defun go--should-fill (got expected)
     11   "Run `fill-paragraph' against GOT and make sure it matches EXPECTED.
     12 
     13 <> in GOT represents point. If they aren't next to each other, then it
     14 represents point and mark to test the region based fill-paragraph."
     15   (with-temp-buffer
     16     (go-mode)
     17     (transient-mark-mode)
     18     (insert got)
     19     (goto-char (point-min))
     20     (let ((beg (progn (search-forward "<") (delete-char -1) (point)))
     21           (end (progn (search-forward ">") (delete-char -1) (point))))
     22       (when (/= beg end)
     23         (set-mark beg))
     24       (goto-char end)
     25       (call-interactively 'fill-paragraph)
     26       (should (string= (buffer-string) expected)))))
     27 
     28 (ert-deftest go--fill-paragraph-single ()
     29   (go--should-fill
     30    "
     31 func main() {
     32 <>  // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     33 }"
     34 
     35    "
     36 func main() {
     37   // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
     38   // eiusmod tempor incididunt ut labore et dolore magna aliqua.
     39 }"
     40    ))
     41 
     42 (ert-deftest go--fill-paragraph-single-region ()
     43   (go--should-fill
     44    "
     45 func main() {
     46 <  // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     47 >}"
     48 
     49    "
     50 func main() {
     51   // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
     52   // eiusmod tempor incididunt ut labore et dolore magna aliqua.
     53 }"
     54    ))
     55 
     56 (ert-deftest go--fill-paragraph-block ()
     57   (go--should-fill
     58    "
     59 func main() {
     60 <>  /* Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. */
     61 }"
     62 
     63    "
     64 func main() {
     65   /* Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
     66      eiusmod tempor incididunt ut labore et dolore magna aliqua. */
     67 }"
     68    ))
     69 
     70 (ert-deftest go--fill-paragraph-block-region ()
     71   (go--should-fill
     72    "
     73 func main() {
     74 <  /* Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. */
     75 >}"
     76 
     77    "
     78 func main() {
     79   /* Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
     80      eiusmod tempor incididunt ut labore et dolore magna aliqua. */
     81 }"
     82    ))
     83 
     84 (ert-deftest go--fill-paragraph-block-empty-first ()
     85   (go--should-fill
     86    "
     87 func main() {
     88 <>  /*
     89        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     90   */
     91 }"
     92 
     93    "
     94 func main() {
     95   /*
     96        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
     97        do eiusmod tempor incididunt ut labore et dolore magna aliqua.
     98   */
     99 }"
    100    ))
    101 
    102 (ert-deftest go--fill-paragraph-block-empty-first-region ()
    103   (go--should-fill
    104    "
    105 func main() {
    106 <  /*
    107        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    108   */
    109 >}"
    110 
    111    "
    112 func main() {
    113   /*
    114        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
    115        do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    116   */
    117 }"
    118    ))
    119 
    120 
    121 (ert-deftest go--fill-paragraph-block-offset ()
    122   (go--should-fill
    123    "
    124 func main() {
    125 <>  /*
    126        Lorem ipsum dolor sit amet, consectetur adipisicing elit,
    127          sed do eiusmod tempor incididunt ut labore
    128          et dolore magna aliqua.
    129   */
    130 }"
    131 
    132    "
    133 func main() {
    134   /*
    135        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
    136          do eiusmod tempor incididunt ut labore et dolore magna
    137          aliqua.
    138   */
    139 }"
    140    ))
    141 
    142 (ert-deftest go--fill-paragraph-block-region ()
    143   (go--should-fill
    144    "
    145 func main() {
    146 <  /* Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. */
    147 >}"
    148 
    149    "
    150 func main() {
    151   /* Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
    152      eiusmod tempor incididunt ut labore et dolore magna aliqua. */
    153 }"
    154    ))
    155 
    156 (ert-deftest go--fill-paragraph-single-artful ()
    157   (go--should-fill
    158    "
    159 func main() {
    160   /////////////////////
    161 <>  // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    162   /////////////////////
    163 }"
    164 
    165    "
    166 func main() {
    167   /////////////////////
    168   // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
    169   // eiusmod tempor incididunt ut labore et dolore magna aliqua.
    170   /////////////////////
    171 }"
    172    ))
    173 
    174 (ert-deftest go--fill-paragraph-single-artful-region ()
    175   (go--should-fill
    176    "
    177 func main() {
    178 <  /////////////////////
    179   // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    180   /////////////////////
    181 >}"
    182 
    183    "
    184 func main() {
    185   /////////////////////
    186   // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
    187   // eiusmod tempor incididunt ut labore et dolore magna aliqua.
    188   /////////////////////
    189 }"
    190    ))
    191 
    192 (ert-deftest go--fill-paragraph-code-region ()
    193   (go--should-fill
    194    "
    195 func main() {
    196 <	if something() {
    197 		somethingElse()
    198 	}
    199 >}"
    200 
    201    ;; important thing is we don't get stuck in an infinite loop
    202    "
    203 func main() {
    204 	if something() { somethingElse() }
    205 }"
    206    ))
    207 
    208 
    209 (ert-deftest go--fill-paragraph-bob ()
    210   (go--should-fill
    211    "<>// Lorem
    212 // ipsum."
    213    "// Lorem ipsum."
    214    )
    215 
    216   (go--should-fill
    217    "<>/*
    218    Lorem
    219    ipsum.
    220 */"
    221    "/*
    222    Lorem ipsum.
    223 */"
    224    ))