diff options
Diffstat (limited to 'test/lisp/textmodes')
-rw-r--r-- | test/lisp/textmodes/conf-mode-tests.el | 204 | ||||
-rw-r--r-- | test/lisp/textmodes/css-mode-tests.el | 113 | ||||
-rw-r--r-- | test/lisp/textmodes/fill-tests.el | 50 | ||||
-rw-r--r-- | test/lisp/textmodes/page-tests.el | 103 | ||||
-rw-r--r-- | test/lisp/textmodes/paragraphs-tests.el | 165 | ||||
-rw-r--r-- | test/lisp/textmodes/sgml-mode-tests.el | 54 | ||||
-rw-r--r-- | test/lisp/textmodes/underline-tests.el | 42 |
7 files changed, 723 insertions, 8 deletions
diff --git a/test/lisp/textmodes/conf-mode-tests.el b/test/lisp/textmodes/conf-mode-tests.el new file mode 100644 index 00000000000..3eefc8f84f9 --- /dev/null +++ b/test/lisp/textmodes/conf-mode-tests.el @@ -0,0 +1,204 @@ +;;; conf-mode-tests.el --- Test suite for conf mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2016-2019 Free Software Foundation, Inc. + +;; Author: J. Alexander Branham <alex.branham@gmail.com> +;; Keywords: internal + +;; This file is 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 3 of the License, 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, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;;; Code: +(require 'conf-mode) +(require 'ert) + +(ert-deftest conf-test-align-assignments () + "Test for `conf-align-assignments'." + (with-temp-buffer + (insert "foo: bar\nbar: baz") + (conf-colon-mode) + (conf-align-assignments) + (should (equal (buffer-string) + "foo: bar\nbar: baz")))) + +(ert-deftest conf-test-font-lock () + (with-temp-buffer + (insert "foo: bar\nbar: baz") + (conf-colon-mode) + (font-lock-mode) + (font-lock-ensure) + (goto-char (point-min)) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (search-forward "bar") + (should-not (face-at-point)))) + +(ert-deftest conf-test-windows-mode () + (with-temp-buffer + ;; from `conf-windows-mode' docstring: + (insert "[ExtShellFolderViews] +Default={5984FFE0-28D4-11CF-AE66-08002B2E1262} +{5984FFE0-28D4-11CF-AE66-08002B2E1262}={5984FFE0-28D4-11CF-AE66-08002B2E1262} + +[{5984FFE0-28D4-11CF-AE66-08002B2E1262}] +PersistMoniker=file://Folder.htt") + (goto-char (point-min)) + (conf-windows-mode) + (font-lock-mode) + (font-lock-ensure) + (search-forward "ExtShell") + (should (equal (face-at-point) 'font-lock-type-face)) + (search-forward "Defau") + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (forward-line) + (beginning-of-line) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (forward-line 2) + (should-not (face-at-point)) + (forward-char) + (should (equal (face-at-point) 'font-lock-type-face)))) + +(ert-deftest conf-test-javaprop-mode () + (with-temp-buffer + ;; From `conf-javaprop-mode' docstring + (insert "// another kind of comment +/* yet another */ + +name:value +name=value +name value +x.1 = +x.2.y.1.z.1 = +x.2.y.1.z.2.zz =") + (goto-char (point-min)) + (conf-javaprop-mode) + (font-lock-mode) + (font-lock-ensure) + (should (equal (face-at-point) 'font-lock-comment-delimiter-face)) + (forward-char 3) + (should (equal (face-at-point) 'font-lock-comment-face)) + (search-forward "*") + (should (equal (face-at-point) 'font-lock-comment-delimiter-face)) + (while (search-forward "nam" nil t) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (search-forward "val") + (should-not (face-at-point))) + (while (re-search-forward "a-z" nil t) + (backward-char) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (re-search-forward "[0-0]" nil t) + (backward-char) + (should (equal (face-at-point) 'font-lock-constant-face))))) + +(ert-deftest conf-test-space-mode () + ;; From `conf-space-mode' docstring. + (with-temp-buffer + (insert "image/jpeg jpeg jpg jpe +image/png png +image/tiff tiff tif +") + (goto-char (point-min)) + (conf-space-mode) + (font-lock-mode) + (font-lock-ensure) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (forward-char 15) + (should-not (face-at-point)))) + +(ert-deftest conf-test-colon-mode () + ;; From `conf-colon-mode' docstring. + (with-temp-buffer + (insert "<Multi_key> <exclam> <exclam> : \"\\241\" exclamdown +<Multi_key> <c> <slash> : \"\\242\" cent") + (goto-char (point-min)) + (conf-colon-mode) + (font-lock-mode) + (font-lock-ensure) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (search-forward "24") + (should (equal (face-at-point) 'font-lock-string-face)) + (forward-line) + (should (equal (face-at-point) 'font-lock-variable-name-face)))) + +(ert-deftest conf-test-ppd-mode () + ;; From `conf-ppd-mode' docstring. + (with-temp-buffer + (insert "*DefaultTransfer: Null +*Transfer Null.Inverse: \"{ 1 exch sub }\"") + (goto-char (point-min)) + (conf-ppd-mode) + (font-lock-mode) + (font-lock-ensure) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (search-forward "Nul") + (should-not (face-at-point)))) + +(ert-deftest conf-test-xdefaults-mode () + ;; From `conf-xdefaults-mode' docstring. + (with-temp-buffer + (insert "*background: gray99 +*foreground: black") + (goto-char (point-min)) + (conf-xdefaults-mode) + (font-lock-mode) + (font-lock-ensure) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (search-forward "gray") + (should-not (face-at-point)))) + +(ert-deftest conf-test-toml-mode () + ;; From `conf-toml-mode' docstring. + (with-temp-buffer + (insert "\[entry] +value = \"some string\"") + (goto-char (point-min)) + (conf-toml-mode) + (font-lock-mode) + (font-lock-ensure) + (should-not (face-at-point)) + (forward-char) + (should (equal (face-at-point) 'font-lock-type-face)) + (forward-line) + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (search-forward "som") + (should (equal (face-at-point) 'font-lock-string-face)))) + +(ert-deftest conf-test-desktop-mode () + ;; From `conf-desktop-mode' dostring. + (with-temp-buffer + (insert " [Desktop Entry] + Name=GNU Image Manipulation Program + Name[oc]=Editor d'imatge GIMP + Exec=gimp-2.8 %U + Terminal=false") + (goto-char (point-min)) + (conf-desktop-mode) + (font-lock-mode) + (font-lock-ensure) + (search-forward "Desk") + (should (equal (face-at-point) 'font-lock-type-face)) + (search-forward "Nam") + (should (equal (face-at-point) 'font-lock-variable-name-face)) + (forward-char 2) + (should-not (face-at-point)) + (search-forward "[") + (should (equal (face-at-point) 'font-lock-constant-face)))) + + + +(provide 'conf-mode-tests) + +;;; conf-mode-tests.el ends here diff --git a/test/lisp/textmodes/css-mode-tests.el b/test/lisp/textmodes/css-mode-tests.el index c16ad3ac287..98dac7478f2 100644 --- a/test/lisp/textmodes/css-mode-tests.el +++ b/test/lisp/textmodes/css-mode-tests.el @@ -85,7 +85,7 @@ (insert "body { top: 0; }") (goto-char 7) (should (equal (css-current-defun-name) "body")) - (goto-char 18) + (goto-char 15) (should (equal (css-current-defun-name) "body")))) (ert-deftest css-test-current-defun-name-nested () @@ -244,6 +244,99 @@ (should (member "body" completions)) (should-not (member "article" completions))))) +(ert-deftest css-test-color-to-4-dpc () + (should (equal (css--color-to-4-dpc "#ffffff") + (css--color-to-4-dpc "#fff"))) + (should (equal (css--color-to-4-dpc "#aabbcc") + (css--color-to-4-dpc "#abc"))) + (should (equal (css--color-to-4-dpc "#fab") + "#ffffaaaabbbb")) + (should (equal (css--color-to-4-dpc "#fafbfc") + "#fafafbfbfcfc"))) + +(ert-deftest css-test-format-hex () + (should (equal (css--format-hex "#fff") "#fff")) + (should (equal (css--format-hex "#ffffff") "#fff")) + (should (equal (css--format-hex "#aabbcc") "#abc")) + (should (equal (css--format-hex "#12ff34") "#12ff34")) + (should (equal (css--format-hex "#aabbccdd") "#abcd")) + (should (equal (css--format-hex "#aabbccde") "#aabbccde")) + (should (equal (css--format-hex "#abcdef") "#abcdef"))) + +(ert-deftest css-test-named-color-to-hex () + (dolist (item '(("black" "#000") + ("white" "#fff") + ("salmon" "#fa8072"))) + (with-temp-buffer + (css-mode) + (insert (nth 0 item)) + (css--named-color-to-hex) + (should (equal (buffer-string) (nth 1 item)))))) + +(ert-deftest css-test-format-rgba-alpha () + (should (equal (css--format-rgba-alpha 0) "0")) + (should (equal (css--format-rgba-alpha 0.0) "0")) + (should (equal (css--format-rgba-alpha 0.00001) "0")) + (should (equal (css--format-rgba-alpha 1) "1")) + (should (equal (css--format-rgba-alpha 1.0) "1")) + (should (equal (css--format-rgba-alpha 1.00001) "1")) + (should (equal (css--format-rgba-alpha 0.10000) "0.1")) + (should (equal (css--format-rgba-alpha 0.100001) "0.1")) + (should (equal (css--format-rgba-alpha 0.2524334) "0.25"))) + +(ert-deftest css-test-hex-to-rgb () + (dolist (item '(("#000" "rgb(0, 0, 0)") + ("#000000" "rgb(0, 0, 0)") + ("#fff" "rgb(255, 255, 255)") + ("#ffffff" "rgb(255, 255, 255)") + ("#ffffff80" "rgba(255, 255, 255, 0.5)") + ("#fff0" "rgba(255, 255, 255, 0)") + ("#fff8" "rgba(255, 255, 255, 0.53)") + ("#ffff" "rgba(255, 255, 255, 1)"))) + (with-temp-buffer + (css-mode) + (insert (nth 0 item)) + (css--hex-to-rgb) + (should (equal (buffer-string) (nth 1 item)))))) + +(ert-deftest css-test-rgb-to-named-color-or-hex () + (dolist (item '(("rgb(0, 0, 0)" "black") + ("rgb(255, 255, 255)" "white") + ("rgb(255, 255, 240)" "ivory") + ("rgb(18, 52, 86)" "#123456") + ("rgba(18, 52, 86, 0.5)" "#12345680") + ("rgba(18, 52, 86, 50%)" "#12345680") + ("rgba(50%, 50%, 50%, 50%)" "#80808080"))) + (with-temp-buffer + (css-mode) + (insert (nth 0 item)) + (css--rgb-to-named-color-or-hex) + (should (equal (buffer-string) (nth 1 item)))))) + +(ert-deftest css-test-cycle-color-format () + (with-temp-buffer + (css-mode) + (insert "black") + (css-cycle-color-format) + (should (equal (buffer-string) "#000")) + (css-cycle-color-format) + (should (equal (buffer-string) "rgb(0, 0, 0)")) + (css-cycle-color-format) + (should (equal (buffer-string) "black")))) + +(ert-deftest css-test-join-nested-selectors () + (should (equal (css--join-nested-selectors '("div" "&:hover")) + "div:hover")) + (should + (equal (css--join-nested-selectors '("a" "&::before, &::after")) + "a::before, a::after")) + (should + (equal (css--join-nested-selectors + '("article" "& > .front-page" "& h1, & h2")) + "article > .front-page h1, article > .front-page h2")) + (should (equal (css--join-nested-selectors '(".link" "& + &")) + ".link + .link"))) + (ert-deftest css-mdn-symbol-guessing () (dolist (item '(("@med" "ia" "@media") ("@keyframes " "{" "@keyframes") @@ -263,11 +356,11 @@ (ert-deftest css-test-rgb-parser () (with-temp-buffer (css-mode) - (dolist (input '("255, 0, 127" - "255, /* comment */ 0, 127" - "255 0 127" - "255, 0, 127, 0.75" - "255 0 127 / 0.75" + (dolist (input '("255, 0, 128" + "255, /* comment */ 0, 128" + "255 0 128" + "255, 0, 128, 0.75" + "255 0 128 / 0.75" "100%, 0%, 50%" "100%, 0%, 50%, 0.115" "100% 0% 50%" @@ -275,7 +368,7 @@ (erase-buffer) (save-excursion (insert input ")")) - (should (equal (css--rgb-color) "#ff007f"))))) + (should (equal (css--rgb-color) "#ff0080"))))) (ert-deftest css-test-hsl-parser () (with-temp-buffer @@ -301,6 +394,12 @@ (should (equal (css--hex-color "#aabbcc") "#aabbcc")) (should (equal (css--hex-color "#aabbccdd") "#aabbcc"))) +(ert-deftest css-test-hex-alpha () + (should (equal (css--hex-alpha "#abcd") "d")) + (should-not (css--hex-alpha "#abc")) + (should (equal (css--hex-alpha "#aabbccdd") "dd")) + (should-not (css--hex-alpha "#aabbcc"))) + (ert-deftest css-test-named-color () (dolist (text '("@mixin black" "@include black")) (with-temp-buffer diff --git a/test/lisp/textmodes/fill-tests.el b/test/lisp/textmodes/fill-tests.el new file mode 100644 index 00000000000..08728746629 --- /dev/null +++ b/test/lisp/textmodes/fill-tests.el @@ -0,0 +1,50 @@ +;;; fill-test.el --- ERT tests for fill.el -*- lexical-binding: t -*- + +;; Copyright (C) 2017-2019 Free Software Foundation, Inc. + +;; Author: Marcin Borkowski <mbork@mbork.pl> +;; Keywords: text, 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 <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; This package defines tests for the filling feature, specifically +;; the `fill-polish-nobreak-p' function. + +;;; Code: + +(require 'ert) + +(ert-deftest fill-test-no-fill-polish-nobreak-p nil + "Tests of the `fill-polish-nobreak-p' function." + (with-temp-buffer + (insert "Abc d efg (h ijk).") + (setq fill-column 8) + (setq-local fill-nobreak-predicate '()) + (fill-paragraph) + (should (string= (buffer-string) "Abc d\nefg (h\nijk)."))) + (with-temp-buffer + (insert "Abc d efg (h ijk).") + (setq fill-column 8) + (setq-local fill-nobreak-predicate '(fill-polish-nobreak-p)) + (fill-paragraph) + (should (string= (buffer-string) "Abc\nd efg\n(h ijk).")))) + + +(provide 'fill-tests) + +;;; fill-tests.el ends here diff --git a/test/lisp/textmodes/page-tests.el b/test/lisp/textmodes/page-tests.el new file mode 100644 index 00000000000..517f1d5a9e5 --- /dev/null +++ b/test/lisp/textmodes/page-tests.el @@ -0,0 +1,103 @@ +;;; page-tests.el --- Tests for page.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; Author: Simen Heggestøyl <simenheg@gmail.com> +;; Keywords: + +;; 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 <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'ert) +(require 'page) + +(ert-deftest page-tests-forward-page () + (with-temp-buffer + (insert "foo\n\nbar\n\nbaz") + (forward-page -1) + (should (looking-at-p "\nbaz")) + (forward-page -2) + (should (= (point) (point-min))) + (forward-page 1) + (should (looking-at-p "\nbar")) + (forward-page) + (should (looking-at-p "\nbaz")) + (forward-page 1) + (should (= (point) (point-max))))) + +(ert-deftest page-tests-backward-page () + (with-temp-buffer + (insert "foo\n\nbar\n\nbaz") + (backward-page 1) + (should (looking-at-p "\nbaz")) + (backward-page) + (should (looking-at-p "\nbar")) + (backward-page 1) + (should (= (point) (point-min))) + (backward-page -1) + (should (looking-at-p "\nbar")) + (backward-page -2) + (should (= (point) (point-max))))) + +(defun page-tests--region-string () + "Return the contents of the region as a string." + (buffer-substring (region-beginning) (region-end))) + +(ert-deftest page-tests-mark-page () + (with-temp-buffer + (insert "foo\n\nbar\n\nbaz") + (mark-page) + (should (equal (page-tests--region-string) "\nbaz")) + (mark-page -2) + (should (equal (page-tests--region-string) "foo\n")) + (mark-page 1) + (should (equal (page-tests--region-string) "\nbar\n")))) + +(ert-deftest page-tests-narrow-to-page () + (with-temp-buffer + (insert "foo\n\nbar\n\nbaz") + (goto-char (point-min)) + (narrow-to-page) + (should (equal (buffer-string) "foo\n")) + (narrow-to-page 2) + (should (equal (buffer-string) "baz")) + (narrow-to-page -1) + (should (equal (buffer-string) "bar\n")))) + +(ert-deftest page-tests-count-lines-page () + (with-temp-buffer + (insert "foo\n\nbar\n\nbaz") + (goto-char (point-min)) + (should (equal (page--count-lines-page) '(1 0 1))) + (goto-char (point-max)) + (should (equal (page--count-lines-page) '(2 2 0))))) + +(ert-deftest page-tests-what-page () + (with-temp-buffer + (insert "foo\n\nbar\n\nbaz") + (goto-char (point-min)) + (should (equal (page--what-page) '(1 1))) + (forward-page) + (should (equal (page--what-page) '(2 2))) + (forward-page) + (should (equal (page--what-page) '(3 4))))) + +;;; page-tests.el ends here diff --git a/test/lisp/textmodes/paragraphs-tests.el b/test/lisp/textmodes/paragraphs-tests.el new file mode 100644 index 00000000000..5772756740f --- /dev/null +++ b/test/lisp/textmodes/paragraphs-tests.el @@ -0,0 +1,165 @@ +;;; paragraphs-tests.el --- Tests for paragraphs.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; Author: Stefan Kangas <stefankangas@gmail.com> + +;; 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 <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;;; Code: + +(require 'ert) +;; (require 'paragraphs) ; loaded by default + +(ert-deftest paragraphs-tests-sentence-end () + (should (> (length (sentence-end)) 0)) + (let ((sentence-end "override works")) + (should (equal (sentence-end) sentence-end)))) + +(ert-deftest paragraphs-tests-forward-backward-paragraph () + (with-temp-buffer + (insert "AA\nAA\n\nBB\nBB\n") + (goto-char (point-min)) + (forward-paragraph) + (should (equal (point) 7)) + (forward-paragraph) + (should (equal (point) 14)) + (backward-paragraph) + (should (equal (point) 7)) + (backward-paragraph) + (should (equal (point) (point-min))))) + +(ert-deftest paragraphs-tests-mark-paragraph () + (with-temp-buffer + (insert "AA\nAA\n\nBB\nBB\n") + (goto-char (point-min)) + (mark-paragraph) + (should mark-active) + (should (equal (mark) 7))) + (should-error (mark-paragraph 0))) + +(ert-deftest paragraphs-tests-kill-paragraph () + (with-temp-buffer + (insert "AA\nAA\n\nBB\nBB\n") + (goto-char (point-min)) + (kill-paragraph nil) + (should (equal (buffer-string) "\nBB\nBB\n")))) + +(ert-deftest paragraphs-tests-backward-kill-paragraph () + (with-temp-buffer + (insert "AA\nAA\n\nBB\nBB\n") + (goto-char 7) + (backward-kill-paragraph nil) + (should (equal (buffer-string) "\nBB\nBB\n")))) + +(ert-deftest paragraphs-tests-transpose-paragraphs () + (with-temp-buffer + (insert "AA\nAA\n\nBB\nBB\n") + (goto-char (point-min)) + (transpose-paragraphs 1) + (should (equal (buffer-string) "\nBB\nBB\nAA\nAA\n")))) + +(ert-deftest paragraphs-tests-start-of-paragraph-text () + (with-temp-buffer + (insert "AA\nAA\n\nBB\nBB\n") + (goto-char (point-max)) + (start-of-paragraph-text) + (should (equal (point) 8)))) + +(ert-deftest paragraphs-tests-end-of-paragraph-text () + (with-temp-buffer + (insert "AA\nAA\n\nBB\nBB\n") + (goto-char (point-min)) + (end-of-paragraph-text) + (should (equal (point) 6)))) + +(ert-deftest paragraphs-tests-forward-sentence () + (with-temp-buffer + (insert "First sentence. Second sentence.") + (goto-char (point-min)) + (forward-sentence) + (should (equal (point) 16)) + (goto-char (point-min)) + (forward-sentence 2) + (should (equal (point) 34)))) + +(ert-deftest paragraphs-tests-repunctuate-sentences () + (with-temp-buffer + (insert "Just. Some. Sentences.") + (goto-char (point-min)) + (repunctuate-sentences t) + (should (equal (buffer-string) "Just. Some. Sentences.")))) + +(ert-deftest paragraphs-tests-backward-sentence () + (with-temp-buffer + (insert "First sentence. Second sentence.") + (goto-char (point-max)) + (backward-sentence) + (should (equal (point) 18)))) + +(ert-deftest paragraphs-tests-kill-sentence () + (with-temp-buffer + (insert "First sentence. Second sentence.") + (goto-char (point-min)) + (kill-sentence) + (should (equal (buffer-string) " Second sentence.")))) + +(ert-deftest paragraphs-tests-backward-kill-sentence () + (with-temp-buffer + (insert "Should not be killed. Should be killed.") + (goto-char (point-max)) + (backward-kill-sentence) + (should (equal (buffer-string) "Should not be killed. ")))) + +(ert-deftest paragraphs-tests-mark-end-of-sentence () + (with-temp-buffer + (insert "Example sentence. Followed by another one.") + (goto-char (point-min)) + (mark-end-of-sentence 1) + (should mark-active) + (should (equal (mark) 18))) + (with-temp-buffer + (insert "Example sentence. Followed by another one.") + (goto-char (point-min)) + (mark-end-of-sentence 2) + (should mark-active) + (should (equal (mark) 44))) + ;; FIXME: This does not work -- how do I do it? + (with-temp-buffer ; test repeating the command + (insert "Example sentence. Followed by another one.") + (goto-char (point-min)) + (mark-end-of-sentence 1) + (setq last-command 'mark-end-of-sentence) ; hack + (mark-end-of-sentence 1) + (should mark-active) + (should (equal (mark) 18)))) + +(ert-deftest paragraphs-tests-transpose-sentences () + (with-temp-buffer + (insert "First sentence. Second sentence. Third sentence.") + (goto-char (point-min)) + (transpose-sentences 1) + (should (equal (buffer-string) + "Second sentence. First sentence. Third sentence.")) + (goto-char (point-min)) + (transpose-sentences 2) + (should (equal (buffer-string) + "First sentence. Third sentence. Second sentence.")))) + +(provide 'paragraphs-tests) +;;; paragraphs-tests.el ends here diff --git a/test/lisp/textmodes/sgml-mode-tests.el b/test/lisp/textmodes/sgml-mode-tests.el index 0000b352ff0..5630036e55c 100644 --- a/test/lisp/textmodes/sgml-mode-tests.el +++ b/test/lisp/textmodes/sgml-mode-tests.el @@ -130,6 +130,36 @@ The point is set to the beginning of the buffer." (sgml-delete-tag 1) (should (string= "Winter is comin'" (buffer-string))))) +(ert-deftest sgml-quote-works () + (let ((text "Foo<Bar> \"Baz\" 'Qux'\n")) + (with-temp-buffer + ;; Back and forth transformation. + (insert text) + (sgml-quote (point-min) (point-max)) + (should (string= "Foo<Bar> "Baz" 'Qux'\n" + (buffer-string))) + (sgml-quote (point-min) (point-max) t) + (should (string= text (buffer-string))) + + ;; The same text escaped differently. + (erase-buffer) + (insert "Foo<Bar> "Baz" 'Qux'\n") + (sgml-quote (point-min) (point-max) t) + (should (string= text (buffer-string))) + + ;; Lack of semicolon. + (erase-buffer) + (insert "&&") + (sgml-quote (point-min) (point-max) t) + (should (string= "&&" (buffer-string))) + + ;; Double quoting + (sgml-quote (point-min) (point-max)) + (sgml-quote (point-min) (point-max)) + (sgml-quote (point-min) (point-max) t) + (sgml-quote (point-min) (point-max) t) + (should (string= "&&" (buffer-string)))))) + (ert-deftest sgml-tests--quotes-syntax () (dolist (str '("a\"b <t>c'd</t>" "a'b <t>c\"d</t>" @@ -138,7 +168,7 @@ The point is set to the beginning of the buffer." "<t>\"a'\"</t>" "<t>'a\"'</t>" "a\"b <tag>c'd</tag>" - ;;"<tag>c>'d</tag>" Fixed in master. + "<tag>c>'d</tag>" "<t><!-- \" --></t>" "<t><!-- ' --></t>" "<t>(')</t>" @@ -152,5 +182,27 @@ The point is set to the beginning of the buffer." (should (= 1 (car (syntax-ppss (1- (point-max)))))) (should (= 0 (car (syntax-ppss (point-max))))))))) +(ert-deftest sgml-mode-quote-in-long-text () + (with-temp-buffer + (sgml-mode) + (insert "<t>" + ;; `syntax-propertize-wholelines' extends chunk size based + ;; on line length, so newlines are significant! + (make-string syntax-propertize-chunk-size ?a) "\n" + "'" + (make-string syntax-propertize-chunk-size ?a) "\n" + "</t>") + ;; If we just check (syntax-ppss (point-max)) immediately, then + ;; we'll end up propertizing the whole buffer in one chunk (so the + ;; test is useless). Simulate something more like what happens + ;; when the buffer is viewed normally. + (cl-loop for pos from (point-min) to (point-max) + by syntax-propertize-chunk-size + do (syntax-ppss pos)) + (syntax-ppss (point-max)) + ;; Check that last tag is parsed as a tag. + (should (= 1 (- (car (syntax-ppss (1- (point-max)))) + (car (syntax-ppss (point-max)))))))) + (provide 'sgml-mode-tests) ;;; sgml-mode-tests.el ends here diff --git a/test/lisp/textmodes/underline-tests.el b/test/lisp/textmodes/underline-tests.el new file mode 100644 index 00000000000..ce6a6c3185e --- /dev/null +++ b/test/lisp/textmodes/underline-tests.el @@ -0,0 +1,42 @@ +;;; underline-tests.el --- Tests for underline.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; Author: Stefan Kangas <stefankangas@gmail.com> + +;; 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 <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;;; Code: + +(require 'ert) +(require 'underline) + +(ert-deftest underline-tests-underline-region () + (with-temp-buffer + (insert "foo bar baz") + (underline-region 5 8) + (should (equal (buffer-string) "foo _\C-hb_\C-ha_\C-hr baz")))) + +(ert-deftest underline-tests-ununderline-region () + (with-temp-buffer + (insert "foo _\C-hb_\C-ha_\C-hr baz") + (ununderline-region 5 13) + (should (equal (buffer-string) "foo bar baz")))) + +(provide 'underline-tests) +;;; underline-tests.el ends here |