diff options
Diffstat (limited to 'test/lisp')
| -rw-r--r-- | test/lisp/emacs-lisp/rx-tests.el | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index 6f392d616d1..bab71b522bb 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el | |||
| @@ -115,5 +115,46 @@ | |||
| 115 | ;; Test zero-argument `seq'. | 115 | ;; Test zero-argument `seq'. |
| 116 | (should (equal (rx (seq)) ""))) | 116 | (should (equal (rx (seq)) ""))) |
| 117 | 117 | ||
| 118 | (defmacro rx-tests--match (regexp string &optional match) | ||
| 119 | (macroexp-let2 nil strexp string | ||
| 120 | `(ert-info ((format "Matching %S to %S" ',regexp ,strexp)) | ||
| 121 | (should (string-match ,regexp ,strexp)) | ||
| 122 | ,@(when match | ||
| 123 | `((should (equal (match-string 0 ,strexp) ,match))))))) | ||
| 124 | |||
| 125 | (ert-deftest rx-nonstring-expr () | ||
| 126 | (let ((bee "b") | ||
| 127 | (vowel "[aeiou]")) | ||
| 128 | (rx-tests--match (rx "a" (literal bee) "c") "abc") | ||
| 129 | (rx-tests--match (rx "a" (regexp bee) "c") "abc") | ||
| 130 | (rx-tests--match (rx "a" (or (regexp bee) "xy") "c") "abc") | ||
| 131 | (rx-tests--match (rx "a" (or "xy" (regexp bee)) "c") "abc") | ||
| 132 | (should-not (string-match (rx (or (regexp bee) "xy")) "")) | ||
| 133 | (rx-tests--match (rx "a" (= 3 (regexp bee)) "c") "abbbc") | ||
| 134 | (rx-tests--match (rx "x" (= 3 (regexp vowel)) "z") "xeoez") | ||
| 135 | (should-not (string-match (rx "x" (= 3 (regexp vowel)) "z") "xe[]z")) | ||
| 136 | (rx-tests--match (rx "x" (= 3 (literal vowel)) "z") | ||
| 137 | "x[aeiou][aeiou][aeiou]z") | ||
| 138 | (rx-tests--match (rx "x" (repeat 1 (regexp vowel)) "z") "xaz") | ||
| 139 | (rx-tests--match (rx "x" (repeat 1 2 (regexp vowel)) "z") "xaz") | ||
| 140 | (rx-tests--match (rx "x" (repeat 1 2 (regexp vowel)) "z") "xauz") | ||
| 141 | (rx-tests--match (rx "x" (>= 1 (regexp vowel)) "z") "xaiiz") | ||
| 142 | (rx-tests--match (rx "x" (** 1 2 (regexp vowel)) "z") "xaiz") | ||
| 143 | (rx-tests--match (rx "x" (group (regexp vowel)) "z") "xaz") | ||
| 144 | (rx-tests--match (rx "x" (group-n 1 (regexp vowel)) "z") "xaz") | ||
| 145 | (rx-tests--match (rx "x" (? (regexp vowel)) "z") "xz"))) | ||
| 146 | |||
| 147 | (ert-deftest rx-nonstring-expr-non-greedy () | ||
| 148 | "`rx's greediness can't affect runtime regexp parts." | ||
| 149 | (let ((ad-min "[ad]*?") | ||
| 150 | (ad-max "[ad]*") | ||
| 151 | (ad "[ad]")) | ||
| 152 | (rx-tests--match (rx "c" (regexp ad-min) "a") "cdaaada" "cda") | ||
| 153 | (rx-tests--match (rx "c" (regexp ad-max) "a") "cdaaada" "cdaaada") | ||
| 154 | (rx-tests--match (rx "c" (minimal-match (regexp ad-max)) "a") "cdaaada" "cdaaada") | ||
| 155 | (rx-tests--match (rx "c" (maximal-match (regexp ad-min)) "a") "cdaaada" "cda") | ||
| 156 | (rx-tests--match (rx "c" (minimal-match (0+ (regexp ad))) "a") "cdaaada" "cda") | ||
| 157 | (rx-tests--match (rx "c" (maximal-match (0+ (regexp ad))) "a") "cdaaada" "cdaaada"))) | ||
| 158 | |||
| 118 | (provide 'rx-tests) | 159 | (provide 'rx-tests) |
| 119 | ;; rx-tests.el ends here. | 160 | ;; rx-tests.el ends here. |