[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 8634efa 6/6: Split regex character class test into
From: |
Michal Nazarewicz |
Subject: |
[Emacs-diffs] master 8634efa 6/6: Split regex character class test into smaller chunks |
Date: |
Fri, 9 Sep 2016 16:32:58 +0000 (UTC) |
branch: master
commit 8634efa38179f44c2cb5c52c25ced3f02fa5ec1a
Author: Michal Nazarewicz <address@hidden>
Commit: Michal Nazarewicz <address@hidden>
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.
---
test/src/regex-tests.el | 90 ++++++++++++++++++++++++-----------------------
1 file changed, 46 insertions(+), 44 deletions(-)
diff --git a/test/src/regex-tests.el b/test/src/regex-tests.el
index 6e21088..c4844c7 100644
--- a/test/src/regex-tests.el
+++ b/test/src/regex-tests.el
@@ -45,54 +45,56 @@ character) must match a string \"\u2420\"."
(concat string suffix)))))))))
(defun regex--test-cc (name matching not-matching)
- (should (string-match-p (concat "^[[:" name ":]]*$") matching))
- (should (string-match-p (concat "^[[:" name ":]]*?\u2622$")
- (concat matching "\u2622")))
- (should (string-match-p (concat "^[^[:" name ":]]*$") not-matching))
- (should (string-match-p (concat "^[^[:" name ":]]*\u2622$")
- (concat not-matching "\u2622")))
- (with-temp-buffer
- (insert matching)
- (let ((p (point)))
- (insert not-matching)
- (goto-char (point-min))
- (skip-chars-forward (concat "[:" name ":]"))
- (should (equal (point) p))
- (skip-chars-forward (concat "^[:" name ":]"))
- (should (equal (point) (point-max)))
- (goto-char (point-min))
- (skip-chars-forward (concat "[:" name ":]\u2622"))
- (should (or (equal (point) p) (equal (point) (1+ p)))))))
-
-(ert-deftest regex-character-classes ()
- "Perform sanity test of regexes using character classes.
+ (let (case-fold-search)
+ (should (string-match-p (concat "^[[:" name ":]]*$") matching))
+ (should (string-match-p (concat "^[[:" name ":]]*?\u2622$")
+ (concat matching "\u2622")))
+ (should (string-match-p (concat "^[^[:" name ":]]*$") not-matching))
+ (should (string-match-p (concat "^[^[:" name ":]]*\u2622$")
+ (concat not-matching "\u2622")))
+ (with-temp-buffer
+ (insert matching)
+ (let ((p (point)))
+ (insert not-matching)
+ (goto-char (point-min))
+ (skip-chars-forward (concat "[:" name ":]"))
+ (should (equal (point) p))
+ (skip-chars-forward (concat "^[:" name ":]"))
+ (should (equal (point) (point-max)))
+ (goto-char (point-min))
+ (skip-chars-forward (concat "[:" name ":]\u2622"))
+ (should (or (equal (point) p) (equal (point) (1+ p))))))))
+
+(dolist (test '(("alnum" "abcABC012łąka" "-, \t\n")
+ ("alpha" "abcABCłąka" "-,012 \t\n")
+ ("digit" "012" "abcABCłąka-, \t\n")
+ ("xdigit" "0123aBc" "łąk-, \t\n")
+ ("upper" "ABCŁĄKA" "abc012-, \t\n")
+ ("lower" "abcłąka" "ABC012-, \t\n")
+
+ ("word" "abcABC012\u2620" "-, \t\n")
+
+ ("punct" ".,-" "abcABC012\u2620 \t\n")
+ ("cntrl" "\1\2\t\n" ".,-abcABC012\u2620 ")
+ ("graph" "abcłąka\u2620-," " \t\n\1")
+ ("print" "abcłąka\u2620-, " "\t\n\1")
+
+ ("space" " \t\n\u2001" "abcABCł0123")
+ ("blank" " \t" "\n\u2001")
+
+ ("ascii" "abcABC012 \t\n\1" "łą\u2620")
+ ("nonascii" "łą\u2622" "abcABC012 \t\n\1")
+ ("unibyte" "abcABC012 \t\n\1" "łą\u2622")
+ ("multibyte" "łą\u2622" "abcABC012 \t\n\1")))
+ (let ((name (intern (concat "regex-tests-" (car test) "-character-class")))
+ (doc (concat "Perform sanity test of regexes using " (car test)
+ " character class.
Go over all the supported character classes and test whether the
classes and their inversions match what they are supposed to
match. The test is done using `string-match-p' as well as
-`skip-chars-forward'."
- (let (case-fold-search)
- (regex--test-cc "alnum" "abcABC012łąka" "-, \t\n")
- (regex--test-cc "alpha" "abcABCłąka" "-,012 \t\n")
- (regex--test-cc "digit" "012" "abcABCłąka-, \t\n")
- (regex--test-cc "xdigit" "0123aBc" "łąk-, \t\n")
- (regex--test-cc "upper" "ABCŁĄKA" "abc012-, \t\n")
- (regex--test-cc "lower" "abcłąka" "ABC012-, \t\n")
-
- (regex--test-cc "word" "abcABC012\u2620" "-, \t\n")
-
- (regex--test-cc "punct" ".,-" "abcABC012\u2620 \t\n")
- (regex--test-cc "cntrl" "\1\2\t\n" ".,-abcABC012\u2620 ")
- (regex--test-cc "graph" "abcłąka\u2620-," " \t\n\1")
- (regex--test-cc "print" "abcłąka\u2620-, " "\t\n\1")
-
- (regex--test-cc "space" " \t\n\u2001" "abcABCł0123")
- (regex--test-cc "blank" " \t" "\n\u2001")
-
- (regex--test-cc "ascii" "abcABC012 \t\n\1" "łą\u2620")
- (regex--test-cc "nonascii" "łą\u2622" "abcABC012 \t\n\1")
- (regex--test-cc "unibyte" "abcABC012 \t\n\1" "łą\u2622")
- (regex--test-cc "multibyte" "łą\u2622" "abcABC012 \t\n\1")))
+`skip-chars-forward'.")))
+ (eval `(ert-deftest ,name () ,doc ,(cons 'regex--test-cc test)) t)))
(defmacro regex-tests-generic-line (comment-char test-file whitelist &rest
body)
- [Emacs-diffs] master updated (e951aa1 -> 8634efa), Michal Nazarewicz, 2016/09/09
- [Emacs-diffs] master 4516130 5/6: Don’t allocate char-table’s extra slots in regexp-out-charset, Michal Nazarewicz, 2016/09/09
- [Emacs-diffs] master 3ffc5f4 1/6: STRING_CHAR does not unify characters; update documentation, Michal Nazarewicz, 2016/09/09
- [Emacs-diffs] master 8634efa 6/6: Split regex character class test into smaller chunks,
Michal Nazarewicz <=
- [Emacs-diffs] master 0e7eb64 4/6: Remove dead loop iterations in regex.c, Michal Nazarewicz, 2016/09/09
- [Emacs-diffs] master c579b28 3/6: Replace decimalnump with alphanumericp, Michal Nazarewicz, 2016/09/09
- [Emacs-diffs] master b1c4c00 2/6: Remove inaccurate comment in regex.c, Michal Nazarewicz, 2016/09/09