go-comment-test.el (1205B)
1 ;;; go-comment-test.el 2 3 ;; Copyright 2020 The go-mode Authors. All rights reserved. Use of 4 ;; this source code is governed by a BSD-style license that can be 5 ;; found in the LICENSE file. 6 7 (require 'ert) 8 (require 'go-mode) 9 (require 'cl-lib) 10 11 (ert-deftest go--comment-region () 12 (go--should-comment 13 " 14 <var foo int 15 >" 16 " 17 // var foo int 18 ") 19 20 (go--should-comment 21 " 22 <// var foo int 23 >" 24 " 25 var foo int 26 ") 27 28 (go--should-comment 29 "var <foo> int" 30 "var /* foo */ int") 31 32 (go--should-comment 33 "var </* foo */> int" 34 "var foo int")) 35 36 (defun go--should-comment (got expected) 37 "Run `comment-dwim' against GOT and make sure it matches EXPECTED. 38 39 <> in GOT represents point. If they aren't next to each other, then it 40 represents point and mark to test the region based comment-region." 41 (with-temp-buffer 42 (go-mode) 43 (transient-mark-mode) 44 (insert got) 45 (goto-char (point-min)) 46 (let ((beg (progn (search-forward "<") (delete-char -1) (point))) 47 (end (progn (search-forward ">") (delete-char -1) (point)))) 48 (when (/= beg end) 49 (set-mark beg)) 50 (goto-char end) 51 (call-interactively 'comment-dwim) 52 (should (string= (buffer-string) expected)))))