Explorar o código

New tests for unicode aware percent escaping

* test-org.el (test-org/org-link-escape-ascii-character)
(test-org/org-link-escape-ascii-ctrl-character)
(test-org/org-link-escape-multibyte-character)
(test-org/org-link-escape-custom-table)
(test-org/org-link-escape-custom-table-merge)
(test-org/org-link-unescape-ascii-character)
(test-org/org-link-unescape-ascii-ctrl-character)
(test-org/org-link-unescape-multibyte-character)
(test-org/org-link-unescape-ascii-extended-char): New tests for
unicode aware percent escaping

All tests for escaping/unescaping multibyte characters are expected to
fail at the moment, because org-link-escape/unescape is not yet
unicode aware.
David Maus %!s(int64=14) %!d(string=hai) anos
pai
achega
47486604a4
Modificáronse 1 ficheiros con 89 adicións e 0 borrados
  1. 89 0
      testing/lisp/test-org.el

+ 89 - 0
testing/lisp/test-org.el

@@ -0,0 +1,89 @@
+;;; test-org.el
+
+;; Copyright (c) ߚ David Maus
+;; Authors: David Maus
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+;;;; Comments:
+
+;; Template test file for Org-mode tests
+
+
+;;; Code:
+(let ((load-path (cons (expand-file-name
+			".." (file-name-directory
+			      (or load-file-name buffer-file-name)))
+		       load-path)))
+  (require 'org-test)
+  (require 'org-test-ob-consts))
+
+
+;;; Tests
+(ert-deftest test-org/org-link-escape-ascii-character ()
+  "Escape an ascii character."
+  (should
+   (string=
+    "%5B"
+    (org-link-escape "["))))
+
+(ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
+  "Escape an ascii control character."
+  (should
+   (string=
+    "%09"
+    (org-link-escape "\t"))))
+
+(ert-deftest test-org/org-link-escape-multibyte-character ()
+  "Escape an unicode multibyte character."
+  (should
+   (string=
+    "%E2%82%AC"
+    (org-link-escape "€"))))
+
+(ert-deftest test-org/org-link-escape-custom-table ()
+  "Escape string with custom character table."
+  (should
+   (string=
+    "Foo%3A%42ar%0A"
+    (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
+
+(ert-deftest test-org/org-link-escape-custom-table-merge ()
+  "Escape string with custom table merged with default table."
+  (should
+   (string=
+    "%5BF%6F%6F%3A%42ar%0A%5D"
+    (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
+
+(ert-deftest test-org/org-link-unescape-ascii-character ()
+  "Unescape an ascii character."
+  (should
+   (string=
+    "["
+    (org-link-unescape "%5B"))))
+
+(ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
+  "Unescpae an ascii control character."
+  (should
+   (string=
+    "\n"
+    (org-link-unescape "%0A"))))
+
+(ert-deftest test-org/org-link-unescape-multibyte-character ()
+  "Unescape unicode multibyte character."
+  (should
+   (string=
+    "€"
+    (org-link-unescape "%E2%82%AC"))))
+
+(ert-deftest test-org/org-link-unescape-ascii-extended-char ()
+  "Unescape old style percent escaped character."
+  (should
+   (string=
+    "àâçèéêîôùû"
+    (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB"))))
+
+(provide 'test-org)
+
+;;; test-org.el ends here