branch: elpa/evil-nerd-commenter
commit aa34d89797692722d5e7d2db0dd07b5c1bd25a7d
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
add unit test and CI
---
.travis.yml | 30 +++++++++++++++
Makefile | 17 +++++++++
evil-nerd-commenter-operator.el | 2 -
evil-nerd-commenter-sdk.el | 4 +-
evil-nerd-commenter-tests.el | 81 +++++++++++++++++++++++++++++++++++++++++
evil-nerd-commenter.el | 3 +-
6 files changed, 130 insertions(+), 7 deletions(-)
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000000..09ff39cc7c
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,30 @@
+language: generic
+
+env:
+ global:
+ - CURL="curl -fsSkL --retry 9 --retry-delay 9"
+ matrix:
+ - EMACS_VERSION=24.4
+ - EMACS_VERSION=24.5
+ - EMACS_VERSION=25.3
+ - EMACS_VERSION=26.1
+ - EMACS_VERSION=master
+
+matrix:
+ allow_failures:
+ - env: EMACS_VERSION=master
+
+install:
+ - $CURL -O
https://github.com/npostavs/emacs-travis/releases/download/bins/emacs-bin-${EMACS_VERSION}.tar.gz
+ - tar -xaf emacs-bin-${EMACS_VERSION}.tar.gz -C /
+ - export EMACS=/tmp/emacs/bin/emacs
+
+script:
+ - $EMACS --version
+ - emacs=$EMACS make test
+
+notifications:
+ email:
+ # Default is change, but that includes a new branch's 1st success.
+ on_success: never
+ on_failure: always
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000..af3245c7d4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+SHELL = /bin/sh
+EMACS ?= emacs
+FILES = $(filter-out evil-test-helpers.el evil-tests.el evil-pkg.el,$(wildcard
evil*.el))
+PROFILER =
+
+.PHONY: test
+
+# Delete byte-compiled files etc.
+clean:
+ rm -f *~
+ rm -f \#*\#
+ rm -f *.elc
+
+# Run tests.
+test:
+ $(EMACS) -batch -Q -l evil-nerd-commenter-sdk.el -l
evil-nerd-commenter.el -l evil-nerd-commenter-tests.el
+ rm -f *.elc .depend
\ No newline at end of file
diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index 8c8d056218..3c056ef00d 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -1,7 +1,5 @@
;;; evil-nerd-commenter-operator.el --- Provides an evil operator for
evil-nerd-commenter
-;; Copyright (C) 2013-2017, Chen Bin
-
;; Author: Chen Bin <[email protected]>
;; This file is not part of GNU Emacs.
diff --git a/evil-nerd-commenter-sdk.el b/evil-nerd-commenter-sdk.el
index cc744cff1d..d8bde19bd2 100644
--- a/evil-nerd-commenter-sdk.el
+++ b/evil-nerd-commenter-sdk.el
@@ -1,8 +1,6 @@
;;; evil-nerd-commenter-sdk.el --- SDK used by other files
-;; Copyright (C) 2017 Chen Bin
-
-;; Author: Chen Bin <chenin DOT sh AT gmail DOT com>
+;; Author: Chen Bin <chenbin DOT sh AT gmail DOT com>
;;; License:
diff --git a/evil-nerd-commenter-tests.el b/evil-nerd-commenter-tests.el
new file mode 100644
index 0000000000..d83b64f6a6
--- /dev/null
+++ b/evil-nerd-commenter-tests.el
@@ -0,0 +1,81 @@
+;; evil-nerd-commenter-tests.el --- unit tests for evil-nerd-commenter -*-
coding: utf-8 -*-
+
+;; Author: Chen Bin <chenbin DOT sh AT gmail DOT com>
+
+;;; License:
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, write to the Free Software
+;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+;;; Commentary:
+
+(require 'ert)
+(require 'evil-nerd-commenter)
+(require 'js)
+
+(defun evilnc-get-lines (start end)
+ (split-string (buffer-substring-no-properties start end) "\n"))
+
+(ert-deftest evilnc-test-forward-line ()
+ (with-temp-buffer
+ (insert "hello\nworld\nbye\nworld")
+ (goto-char (point-min))
+ (evilnc--forward-line 1)
+ (should (eq (length (evilnc-get-lines (point-min) (point))) 2))
+ (goto-char (point-min))
+ (evilnc--forward-line 2)
+ (should (eq (length (evilnc-get-lines (point-min) (point))) 3))))
+
+(ert-deftest evilnc-test-comment-lines ()
+ (let* (lines)
+ (with-temp-buffer
+ (insert "hello\nworld\nbye\nworld")
+ ;; test js comment
+ (js-mode)
+ (goto-char (point-min))
+ ;; comment out current line
+ (evilnc-comment-or-uncomment-lines 1)
+ (setq lines (evilnc-get-lines (point-min) (line-end-position)))
+ (should (string= (car lines) "// hello"))
+
+ ;; un-comment current line
+ (evilnc-comment-or-uncomment-lines 1)
+ (setq lines (evilnc-get-lines (point-min) (line-end-position)))
+ (should (string= (car lines) "hello"))
+
+ ;; comment multiple lines
+ (goto-char (point-min))
+ (evilnc-comment-or-uncomment-lines 3)
+ (setq lines (evilnc-get-lines (point-min) (point-max)))
+ (should (string= (nth 0 lines) "// hello"))
+ (should (string= (nth 1 lines) "// world"))
+ (should (string= (nth 2 lines) "// bye"))
+ (should (string= (nth 3 lines) "world")))))
+
+(ert-deftest evilnc-test-copy-and-comment-lines ()
+ (let* (lines)
+ (with-temp-buffer
+ (insert "hello\nworld")
+ (js-mode)
+ (goto-char (point-min))
+ (evilnc-copy-and-comment-lines 2)
+ (setq lines (evilnc-get-lines (point-min) (point-max)))
+ (should (string= (nth 0 lines) "// hello"))
+ (should (string= (nth 1 lines) "// world"))
+ (should (string= (nth 2 lines) "hello"))
+ (should (string= (nth 3 lines) "world")))))
+
+(ert-run-tests-batch-and-exit)
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index cbe8d9afcb..647f5c6a97 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -1,8 +1,7 @@
;;; evil-nerd-commenter.el --- Comment/uncomment lines efficiently. Like Nerd
Commenter in Vim
-;; Copyright (C) 2013-2019, Chen Bin
-
;; Author: Chen Bin <[email protected]>
+
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
;; Version: 3.3.4
;; Package-Requires: ((emacs "24.4"))