2020-11-14 16:24:26 +01:00
|
|
|
;;; ansi-color-tests.el --- Test suite for ansi-color -*- lexical-binding: t; -*-
|
|
|
|
|
2021-01-01 01:13:56 -08:00
|
|
|
;; Copyright (C) 2020-2021 Free Software Foundation, Inc.
|
2020-11-14 16:24:26 +01:00
|
|
|
|
|
|
|
;; Author: Pablo Barbáchano <pablob@amazon.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 'ansi-color)
|
|
|
|
|
2021-09-24 00:30:06 +01:00
|
|
|
(defvar ansi-color-tests--strings
|
|
|
|
(let ((bright-yellow (face-foreground 'ansi-color-bright-yellow nil 'default))
|
|
|
|
(yellow (face-foreground 'ansi-color-yellow nil 'default)))
|
|
|
|
`(("Hello World" "Hello World")
|
|
|
|
("\e[33mHello World\e[0m" "Hello World"
|
|
|
|
(:foreground ,yellow))
|
|
|
|
("\e[43mHello World\e[0m" "Hello World"
|
|
|
|
(:background ,yellow))
|
|
|
|
("\e[93mHello World\e[0m" "Hello World"
|
|
|
|
(:foreground ,bright-yellow))
|
|
|
|
("\e[103mHello World\e[0m" "Hello World"
|
|
|
|
(:background ,bright-yellow))
|
|
|
|
("\e[1;33mHello World\e[0m" "Hello World"
|
|
|
|
(ansi-color-bold (:foreground ,yellow))
|
|
|
|
(ansi-color-bold (:foreground ,bright-yellow)))
|
|
|
|
("\e[33;1mHello World\e[0m" "Hello World"
|
|
|
|
(ansi-color-bold (:foreground ,yellow))
|
|
|
|
(ansi-color-bold (:foreground ,bright-yellow)))
|
|
|
|
("\e[1m\e[33mHello World\e[0m" "Hello World"
|
|
|
|
(ansi-color-bold (:foreground ,yellow))
|
|
|
|
(ansi-color-bold (:foreground ,bright-yellow)))
|
|
|
|
("\e[33m\e[1mHello World\e[0m" "Hello World"
|
|
|
|
(ansi-color-bold (:foreground ,yellow))
|
|
|
|
(ansi-color-bold (:foreground ,bright-yellow)))
|
|
|
|
("\e[1m\e[3m\e[5mbold italics blink\e[0m" "bold italics blink"
|
|
|
|
(ansi-color-bold ansi-color-italic ansi-color-slow-blink))
|
|
|
|
("\e[10munrecognized\e[0m" "unrecognized"))))
|
2020-11-14 16:24:26 +01:00
|
|
|
|
|
|
|
(ert-deftest ansi-color-apply-on-region-test ()
|
2021-09-24 00:30:06 +01:00
|
|
|
(pcase-dolist (`(,input ,text ,face) ansi-color-tests--strings)
|
Add support for "bright" ANSI colors in ansi-color
* lisp/ansi-color.el (ansi-color-bold, ansi-color-faint, ansi-color-italic)
(ansi-color-underline, ansi-color-slow-blink, ansi-color-fast-blink)
(ansi-color-inverse, ansi-color-red, ansi-color-green, ansi-color-yellow)
(ansi-color-blue, ansi-color-magenta, ansi-color-cyan, ansi-color-white)
(ansi-color-bright-red, ansi-color-bright-green, ansi-color-bright-yellow)
(ansi-color-bright-blue, ansi-color-bright-magenta, ansi-color-bright-cyan)
(ansi-color-bright-white): New faces.
(ansi-color-basic-faces-vector, ansi-color-normal-colors-vector)
(ansi-color-bright-colors-vector): New constants.
(ansi-color-faces-vector, ansi-color-names-vector): Make obsolete.
(ansi-color-bold-is-bright): New defcustom.
(ansi-color--find-face): Sort ANSI codes and check
'ansi-color-bold-is-bright'.
(ansi-color-apply-sequence): Support bright ANSI colors.
(ansi-color-make-color-map, ansi-color-map, ansi-color-map-update):
Make obsolete.
(ansi-color-get-face-1): Add BRIGHT parameter.
* lisp/man.el (Man-ansi-color-basic-faces-vector): New variable.
(Man-ansi-color-map): Make obsolete.
(Man-fontify-manpage): Use 'Man-ansi-color-basic-faces-vector' here.
* test/lisp/ansi-color-tests.el
(ansi-color-apply-on-region-bold-is-bright-test): New function.
2021-09-22 18:37:52 -07:00
|
|
|
(with-temp-buffer
|
|
|
|
(insert input)
|
|
|
|
(ansi-color-apply-on-region (point-min) (point-max))
|
|
|
|
(should (equal (buffer-string) text))
|
|
|
|
(should (equal (get-char-property (point-min) 'face) face))
|
|
|
|
(when face
|
2021-09-24 00:30:06 +01:00
|
|
|
(should (overlays-at (point-min)))))))
|
Add support for "bright" ANSI colors in ansi-color
* lisp/ansi-color.el (ansi-color-bold, ansi-color-faint, ansi-color-italic)
(ansi-color-underline, ansi-color-slow-blink, ansi-color-fast-blink)
(ansi-color-inverse, ansi-color-red, ansi-color-green, ansi-color-yellow)
(ansi-color-blue, ansi-color-magenta, ansi-color-cyan, ansi-color-white)
(ansi-color-bright-red, ansi-color-bright-green, ansi-color-bright-yellow)
(ansi-color-bright-blue, ansi-color-bright-magenta, ansi-color-bright-cyan)
(ansi-color-bright-white): New faces.
(ansi-color-basic-faces-vector, ansi-color-normal-colors-vector)
(ansi-color-bright-colors-vector): New constants.
(ansi-color-faces-vector, ansi-color-names-vector): Make obsolete.
(ansi-color-bold-is-bright): New defcustom.
(ansi-color--find-face): Sort ANSI codes and check
'ansi-color-bold-is-bright'.
(ansi-color-apply-sequence): Support bright ANSI colors.
(ansi-color-make-color-map, ansi-color-map, ansi-color-map-update):
Make obsolete.
(ansi-color-get-face-1): Add BRIGHT parameter.
* lisp/man.el (Man-ansi-color-basic-faces-vector): New variable.
(Man-ansi-color-map): Make obsolete.
(Man-fontify-manpage): Use 'Man-ansi-color-basic-faces-vector' here.
* test/lisp/ansi-color-tests.el
(ansi-color-apply-on-region-bold-is-bright-test): New function.
2021-09-22 18:37:52 -07:00
|
|
|
|
|
|
|
(ert-deftest ansi-color-apply-on-region-bold-is-bright-test ()
|
2021-09-24 00:30:06 +01:00
|
|
|
(pcase-dolist (`(,input ,text ,normal-face ,bright-face)
|
|
|
|
ansi-color-tests--strings)
|
Add support for "bright" ANSI colors in ansi-color
* lisp/ansi-color.el (ansi-color-bold, ansi-color-faint, ansi-color-italic)
(ansi-color-underline, ansi-color-slow-blink, ansi-color-fast-blink)
(ansi-color-inverse, ansi-color-red, ansi-color-green, ansi-color-yellow)
(ansi-color-blue, ansi-color-magenta, ansi-color-cyan, ansi-color-white)
(ansi-color-bright-red, ansi-color-bright-green, ansi-color-bright-yellow)
(ansi-color-bright-blue, ansi-color-bright-magenta, ansi-color-bright-cyan)
(ansi-color-bright-white): New faces.
(ansi-color-basic-faces-vector, ansi-color-normal-colors-vector)
(ansi-color-bright-colors-vector): New constants.
(ansi-color-faces-vector, ansi-color-names-vector): Make obsolete.
(ansi-color-bold-is-bright): New defcustom.
(ansi-color--find-face): Sort ANSI codes and check
'ansi-color-bold-is-bright'.
(ansi-color-apply-sequence): Support bright ANSI colors.
(ansi-color-make-color-map, ansi-color-map, ansi-color-map-update):
Make obsolete.
(ansi-color-get-face-1): Add BRIGHT parameter.
* lisp/man.el (Man-ansi-color-basic-faces-vector): New variable.
(Man-ansi-color-map): Make obsolete.
(Man-fontify-manpage): Use 'Man-ansi-color-basic-faces-vector' here.
* test/lisp/ansi-color-tests.el
(ansi-color-apply-on-region-bold-is-bright-test): New function.
2021-09-22 18:37:52 -07:00
|
|
|
(with-temp-buffer
|
|
|
|
(let ((ansi-color-bold-is-bright t)
|
|
|
|
(face (or bright-face normal-face)))
|
|
|
|
(insert input)
|
2020-11-14 16:24:26 +01:00
|
|
|
(ansi-color-apply-on-region (point-min) (point-max))
|
Add support for "bright" ANSI colors in ansi-color
* lisp/ansi-color.el (ansi-color-bold, ansi-color-faint, ansi-color-italic)
(ansi-color-underline, ansi-color-slow-blink, ansi-color-fast-blink)
(ansi-color-inverse, ansi-color-red, ansi-color-green, ansi-color-yellow)
(ansi-color-blue, ansi-color-magenta, ansi-color-cyan, ansi-color-white)
(ansi-color-bright-red, ansi-color-bright-green, ansi-color-bright-yellow)
(ansi-color-bright-blue, ansi-color-bright-magenta, ansi-color-bright-cyan)
(ansi-color-bright-white): New faces.
(ansi-color-basic-faces-vector, ansi-color-normal-colors-vector)
(ansi-color-bright-colors-vector): New constants.
(ansi-color-faces-vector, ansi-color-names-vector): Make obsolete.
(ansi-color-bold-is-bright): New defcustom.
(ansi-color--find-face): Sort ANSI codes and check
'ansi-color-bold-is-bright'.
(ansi-color-apply-sequence): Support bright ANSI colors.
(ansi-color-make-color-map, ansi-color-map, ansi-color-map-update):
Make obsolete.
(ansi-color-get-face-1): Add BRIGHT parameter.
* lisp/man.el (Man-ansi-color-basic-faces-vector): New variable.
(Man-ansi-color-map): Make obsolete.
(Man-fontify-manpage): Use 'Man-ansi-color-basic-faces-vector' here.
* test/lisp/ansi-color-tests.el
(ansi-color-apply-on-region-bold-is-bright-test): New function.
2021-09-22 18:37:52 -07:00
|
|
|
(should (equal (buffer-string) text))
|
|
|
|
(should (equal (get-char-property (point-min) 'face) face))
|
|
|
|
(when face
|
2021-09-24 00:30:06 +01:00
|
|
|
(should (overlays-at (point-min))))))))
|
2020-11-14 16:24:26 +01:00
|
|
|
|
|
|
|
(ert-deftest ansi-color-apply-on-region-preserving-test ()
|
2021-09-24 00:30:06 +01:00
|
|
|
(dolist (pair ansi-color-tests--strings)
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert (car pair))
|
|
|
|
(ansi-color-apply-on-region (point-min) (point-max) t)
|
|
|
|
(should (equal (buffer-string) (car pair))))))
|
2020-11-14 16:24:26 +01:00
|
|
|
|
|
|
|
(provide 'ansi-color-tests)
|
|
|
|
|
|
|
|
;;; ansi-color-tests.el ends here
|