diff options
| author | Mattias EngdegÄrd | 2023-07-30 15:30:38 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2023-07-30 18:12:19 +0200 |
| commit | 2b8796eea1979fe6891ab9d80cd126fe8980167a (patch) | |
| tree | 0e49ad64bf11942baf797aecf87723ecc8842f00 /test | |
| parent | ba60070b81c4b507b856269031a17b99e9f5e77c (diff) | |
| download | emacs-2b8796eea1979fe6891ab9d80cd126fe8980167a.tar.gz emacs-2b8796eea1979fe6891ab9d80cd126fe8980167a.zip | |
Fix rx wrong-code bug: ranges starting with ^
(rx (in (?^ . ?a))) was incorrectly translated to "[^-a]".
Change it so that we get "[_-a^]" instead.
* lisp/emacs-lisp/rx.el (rx--generate-alt): Split ranges starting with
`^` occurring first in a non-negated character alternative.
* test/lisp/emacs-lisp/rx-tests.el (rx-any): Add and adapt tests.
(cherry picked from commit 5f5d668ac7917d61e9366fe0c3efd7b542671c3d)
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/emacs-lisp/rx-tests.el | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index 028250b7352..9c8628a8f26 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el | |||
| @@ -112,23 +112,33 @@ | |||
| 112 | (should (equal (rx (any "]" "^") (any "]" "-") (any "-" "^") | 112 | (should (equal (rx (any "]" "^") (any "]" "-") (any "-" "^") |
| 113 | (not (any "]" "^")) (not (any "]" "-")) | 113 | (not (any "]" "^")) (not (any "]" "-")) |
| 114 | (not (any "-" "^"))) | 114 | (not (any "-" "^"))) |
| 115 | "[]^][]-][-^][^]^][^]-][^-^]")) | 115 | "[]^][]-][-^][^]^][^]-][^^-]")) |
| 116 | (should (equal (rx (any "]" "^" "-") (not (any "]" "^" "-"))) | 116 | (should (equal (rx (any "]" "^" "-") (not (any "]" "^" "-"))) |
| 117 | "[]^-][^]^-]")) | 117 | "[]^-][^]^-]")) |
| 118 | (should (equal (rx (any "^-f") (any "^-f" "-") | ||
| 119 | (any "^-f" "z") (any "^-f" "z" "-")) | ||
| 120 | "[_-f^][_-f^-][_-f^z][_-f^z-]")) | ||
| 121 | (should (equal (rx (not (any "^-f")) (not (any "^-f" "-")) | ||
| 122 | (not (any "^-f" "z")) (not (any "^-f" "z" "-"))) | ||
| 123 | "[^^-f][^^-f-][^^-fz][^^-fz-]")) | ||
| 124 | (should (equal (rx (any "^-f" word) (any "^-f" "-" word)) | ||
| 125 | "[_-f^[:word:]][_-f^[:word:]-]")) | ||
| 126 | (should (equal (rx (not (any "^-f" word)) (not (any "^-f" "-" word))) | ||
| 127 | "[^^-f[:word:]][^^-f[:word:]-]")) | ||
| 118 | (should (equal (rx (any "-" ascii) (any "^" ascii) (any "]" ascii)) | 128 | (should (equal (rx (any "-" ascii) (any "^" ascii) (any "]" ascii)) |
| 119 | "[[:ascii:]-][[:ascii:]^][][:ascii:]]")) | 129 | "[[:ascii:]-][[:ascii:]^][][:ascii:]]")) |
| 120 | (should (equal (rx (not (any "-" ascii)) (not (any "^" ascii)) | 130 | (should (equal (rx (not (any "-" ascii)) (not (any "^" ascii)) |
| 121 | (not (any "]" ascii))) | 131 | (not (any "]" ascii))) |
| 122 | "[^[:ascii:]-][^[:ascii:]^][^][:ascii:]]")) | 132 | "[^[:ascii:]-][^^[:ascii:]][^][:ascii:]]")) |
| 123 | (should (equal (rx (any "-]" ascii) (any "^]" ascii) (any "-^" ascii)) | 133 | (should (equal (rx (any "-]" ascii) (any "^]" ascii) (any "-^" ascii)) |
| 124 | "[][:ascii:]-][]^[:ascii:]][[:ascii:]^-]")) | 134 | "[][:ascii:]-][]^[:ascii:]][[:ascii:]^-]")) |
| 125 | (should (equal (rx (not (any "-]" ascii)) (not (any "^]" ascii)) | 135 | (should (equal (rx (not (any "-]" ascii)) (not (any "^]" ascii)) |
| 126 | (not (any "-^" ascii))) | 136 | (not (any "-^" ascii))) |
| 127 | "[^][:ascii:]-][^]^[:ascii:]][^[:ascii:]^-]")) | 137 | "[^][:ascii:]-][^]^[:ascii:]][^^[:ascii:]-]")) |
| 128 | (should (equal (rx (any "-]^" ascii) (not (any "-]^" ascii))) | 138 | (should (equal (rx (any "-]^" ascii) (not (any "-]^" ascii))) |
| 129 | "[]^[:ascii:]-][^]^[:ascii:]-]")) | 139 | "[]^[:ascii:]-][^]^[:ascii:]-]")) |
| 130 | (should (equal (rx (any "^" lower upper) (not (any "^" lower upper))) | 140 | (should (equal (rx (any "^" lower upper) (not (any "^" lower upper))) |
| 131 | "[[:lower:]^[:upper:]][^[:lower:]^[:upper:]]")) | 141 | "[[:lower:]^[:upper:]][^^[:lower:][:upper:]]")) |
| 132 | (should (equal (rx (any "-" lower upper) (not (any "-" lower upper))) | 142 | (should (equal (rx (any "-" lower upper) (not (any "-" lower upper))) |
| 133 | "[[:lower:][:upper:]-][^[:lower:][:upper:]-]")) | 143 | "[[:lower:][:upper:]-][^[:lower:][:upper:]-]")) |
| 134 | (should (equal (rx (any "]" lower upper) (not (any "]" lower upper))) | 144 | (should (equal (rx (any "]" lower upper) (not (any "]" lower upper))) |
| @@ -143,7 +153,7 @@ | |||
| 143 | "[]-a-][^]-a-]")) | 153 | "[]-a-][^]-a-]")) |
| 144 | (should (equal (rx (any "--]") (not (any "--]")) | 154 | (should (equal (rx (any "--]") (not (any "--]")) |
| 145 | (any "-" "^-a") (not (any "-" "^-a"))) | 155 | (any "-" "^-a") (not (any "-" "^-a"))) |
| 146 | "[].-\\-][^].-\\-][-^-a][^-^-a]")) | 156 | "[].-\\-][^].-\\-][_-a^-][^^-a-]")) |
| 147 | (should (equal (rx (not (any "!a" "0-8" digit nonascii))) | 157 | (should (equal (rx (not (any "!a" "0-8" digit nonascii))) |
| 148 | "[^!0-8a[:digit:][:nonascii:]]")) | 158 | "[^!0-8a[:digit:][:nonascii:]]")) |
| 149 | (should (equal (rx (any) (not (any))) | 159 | (should (equal (rx (any) (not (any))) |