File: go-comment-test.el

package info (click to toggle)
go-mode.el 3%3A1.6.0%2Bgit20250311.0ed3c52-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: lisp: 3,292; sh: 5; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;;; go-comment-test.el

;; Copyright 2020 The go-mode Authors. All rights reserved. Use of
;; this source code is governed by a BSD-style license that can be
;; found in the LICENSE file.

(require 'ert)
(require 'go-mode)
(require 'cl-lib)

(ert-deftest go--comment-region ()
  (go--should-comment
   "
<var foo int
>"
   "
// var foo int
")

  (go--should-comment
   "
<// var foo int
>"
   "
var foo int
")

  (go--should-comment
   "var <foo> int"
   "var /* foo */ int")

  (go--should-comment
   "var </* foo */> int"
   "var foo int"))

(defun go--should-comment (got expected)
  "Run `comment-dwim' against GOT and make sure it matches EXPECTED.

<> in GOT represents point. If they aren't next to each other, then it
represents point and mark to test the region based comment-region."
  (with-temp-buffer
    (go-mode)
    (transient-mark-mode)
    (insert got)
    (goto-char (point-min))
    (let ((beg (progn (search-forward "<") (delete-char -1) (point)))
          (end (progn (search-forward ">") (delete-char -1) (point))))
      (when (/= beg end)
        (set-mark beg))
      (goto-char end)
      (call-interactively 'comment-dwim)
      (should (string= (buffer-string) expected)))))