From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel,gmane.emacs.bugs Subject: [PATCH] Add basic test suits for tildify package. Date: Wed, 21 May 2014 17:37:50 -1000 Organization: Google Inc Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1400730505 10320 80.91.229.3 (22 May 2014 03:48:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 May 2014 03:48:25 +0000 (UTC) To: emacs-devel@gnu.org, bug-gnu-emacs@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 22 05:48:20 2014 Return-path: Envelope-to: ged-emacs-devel@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 1WnJzO-0001dK-PW for ged-emacs-devel@m.gmane.org; Thu, 22 May 2014 05:48:19 +0200 Original-Received: from localhost ([::1]:34546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnJzN-0002QU-P5 for ged-emacs-devel@m.gmane.org; Wed, 21 May 2014 23:48:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnJzG-0002QM-W6 for emacs-devel@gnu.org; Wed, 21 May 2014 23:48:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WnJzC-0000YP-K2 for emacs-devel@gnu.org; Wed, 21 May 2014 23:48:10 -0400 Original-Received: from mail-pb0-x22d.google.com ([2607:f8b0:400e:c01::22d]:53606) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnJzC-0000Y1-8i for emacs-devel@gnu.org; Wed, 21 May 2014 23:48:06 -0400 Original-Received: by mail-pb0-f45.google.com with SMTP id um1so2061498pbc.32 for ; Wed, 21 May 2014 20:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:organization:user-agent:face:message-id :mime-version:content-type; bh=vcE0/t6N2VNEs0d8yk64puu78ai5d7ISsTi5IX0QdSY=; b=fF7NYLprY2hbL0Tvhxs6/TbwM7deAsSDPzYbl9BNxKTZEwOJy7j88UVugQHa576EAb 3MXMjBwi19/TKAngRWHY1xTS7zcjDKIttRGstlbBf0Z2uS7ZVnEjQ4jREmqEw8QqNnU2 BjBwwiEOTW29Sh5BpW0H6XenRiy0dIg05t+HkaWJ0eNrdRpk/8aRSunV4UopT69+l68e CXiXLvH+l834t9IjpzHibWhWW0keAErrFS4t/1DvQj3fZvllCecX0tdbXsrSOWGPN3Q/ Ni8UYaRVmBdQYGRDsmVUwj2i8LI+Hi+4K50WrzkpSDLrr7K8V1xy7sOvFfMtKPR5R00F lWIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:organization :user-agent:face:message-id:mime-version:content-type; bh=vcE0/t6N2VNEs0d8yk64puu78ai5d7ISsTi5IX0QdSY=; b=Hj1bV63TK7ojnXg1R6tiDioPb/41s+q2irlJ1Z4Y/tr2Vk2vyoMNLG6B9RD+vz0lNM 3OhLHxL25+IeyAvrdCnA+hUZnQfWRgwM19qnN4gTzfFiQxhGYpud3mN138s21mobyN6H RYNrSYf6AvDXTlSUhueg43JD4GNHhGLbgWenyME+c6K+yxB0t52Lx+o0ZCRAauARFW6Y kdgsTpTXTYu0iHNUiux+5bxXRVlohTbCFBORjmwyhIzbAkBuHY6W9NHhUhKVfA3I6/1O 4qHSe+aBd3FeWVfxEZXQG77mopCH9VDEX8uqeRGBJJHzXX+Zv9WqYOY4EVUHKu9mFN1/ 7cwg== X-Gm-Message-State: ALoCoQlYZRxezeI/4OBvHbjO8jnlwQSX20rZWgWpmQxnchLKU5z4ycbCDfn2suadP26eq9hJvOP4 X-Received: by 10.66.250.202 with SMTP id ze10mr64261804pac.153.1400730484323; Wed, 21 May 2014 20:48:04 -0700 (PDT) Original-Received: from mpn-glaptop.roam.corp.google.com (rrcs-24-43-221-254.west.biz.rr.com. [24.43.221.254]) by mx.google.com with ESMTPSA id id10sm10519854pbc.35.2014.05.21.20.48.02 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 21 May 2014 20:48:03 -0700 (PDT) User-Agent: Notmuch/0.17+15~gb65ca8e (http://notmuchmail.org) Emacs/24.4.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd; KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR 4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:172013 gmane.emacs.bugs:89341 Archived-At: --- 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