From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#17547: [PATCH] Add basic test suits for tildify package. Date: Tue, 27 May 2014 21:02:36 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1401239005 16938 80.91.229.3 (28 May 2014 01:03:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 May 2014 01:03:25 +0000 (UTC) Cc: Milan Zamazal , 17547-done@debbugs.gnu.org To: Michal Nazarewicz Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 28 03:03:18 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WpSGz-0005pk-SQ for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 May 2014 03:03:18 +0200 Original-Received: from localhost ([::1]:38998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpSGz-0004G0-Df for geb-bug-gnu-emacs@m.gmane.org; Tue, 27 May 2014 21:03:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpSGq-0004Dt-Nx for bug-gnu-emacs@gnu.org; Tue, 27 May 2014 21:03:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WpSGk-0001H6-O3 for bug-gnu-emacs@gnu.org; Tue, 27 May 2014 21:03:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34965) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpSGk-0001H0-L5 for bug-gnu-emacs@gnu.org; Tue, 27 May 2014 21:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WpSGk-0006TN-C0 for bug-gnu-emacs@gnu.org; Tue, 27 May 2014 21:03:02 -0400 Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 May 2014 01:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 17547 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 17547@debbugs.gnu.org, monnier@iro.umontreal.ca, mina86@mina86.com Original-Received: via spool by 17547-done@debbugs.gnu.org id=D17547.140123896724852 (code D ref 17547); Wed, 28 May 2014 01:03:01 +0000 Original-Received: (at 17547-done) by debbugs.gnu.org; 28 May 2014 01:02:47 +0000 Original-Received: from localhost ([127.0.0.1]:33840 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WpSGU-0006Sm-IB for submit@debbugs.gnu.org; Tue, 27 May 2014 21:02:47 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:64405) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WpSGR-0006SV-8T for 17547-done@debbugs.gnu.org; Tue, 27 May 2014 21:02:44 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArYGAIDvNVNLd/fU/2dsb2JhbABZgwY7gw/APYEXF3SCJQEBAQECAVYjBQsLDiYSFA0LDSQTCYdcAwkIyl0Nhy8XjF6BOhEBUAeEOASOVIYPBYF5jlgDg12BaoNMIYEsBwIX X-IPAS-Result: ArYGAIDvNVNLd/fU/2dsb2JhbABZgwY7gw/APYEXF3SCJQEBAQECAVYjBQsLDiYSFA0LDSQTCYdcAwkIyl0Nhy8XjF6BOhEBUAeEOASOVIYPBYF5jlgDg12BaoNMIYEsBwIX X-IronPort-AV: E=Sophos;i="4.97,753,1389762000"; d="scan'208";a="64502096" Original-Received: from 75-119-247-212.dsl.teksavvy.com (HELO pastel.home) ([75.119.247.212]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 27 May 2014 21:02:37 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id EDFFC60094; Tue, 27 May 2014 21:02:36 -0400 (EDT) In-Reply-To: (Michal Nazarewicz's message of "Wed, 21 May 2014 17:37:50 -1000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:89593 Archived-At: [ Please try not to send the same email to both emacs-devel and bug-gnu-emacs. ] Thanks, installed. Stefan >>>>> "Michal" == Michal Nazarewicz writes: > --- > lisp/ChangeLog | 5 ++ > lisp/textmodes/tildify.el | 22 +++++---- > test/ChangeLog | 4 ++ > test/automated/tildify-tests.el | 106 ++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 128 insertions(+), 9 deletions(-) > create mode 100644 test/automated/tildify-tests.el > diff --git a/lisp/ChangeLog b/lisp/ChangeLog > index 09796f7..c2b1612 100644 > --- a/lisp/ChangeLog > +++ b/lisp/ChangeLog > @@ -1,3 +1,8 @@ > +2014-05-21 Michal Nazarewicz > + > + * textmodes/tildify.el (tildify-buffer, tildify-region): Add > + dont-ask option. > + > 2014-05-19 Leo Liu > * emacs-lisp/cl-lib.el (cl-endp): Conform to CL's semantics. > diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el > index 9732e7f..339f900 100644 > --- a/lisp/textmodes/tildify.el > +++ b/lisp/textmodes/tildify.el > @@ -3,7 +3,7 @@ > ;; Copyright (C) 1997-2014 Free Software Foundation, Inc. > ;; Author: Milan Zamazal > -;; Version: 4.5 > +;; Version: 4.5.1 > ;; Keywords: text, TeX, SGML, wp > ;; This file is part of GNU Emacs. > @@ -172,20 +172,22 @@ END-REGEX defines end of the corresponding text part and can be either: > ;;; *** Interactive functions *** > ;;;###autoload > -(defun tildify-region (beg end) > +(defun tildify-region (beg end &optional dont-ask) > "Add hard spaces in the region between BEG and END. > See variables `tildify-pattern-alist', `tildify-string-alist', and > `tildify-ignored-environments-alist' for information about configuration > parameters. > -This function performs no refilling of the changed text." > - (interactive "*r") > +This function performs no refilling of the changed text. > +If DONT-ASK is set, or called interactively with prefix argument, user > +won't be prompted for confirmation of each substitution." > + (interactive "*rP") > (setq tildify-count 0) > (let (a > z > (marker-end (copy-marker end)) > end-env > finish > - (ask t) > + (ask (not dont-ask)) > (case-fold-search nil) > (regexp (tildify-build-regexp)) ; beginnings of environments > aux) > @@ -226,14 +228,16 @@ This function performs no refilling of the changed text." > (message "%d spaces replaced." tildify-count)) > ;;;###autoload > -(defun tildify-buffer () > +(defun tildify-buffer (&optional dont-ask) > "Add hard spaces in the current buffer. > See variables `tildify-pattern-alist', `tildify-string-alist', and > `tildify-ignored-environments-alist' for information about configuration > parameters. > -This function performs no refilling of the changed text." > - (interactive "*") > - (tildify-region (point-min) (point-max))) > +This function performs no refilling of the changed text. > +If DONT-ASK is set, or called interactively with prefix argument, user > +won't be prompted for confirmation of each substitution." > + (interactive "*P") > + (tildify-region (point-min) (point-max) dont-ask)) > ;;; *** Auxiliary functions *** > diff --git a/test/ChangeLog b/test/ChangeLog > index 3fed975..17468c2 100644 > --- a/test/ChangeLog > +++ b/test/ChangeLog > @@ -1,3 +1,7 @@ > +2014-05-21 Michal Nazarewicz > + > + * automated/tildify-tests.el: New file. > + > 2014-05-15 Dmitry Antipov > * automated/fns-tests.el: New file. > diff --git a/test/automated/tildify-tests.el b/test/automated/tildify-tests.el > new file mode 100644 > index 0000000..4223029 > --- /dev/null > +++ b/test/automated/tildify-tests.el > @@ -0,0 +1,106 @@ > +;;; tildify-test.el --- ERT tests for teldify.el > + > +;; Copyright (C) 2014 Free Software Foundation, Inc. > + > +;; Author: Michal Nazarewicz > +;; Version: 4.5 > +;; Keywords: text, TeX, SGML, wp > + > +;; This file is part of GNU Emacs. > + > +;; GNU Emacs 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 3 of the License, or > +;; (at your option) any later version. > + > +;; GNU Emacs 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 GNU Emacs. If not, see . > + > +;;; Commentary: > + > +;; This package defines regression tests for the tildify package. > + > +;;; Code: > + > +(require 'ert) > +(require 'tildify) > + > +(defun tildify-test--example-sentence (space) > + "Return an example sentence with SPACE where hard space is required." > + (concat "Lorem ipsum v" space "dolor sit amet, a" space > + "consectetur adipiscing elit.")) > + > + > +(defun tildify-test--example-html (sentence &optional with-nbsp) > + "Return an example HTML code. > +SENTENCE is placed where spaces should not be replaced with hard spaces, and > +WITH-NBSP is placed where spaces should be replaced with hard spaces. If the > +latter is missing, SENTENCE will be used in all placeholder positions." > + (let ((with-nbsp (or with-nbsp sentence))) > + (concat "

