aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMattias EngdegÄrd2020-02-11 20:04:42 +0100
committerMattias EngdegÄrd2020-03-01 10:47:14 +0100
commit49d3cd90bd80a225d5ec26027318ffb4606ff513 (patch)
tree13ba7b7faec7014b626d1c4dfdbfec98df44631f /test
parent6b48aedb6b3b1de0b41b61b727d14ab8277d2f73 (diff)
downloademacs-49d3cd90bd80a225d5ec26027318ffb4606ff513.tar.gz
emacs-49d3cd90bd80a225d5ec26027318ffb4606ff513.zip
rx: Improve 'or' compositionality (bug#37659)
Perform 'regexp-opt' on nested 'or' forms, and after expansion of user-defined and 'eval' forms. Characters are now turned into strings for wider 'regexp-opt' scope. This preserves the longest-match semantics for string in 'or' forms over composition. * doc/lispref/searching.texi (Rx Constructs): Document. * lisp/emacs-lisp/rx.el (rx--normalise-or-arg) (rx--all-string-or-args): New. (rx--translate-or): Normalise arguments first, and check for strings in subforms. (rx--expand-eval): Extracted from rx--translate-eval. (rx--translate-eval): Call rx--expand-eval. * test/lisp/emacs-lisp/rx-tests.el (rx-or, rx-def-in-or): Add tests. * etc/NEWS: Announce.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/rx-tests.el13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el
index 2e34d65a9aa..4888e1d9d1e 100644
--- a/test/lisp/emacs-lisp/rx-tests.el
+++ b/test/lisp/emacs-lisp/rx-tests.el
@@ -42,13 +42,24 @@
42(ert-deftest rx-or () 42(ert-deftest rx-or ()
43 (should (equal (rx (or "ab" (| "c" nonl) "de")) 43 (should (equal (rx (or "ab" (| "c" nonl) "de"))
44 "ab\\|c\\|.\\|de")) 44 "ab\\|c\\|.\\|de"))
45 (should (equal (rx (or "ab" "abc" "a")) 45 (should (equal (rx (or "ab" "abc" ?a))
46 "\\(?:a\\(?:bc?\\)?\\)")) 46 "\\(?:a\\(?:bc?\\)?\\)"))
47 (should (equal (rx (or "ab" (| (or "abcd" "abcde")) (or "a" "abc")))
48 "\\(?:a\\(?:b\\(?:c\\(?:de?\\)?\\)?\\)?\\)"))
49 (should (equal (rx (or "a" (eval (string ?a ?b))))
50 "\\(?:ab?\\)"))
47 (should (equal (rx (| nonl "a") (| "b" blank)) 51 (should (equal (rx (| nonl "a") (| "b" blank))
48 "\\(?:.\\|a\\)\\(?:b\\|[[:blank:]]\\)")) 52 "\\(?:.\\|a\\)\\(?:b\\|[[:blank:]]\\)"))
49 (should (equal (rx (|)) 53 (should (equal (rx (|))
50 "\\`a\\`"))) 54 "\\`a\\`")))
51 55
56(ert-deftest rx-def-in-or ()
57 (rx-let ((a b)
58 (b (or "abc" c))
59 (c ?a))
60 (should (equal (rx (or a (| "ab" "abcde") "abcd"))
61 "\\(?:a\\(?:b\\(?:c\\(?:de?\\)?\\)?\\)?\\)"))))
62
52(ert-deftest rx-char-any () 63(ert-deftest rx-char-any ()
53 "Test character alternatives with `]' and `-' (Bug#25123)." 64 "Test character alternatives with `]' and `-' (Bug#25123)."
54 (should (equal 65 (should (equal