File: go-indentation-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 (124 lines) | stat: -rw-r--r-- 1,819 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
;;; go-indentation-test.el

;; Copyright 2019 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)

(ert-deftest go--indent-line ()
  (dolist (file (directory-files (expand-file-name "test/testdata/indentation_tests/") t ".*\\.go$"))
    (with-temp-buffer
      (go-mode)
      (insert-file-contents file)
      (let ((contents-before-indent (buffer-string)) (inhibit-message t))
        (indent-region (point-min) (point-max) nil)
        (should (string= contents-before-indent (buffer-string)))))))

(ert-deftest go-dot-mod--indent-line ()
  (with-temp-buffer
    (go-dot-mod-mode)
    (insert-file-contents "test/testdata/indentation_tests/go.mod")
    (let ((contents-before-indent (buffer-string)) (inhibit-message t))
      (indent-region (point-min) (point-max) nil)
      (should (string= contents-before-indent (buffer-string))))))

(defun go--should-indent (input expected)
  "Run `indent-region' against INPUT and make sure it matches EXPECTED."
  (with-temp-buffer
    (go-mode)
    (insert input)
    (let ((inhibit-message t))
      (indent-region (point-min) (point-max))
      (should (string= (buffer-string) expected)))))

(ert-deftest go--indent-top-level ()
  (go--should-indent
   "
package foo
  var foo = 123 +
    456 +
    789
"

   "
package foo
var foo = 123 +
	456 +
	789
"
   ))

(ert-deftest go--indent-multiline-comment ()
  (go--should-indent
   "
{
	/*
a
	*/
}
"

   "
{
	/*
	   a
	*/
}
")

  (go--should-indent
   "
{
	/*   LISTEN
a
	*/
}
"

   "
{
	/*   LISTEN
	     a
	*/
}
")

  (go--should-indent
   "
{
	/* c
	c
c
	*/
}
"

   "
{
	/* c
	c
	c
	*/
}
")

  (go--should-indent
   "
{
	/* cool
	*  cat
	 *
	*/
}
"

   "
{
	/* cool
	 *  cat
	 *
	 */
}
"))