aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichal Nazarewicz2016-08-17 19:53:01 +0200
committerMichal Nazarewicz2016-09-09 03:07:15 +0200
commit8634efa38179f44c2cb5c52c25ced3f02fa5ec1a (patch)
treef05347064ee2e1c7f260488313fd08232be8e18c /test
parent4516130d5a4bec47e86bdf560a1375740b6bb110 (diff)
downloademacs-8634efa38179f44c2cb5c52c25ced3f02fa5ec1a.tar.gz
emacs-8634efa38179f44c2cb5c52c25ced3f02fa5ec1a.zip
Split regex character class test into smaller chunks
Having one test for all character classes it is not always trivial to determine which class is failing. This happens when failure is caused by ‘(should (equal (point) (point-max)))’ not being met. With per-character class tests, it is immidiatelly obvious which test causes issues plus tests for all classes are run even if some of them fail. * test/src/regex-tests.el (regex-character-classes): Delete and split into… (regex-tests-alnum-character-class, regex-tests-alpha-character-class, regex-tests-ascii-character-class, regex-tests-blank-character-class, regex-tests-cntrl-character-class, regex-tests-digit-character-class, regex-tests-graph-character-class, regex-tests-lower-character-class, regex-tests-multibyte-character-class, regex-tests-nonascii-character-class, regex-tests-print-character-class, regex-tests-punct-character-class, regex-tests-space-character-class, regex-tests-unibyte-character-class, regex-tests-upper-character-class, regex-tests-word-character-class, regex-tests-xdigit-character-class): …new tests.
Diffstat (limited to 'test')
-rw-r--r--test/src/regex-tests.el90
1 files changed, 46 insertions, 44 deletions
diff --git a/test/src/regex-tests.el b/test/src/regex-tests.el
index 6e21088114e..c4844c7cdbc 100644
--- a/test/src/regex-tests.el
+++ b/test/src/regex-tests.el
@@ -45,54 +45,56 @@ character) must match a string \"\u2420\"."
45 (concat string suffix))))))))) 45 (concat string suffix)))))))))
46 46
47(defun regex--test-cc (name matching not-matching) 47(defun regex--test-cc (name matching not-matching)
48 (should (string-match-p (concat "^[[:" name ":]]*$") matching)) 48 (let (case-fold-search)
49 (should (string-match-p (concat "^[[:" name ":]]*?\u2622$") 49 (should (string-match-p (concat "^[[:" name ":]]*$") matching))
50 (concat matching "\u2622"))) 50 (should (string-match-p (concat "^[[:" name ":]]*?\u2622$")
51 (should (string-match-p (concat "^[^[:" name ":]]*$") not-matching)) 51 (concat matching "\u2622")))
52 (should (string-match-p (concat "^[^[:" name ":]]*\u2622$") 52 (should (string-match-p (concat "^[^[:" name ":]]*$") not-matching))
53 (concat not-matching "\u2622"))) 53 (should (string-match-p (concat "^[^[:" name ":]]*\u2622$")
54 (with-temp-buffer 54 (concat not-matching "\u2622")))
55 (insert matching) 55 (with-temp-buffer
56 (let ((p (point))) 56 (insert matching)
57 (insert not-matching) 57 (let ((p (point)))
58 (goto-char (point-min)) 58 (insert not-matching)
59 (skip-chars-forward (concat "[:" name ":]")) 59 (goto-char (point-min))
60 (should (equal (point) p)) 60 (skip-chars-forward (concat "[:" name ":]"))
61 (skip-chars-forward (concat "^[:" name ":]")) 61 (should (equal (point) p))
62 (should (equal (point) (point-max))) 62 (skip-chars-forward (concat "^[:" name ":]"))
63 (goto-char (point-min)) 63 (should (equal (point) (point-max)))
64 (skip-chars-forward (concat "[:" name ":]\u2622")) 64 (goto-char (point-min))
65 (should (or (equal (point) p) (equal (point) (1+ p))))))) 65 (skip-chars-forward (concat "[:" name ":]\u2622"))
66 66 (should (or (equal (point) p) (equal (point) (1+ p))))))))
67(ert-deftest regex-character-classes () 67
68 "Perform sanity test of regexes using character classes. 68(dolist (test '(("alnum" "abcABC012łąka" "-, \t\n")
69 ("alpha" "abcABCłąka" "-,012 \t\n")
70 ("digit" "012" "abcABCłąka-, \t\n")
71 ("xdigit" "0123aBc" "łąk-, \t\n")
72 ("upper" "ABCŁĄKA" "abc012-, \t\n")
73 ("lower" "abcłąka" "ABC012-, \t\n")
74
75 ("word" "abcABC012\u2620" "-, \t\n")
76
77 ("punct" ".,-" "abcABC012\u2620 \t\n")
78 ("cntrl" "\1\2\t\n" ".,-abcABC012\u2620 ")
79 ("graph" "abcłąka\u2620-," " \t\n\1")
80 ("print" "abcłąka\u2620-, " "\t\n\1")
81
82 ("space" " \t\n\u2001" "abcABCł0123")
83 ("blank" " \t" "\n\u2001")
84
85 ("ascii" "abcABC012 \t\n\1" "łą\u2620")
86 ("nonascii" "łą\u2622" "abcABC012 \t\n\1")
87 ("unibyte" "abcABC012 \t\n\1" "łą\u2622")
88 ("multibyte" "łą\u2622" "abcABC012 \t\n\1")))
89 (let ((name (intern (concat "regex-tests-" (car test) "-character-class")))
90 (doc (concat "Perform sanity test of regexes using " (car test)
91 " character class.
69 92
70Go over all the supported character classes and test whether the 93Go over all the supported character classes and test whether the
71classes and their inversions match what they are supposed to 94classes and their inversions match what they are supposed to
72match. The test is done using `string-match-p' as well as 95match. The test is done using `string-match-p' as well as
73`skip-chars-forward'." 96`skip-chars-forward'.")))
74 (let (case-fold-search) 97 (eval `(ert-deftest ,name () ,doc ,(cons 'regex--test-cc test)) t)))
75 (regex--test-cc "alnum" "abcABC012łąka" "-, \t\n")
76 (regex--test-cc "alpha" "abcABCłąka" "-,012 \t\n")
77 (regex--test-cc "digit" "012" "abcABCłąka-, \t\n")
78 (regex--test-cc "xdigit" "0123aBc" "łąk-, \t\n")
79 (regex--test-cc "upper" "ABCŁĄKA" "abc012-, \t\n")
80 (regex--test-cc "lower" "abcłąka" "ABC012-, \t\n")
81
82 (regex--test-cc "word" "abcABC012\u2620" "-, \t\n")
83
84 (regex--test-cc "punct" ".,-" "abcABC012\u2620 \t\n")
85 (regex--test-cc "cntrl" "\1\2\t\n" ".,-abcABC012\u2620 ")
86 (regex--test-cc "graph" "abcłąka\u2620-," " \t\n\1")
87 (regex--test-cc "print" "abcłąka\u2620-, " "\t\n\1")
88
89 (regex--test-cc "space" " \t\n\u2001" "abcABCł0123")
90 (regex--test-cc "blank" " \t" "\n\u2001")
91
92 (regex--test-cc "ascii" "abcABC012 \t\n\1" "łą\u2620")
93 (regex--test-cc "nonascii" "łą\u2622" "abcABC012 \t\n\1")
94 (regex--test-cc "unibyte" "abcABC012 \t\n\1" "łą\u2622")
95 (regex--test-cc "multibyte" "łą\u2622" "abcABC012 \t\n\1")))
96 98
97 99
98(defmacro regex-tests-generic-line (comment-char test-file whitelist &rest body) 100(defmacro regex-tests-generic-line (comment-char test-file whitelist &rest body)