diff options
| author | Mattias EngdegÄrd | 2019-12-06 22:23:57 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-12-10 22:37:47 +0100 |
| commit | ea93326cc046cb1beb7535cdf6d69b216b767685 (patch) | |
| tree | 5494bab812fdaf3f7a2997cb70926bdf6ec13993 /test/lisp | |
| parent | 9546a2a0d6653a7d930cda722f5babbebb0a1d0c (diff) | |
| download | emacs-ea93326cc046cb1beb7535cdf6d69b216b767685.tar.gz emacs-ea93326cc046cb1beb7535cdf6d69b216b767685.zip | |
Add `union' and `intersection' to rx (bug#37849)
These character set operations, together with `not' for set
complement, improve the compositionality of rx, and reduce duplication
in complicated cases. Named character classes are not permitted in
set operations.
* lisp/emacs-lisp/rx.el (rx--translate-any): Split into multiple
functions.
(rx--foldl, rx--parse-any, rx--generate-alt, rx--intervals-to-alt)
(rx--complement-intervals, rx--intersect-intervals)
(rx--union-intervals, rx--charset-intervals, rx--charset-union)
(rx--charset-all, rx--charset-intersection, rx--translate-union)
(rx--translate-intersection): New.
(rx--translate-not, rx--translate-form, rx--builtin-forms, rx):
Add `union' and `intersection'.
* test/lisp/emacs-lisp/rx-tests.el (rx-union ,rx-def-in-union)
(rx-intersection, rx-def-in-intersection): New tests.
* doc/lispref/searching.texi (Rx Constructs):
* etc/NEWS:
Document `union' and `intersection'.
Diffstat (limited to 'test/lisp')
| -rw-r--r-- | test/lisp/emacs-lisp/rx-tests.el | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index 317dae2990b..0cd2c9590b7 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el | |||
| @@ -274,6 +274,63 @@ | |||
| 274 | (should (equal (rx (not (not ascii)) (not (not (not (any "a-z"))))) | 274 | (should (equal (rx (not (not ascii)) (not (not (not (any "a-z"))))) |
| 275 | "[[:ascii:]][^a-z]"))) | 275 | "[[:ascii:]][^a-z]"))) |
| 276 | 276 | ||
| 277 | (ert-deftest rx-union () | ||
| 278 | (should (equal (rx (union)) | ||
| 279 | "\\`a\\`")) | ||
| 280 | (should (equal (rx (union (any "ba"))) | ||
| 281 | "[ab]")) | ||
| 282 | (should (equal (rx (union (any "a-f") (any "c-k" ?y) (any ?r "x-z"))) | ||
| 283 | "[a-krx-z]")) | ||
| 284 | (should (equal (rx (union (not (any "a-m")) (not (any "f-p")))) | ||
| 285 | "[^f-m]")) | ||
| 286 | (should (equal (rx (union (any "e-m") (not (any "a-z")))) | ||
| 287 | "[^a-dn-z]")) | ||
| 288 | (should (equal (rx (union (not (any "g-r")) (not (any "t")))) | ||
| 289 | "[^z-a]")) | ||
| 290 | (should (equal (rx (not (union (not (any "g-r")) (not (any "t"))))) | ||
| 291 | "\\`a\\`")) | ||
| 292 | (should (equal (rx (union (union (any "a-f") (any "u-z")) | ||
| 293 | (any "g-r"))) | ||
| 294 | "[a-ru-z]")) | ||
| 295 | (should (equal (rx (union (intersection (any "c-z") (any "a-g")) | ||
| 296 | (not (any "a-k")))) | ||
| 297 | "[^abh-k]"))) | ||
| 298 | |||
| 299 | (ert-deftest rx-def-in-union () | ||
| 300 | (rx-let ((a (any "badc")) | ||
| 301 | (b (union a (any "def")))) | ||
| 302 | (should (equal(rx (union b (any "q"))) | ||
| 303 | "[a-fq]")))) | ||
| 304 | |||
| 305 | (ert-deftest rx-intersection () | ||
| 306 | (should (equal (rx (intersection)) | ||
| 307 | "[^z-a]")) | ||
| 308 | (should (equal (rx (intersection (any "ba"))) | ||
| 309 | "[ab]")) | ||
| 310 | (should (equal (rx (intersection (any "a-j" "u-z") (any "c-k" ?y) | ||
| 311 | (any "a-i" "x-z"))) | ||
| 312 | "[c-iy]")) | ||
| 313 | (should (equal (rx (intersection (not (any "a-m")) (not (any "f-p")))) | ||
| 314 | "[^a-p]")) | ||
| 315 | (should (equal (rx (intersection (any "a-z") (not (any "g-q")))) | ||
| 316 | "[a-fr-z]")) | ||
| 317 | (should (equal (rx (intersection (any "a-d") (any "e"))) | ||
| 318 | "\\`a\\`")) | ||
| 319 | (should (equal (rx (not (intersection (any "a-d") (any "e")))) | ||
| 320 | "[^z-a]")) | ||
| 321 | (should (equal (rx (intersection (any "d-u") | ||
| 322 | (intersection (any "e-z") (any "a-m")))) | ||
| 323 | "[e-m]")) | ||
| 324 | (should (equal (rx (intersection (union (any "a-f") (any "f-t")) | ||
| 325 | (any "e-w"))) | ||
| 326 | "[e-t]"))) | ||
| 327 | |||
| 328 | (ert-deftest rx-def-in-intersection () | ||
| 329 | (rx-let ((a (any "a-g")) | ||
| 330 | (b (intersection a (any "d-j")))) | ||
| 331 | (should (equal(rx (intersection b (any "e-k"))) | ||
| 332 | "[e-g]")))) | ||
| 333 | |||
| 277 | (ert-deftest rx-group () | 334 | (ert-deftest rx-group () |
| 278 | (should (equal (rx (group nonl) (submatch "x") | 335 | (should (equal (rx (group nonl) (submatch "x") |
| 279 | (group-n 3 "y") (submatch-n 13 "z") (backref 1)) | 336 | (group-n 3 "y") (submatch-n 13 "z") (backref 1)) |