" with-nbsp "

\n" > + "
" sentence "
\n" > + "\n" > + "

" with-nbsp "

\n" > + "<" sentence ">\n"))) > + > + > +(defun tildify-test--test (modes input expected) > + "Test tildify running in MODES. > +INPUT is the initial content of the buffer and EXPECTED is expected result > +after `tildify-buffer' is run." > + (dolist (mode modes) > + (with-temp-buffer > + (funcall mode) > + (let ((header (concat "Testing `tildify-buffer' in " > + (symbol-name mode) "\n"))) > + (insert header input) > + (tildify-buffer t) > + (should (string-equal (concat header expected) (buffer-string))))) > + (with-temp-buffer > + (funcall mode) > + (let ((header (concat "Testing `tildify-region' in " > + (symbol-name mode) "\n"))) > + (insert header input) > + (tildify-region (point-min) (point-max) t) > + (should (string-equal (concat header expected) (buffer-string))))))) > + > +(ert-deftest tildify-test-html () > + "Tests tildification in an HTML document" > + (let* ((sentence (tildify-test--example-sentence " ")) > + (with-nbsp (tildify-test--example-sentence " "))) > + (tildify-test--test '(html-mode sgml-mode) > + (tildify-test--example-html sentence sentence) > + (tildify-test--example-html sentence with-nbsp)))) > + > + > +(defun tildify-test--example-tex (sentence &optional with-nbsp) > + "Return an example (La)Tex code. > +SENTENCE is placed where spaces should not be replaced with hard spaces, and > +WITH-NBSP is placed where spaces should be replaced with hard spaces. If the > +latter is missing, SENTENCE will be used in all placeholder positions." > + (let ((with-nbsp (or with-nbsp sentence))) > + (concat with-nbsp "\n" > + "\\begin{verbatim}\n" sentence "\n\\end{verbatim}\n" > + "\\verb#" sentence "#\n" > + "$$" sentence "$$\n" > + "$" sentence "$\n" > + "\\[" sentence "\\]\n" > + "\\v A % " sentence "\n" > + with-nbsp "\n"))) > + > +(ert-deftest tildify-test-tex () > + "Tests tildification in a (La)TeX document" > + (let* ((sentence (tildify-test--example-sentence " ")) > + (with-nbsp (tildify-test--example-sentence "~"))) > + (tildify-test--test '(tex-mode latex-mode plain-tex-mode) > + (tildify-test--example-tex sentence sentence) > + (tildify-test--example-tex sentence with-nbsp)))) > + > +(provide 'tildify-tests) > + > +;;; tildify-tests.el ends here > -- > 1.9.1.423.g4596e3a