go-indentation-test.el (1809B)
1 ;;; go-indentation-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 (ert-deftest go--indent-line () 11 (dolist (file (directory-files (expand-file-name "testdata/indentation_tests/") t ".*\\.go$")) 12 (with-temp-buffer 13 (go-mode) 14 (insert-file-contents file) 15 (let ((contents-before-indent (buffer-string)) (inhibit-message t)) 16 (indent-region (point-min) (point-max) nil) 17 (should (string= contents-before-indent (buffer-string))))))) 18 19 (ert-deftest go-dot-mod--indent-line () 20 (with-temp-buffer 21 (go-dot-mod-mode) 22 (insert-file-contents "testdata/indentation_tests/go.mod") 23 (let ((contents-before-indent (buffer-string)) (inhibit-message t)) 24 (indent-region (point-min) (point-max) nil) 25 (should (string= contents-before-indent (buffer-string)))))) 26 27 (defun go--should-indent (input expected) 28 "Run `indent-region' against INPUT and make sure it matches EXPECTED." 29 (with-temp-buffer 30 (go-mode) 31 (insert input) 32 (let ((inhibit-message t)) 33 (indent-region (point-min) (point-max)) 34 (should (string= (buffer-string) expected))))) 35 36 (ert-deftest go--indent-top-level () 37 (go--should-indent 38 " 39 package foo 40 var foo = 123 + 41 456 + 42 789 43 " 44 45 " 46 package foo 47 var foo = 123 + 48 456 + 49 789 50 " 51 )) 52 53 (ert-deftest go--indent-multiline-comment () 54 (go--should-indent 55 " 56 { 57 /* 58 a 59 */ 60 } 61 " 62 63 " 64 { 65 /* 66 a 67 */ 68 } 69 ") 70 71 (go--should-indent 72 " 73 { 74 /* LISTEN 75 a 76 */ 77 } 78 " 79 80 " 81 { 82 /* LISTEN 83 a 84 */ 85 } 86 ") 87 88 (go--should-indent 89 " 90 { 91 /* c 92 c 93 c 94 */ 95 } 96 " 97 98 " 99 { 100 /* c 101 c 102 c 103 */ 104 } 105 ") 106 107 (go--should-indent 108 " 109 { 110 /* cool 111 * cat 112 * 113 */ 114 } 115 " 116 117 " 118 { 119 /* cool 120 * cat 121 * 122 */ 123 } 124 "))