[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xr 8532df8 02/13: Move tests to separate file
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/xr 8532df8 02/13: Move tests to separate file |
Date: |
Wed, 13 Feb 2019 04:03:27 -0500 (EST) |
branch: externals/xr
commit 8532df85cc9a65fde2afdfff2c7b8c8c6ec56dd2
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Move tests to separate file
Put all tests in a separate file, xr-test.el, and use ert.
Byte-compilation is now clean.
---
xr-test.el | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xr.el | 187 --------------------------------------------------
2 files changed, 228 insertions(+), 187 deletions(-)
diff --git a/xr-test.el b/xr-test.el
new file mode 100644
index 0000000..ea3d9b4
--- /dev/null
+++ b/xr-test.el
@@ -0,0 +1,228 @@
+;;; xr-test.el --- Tests for xr.el -*- lexical-binding: t -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Mattias Engdegård <address@hidden>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+(require 'xr)
+(require 'ert)
+
+
+(ert-deftest xr-basic ()
+ (should (equal (xr "a\\$b\\\\c\\[\\]\\q")
+ "a$b\\c[]q"))
+ (should (equal (xr "\\(?:ab\\|c*d\\)?")
+ '(opt (or "ab" (seq (zero-or-more "c") "d")))))
+ (should (equal (xr ".+")
+ '(one-or-more nonl)))
+ )
+
+(ert-deftest xr-repeat ()
+ (should (equal (xr "\\(?:x?y\\)\\{3\\}")
+ '(= 3 (opt "x") "y")))
+ (should (equal (xr "\\(?:x?y\\)\\{3,8\\}")
+ '(repeat 3 8 (opt "x") "y")))
+ (should (equal (xr "\\(?:x?y\\)\\{3,\\}")
+ '(>= 3 (opt "x") "y")))
+ (should (equal (xr "\\(?:x?y\\)\\{,8\\}")
+ '(repeat 0 8 (opt "x") "y")))
+ (should (equal (xr "\\(?:xy\\)\\{4,4\\}")
+ '(= 4 "xy")))
+ (should (equal (xr "a\\{,\\}")
+ '(zero-or-more "a")))
+ (should (equal (xr "a\\{0\\}")
+ '(repeat 0 0 "a")))
+ (should (equal (xr "a\\{0,\\}")
+ '(zero-or-more "a")))
+ (should (equal (xr "a\\{0,0\\}")
+ '(repeat 0 0 "a")))
+ (should (equal (xr "a\\{\\}")
+ '(repeat 0 0 "a")))
+ (should (equal (xr "a\\{,1\\}")
+ '(repeat 0 1 "a")))
+ (should (equal (xr "a\\{1,\\}")
+ '(>= 1 "a")))
+ )
+
+(ert-deftest xr-backref ()
+ (should (equal (xr "\\(ab\\)\\(?3:cd\\)\\1\\3")
+ '(seq (group "ab") (group-n 3 "cd") (backref 1) (backref 3))))
+ )
+
+(ert-deftest xr-misc ()
+ (should (equal (xr "^.\\w\\W\\`\\'\\=\\b\\B\\<\\>\\_<\\_>$")
+ '(seq bol nonl wordchar not-wordchar bos eos point
+ word-boundary not-word-boundary bow eow
+ symbol-start symbol-end eol)))
+ )
+
+(ert-deftest xr-syntax ()
+ (should (equal (xr "\\s-\\s \\sw\\s_\\s.\\s(\\s)\\s\"")
+ '(seq (syntax whitespace) (syntax whitespace) (syntax word)
+ (syntax symbol) (syntax punctuation)
+ (syntax open-parenthesis) (syntax close-parenthesis)
+ (syntax string-quote))))
+ (should (equal (xr "\\s\\\\s/\\s$\\s'\\s<\\s>\\s!\\s|")
+ '(seq (syntax escape) (syntax character-quote)
+ (syntax paired-delimiter) (syntax expression-prefix)
+ (syntax comment-start) (syntax comment-end)
+ (syntax comment-delimiter) (syntax string-delimiter))))
+ (should (equal (xr "\\S-\\S<")
+ '(seq (not (syntax whitespace))
+ (not (syntax comment-start)))))
+ )
+
+(ert-deftest xr-category ()
+ (should (equal (xr "\\c0\\c1\\c2\\c3\\c4\\c5\\c6\\c7\\c8\\c9\\c<\\c>")
+ '(seq (category consonant) (category base-vowel)
+ (category upper-diacritical-mark)
+ (category lower-diacritical-mark)
+ (category tone-mark) (category symbol) (category digit)
+ (category vowel-modifying-diacritical-mark)
+ (category vowel-sign) (category semivowel-lower)
+ (category not-at-end-of-line)
+ (category not-at-beginning-of-line))))
+ (should (equal (xr "\\cA\\cC\\cG\\cH\\cI\\cK\\cN\\cY\\c^")
+ '(seq (category alpha-numeric-two-byte) (category chinese-two-byte)
+ (category greek-two-byte) (category japanese-hiragana-two-byte)
+ (category indian-two-byte)
+ (category japanese-katakana-two-byte)
+ (category korean-hangul-two-byte) (category cyrillic-two-byte)
+ (category combining-diacritic))))
+ (should (equal (xr "\\ca\\cb\\cc\\ce\\cg\\ch\\ci\\cj\\ck\\cl\\co\\cq\\cr")
+ '(seq (category ascii) (category arabic) (category chinese)
+ (category ethiopic) (category greek) (category korean)
+ (category indian) (category japanese)
+ (category japanese-katakana) (category latin) (category lao)
+ (category tibetan) (category japanese-roman))))
+ (should (equal (xr "\\ct\\cv\\cw\\cy\\c|")
+ '(seq (category thai) (category vietnamese) (category hebrew)
+ (category cyrillic) (category can-break))))
+ (should (equal (xr "\\C2\\C^")
+ '(seq (not (category upper-diacritical-mark))
+ (not (category combining-diacritic)))))
+ )
+
+(ert-deftest xr-lazy ()
+ (should (equal (xr "\\(?:a.\\)*?")
+ '(*? "a" nonl)))
+ (should (equal (xr "\\(?:a.\\)+?")
+ '(+? "a" nonl)))
+ (should (equal (xr "\\(?:a.\\)??")
+ '(?? "a" nonl)))
+ (should (equal (xr "\\(?:.\\(a+\\(?:b+?c*\\)?\\)??\\)*")
+ '(zero-or-more
+ nonl
+ (?? (group (one-or-more "a")
+ (opt (+? "b")
+ (zero-or-more "c")))))))
+ )
+
+(ert-deftest xr-char-classes ()
+ (should (equal (xr "[[:alnum:][:blank:]][[:alpha:]][[:cntrl:][:digit:]]")
+ '(seq (any alnum blank) alpha (any cntrl digit))))
+ (should (equal (xr "[^[:lower:][:punct:]][^[:space:]]")
+ '(seq (not (any lower punct)) (not space))))
+ (should (equal (xr "^[a-z]*")
+ '(seq bol (zero-or-more (any "a-z")))))
+ (should (equal (xr "some[.]thing")
+ "some.thing"))
+ (should (equal (xr "[^]-c]")
+ '(not (any "]-c"))))
+ (should (equal (xr "[-^]")
+ '(any "-" "^")))
+ (should (equal (xr "[a-z-+/*%0-4[:xdigit:]]")
+ '(any "a-z" "-" "+/*%" "0-4" xdigit)))
+ (should (equal (xr "[^]A-Za-z-]*")
+ '(zero-or-more (not (any "]" "A-Za-z" "-")))))
+ (should (equal (xr "[+*%A-Ka-k0-3${-}]")
+ '(any "+*%" "A-Ka-k0-3" "$" "{-}")))
+ )
+
+(ert-deftest xr-empty ()
+ (should (equal (xr "")
+ ""))
+ (should (equal (xr "a\\|")
+ '(or "a" "")))
+ (should (equal (xr "\\|a")
+ '(or "" "a")))
+ (should (equal (xr "a\\|\\|b")
+ '(or "a" "" "b")))
+ )
+
+(ert-deftest xr-anything ()
+ (should (equal (xr "\\(?:.\\|\n\\)?\\(\n\\|.\\)*")
+ '(seq (opt anything) (zero-or-more (group anything)))))
+ )
+
+(ert-deftest xr-real ()
+ (should (equal (xr "\\*\\*\\* EOOH \\*\\*\\*\n")
+ "*** EOOH ***\n"))
+ (should (equal (xr "\\<\\(catch\\|finally\\)\\>[^_]")
+ '(seq bow (group (or "catch" "finally")) eow
+ (not (any "_")))))
+ (should (equal (xr "[ \t\n]*:\\([^:]+\\|$\\)")
+ '(seq (zero-or-more (any " \t\n")) ":"
+ (group (or (one-or-more (not (any ":")))
+ eol)))))
+ )
+
+(ert-deftest xr-edge-cases ()
+ (should (equal (xr "^a^b\\(?:^c^\\|^d^\\|e^\\)^")
+ '(seq bol "a^b" (or (seq bol "c^") (seq bol "d^") "e^") "^")))
+ (should (equal (xr "$a$b\\(?:$c$\\|$d$\\|$e$\\)$")
+ '(seq "$a$b" (or (seq "$c" eol) (seq "$d" eol) (seq "$e" eol))
+ eol)))
+ (should (equal (xr "*a\\|*b\\(*c\\)")
+ '(or "*a" (seq "*b" (group "*c")))))
+ (should (equal (xr "+a\\|+b\\(+c\\)")
+ '(or "+a" (seq "+b" (group "+c")))))
+ (should (equal (xr "?a\\|?b\\(?c\\)")
+ '(or "?a" (seq "?b" (group "?c")))))
+ (should (equal (xr "^**")
+ '(seq bol (zero-or-more "*"))))
+ (should (equal (xr "^+")
+ '(seq bol "+")))
+ (should (equal (xr "^?")
+ '(seq bol "?")))
+ (should (equal (xr "*?a\\|^??b")
+ '(or (seq (opt "*") "a") (seq bol (opt "?") "b"))))
+ (should (equal (xr "^\\{xy")
+ '(seq bol "{xy")))
+ (should (equal (xr "\\{2,3\\}")
+ "{2,3}"))
+ )
+
+(ert-deftest xr-simplify ()
+ (should (equal (xr "a\\(?:b?\\(?:c.\\)d*\\)e")
+ '(seq "a" (opt "b") "c" nonl (zero-or-more "d") "e")))
+ (should (equal (xr "a\\(?:b\\(?:c.d\\)e\\)f")
+ '(seq "abc" nonl "def")))
+ )
+
+(ert-deftest xr-pretty ()
+ (should (equal (xr--pp-rx-to-str "A\e\r\n\t\0 \x7f\x80\ B\xff\x02")
+ "\"A\\e\\r\\n\\t\\x00 \\x7f\\200B\\xff\\x02\"\n"))
+ (should (equal (xr--pp-rx-to-str '(?? nonl))
+ "(?? nonl)\n"))
+ (should (equal (xr--pp-rx-to-str '(repeat 1 63 "a"))
+ "(repeat 1 63 \"a\")\n"))
+ )
+
+(provide 'xr-test)
+
+;;; xr-test.el ends here
diff --git a/xr.el b/xr.el
index 199f0e3..6ad306f 100644
--- a/xr.el
+++ b/xr.el
@@ -488,193 +488,6 @@ way. It is intended for use from an interactive elisp
session.
Returns nil."
(insert (xr--pp-rx-to-str (xr re-string))))
-
-(defun xr--expect-result (fun input expected)
- "Verify (FUN INPUT) against EXPECTED."
- (let ((got (funcall fun input)))
- (unless (equal got expected)
- (error "Failure in (%s %S):\ngot %S\nexpected %S"
- fun input got expected))))
-
-(defun xr--expect (regexp-str expected-rx)
- "Verify (xr REGEXP-STR) against EXPECTED-RX."
- (xr--expect-result 'xr regexp-str expected-rx))
-
-(defun xr--expect-pp (rx expected-str)
- "Verify (xr--pp-rx-to-str RX) against EXPECTED-STR."
- (xr--expect-result 'xr--pp-rx-to-str rx expected-str))
-
(provide 'xr)
-(eval-when-compile
- ;; FIXME: When byte-compiling the file, this `eval-when-compile' block
- ;; will be executed at a time where the above functions have been compiled
- ;; but they're not necessarily known by the current Emacs session yet
- ;; (because the neither `xr.el' nor `xr.elc' has been loaded yet).
- ;; As a quick fix, we (require 'xr) here to load the `xr' file (and fail
- ;; silently if the file is not in `load-path').
- ;; Maybe a better fix is to move those tests to a separate file, and/or
- ;; to wrap them in an `ert-deftest'.
- (when (require 'xr nil 'noerror)
- (xr--expect "a\\$b\\\\c\\[\\]\\q"
- "a$b\\c[]q")
- (xr--expect "\\(?:ab\\|c*d\\)?"
- '(opt (or "ab" (seq (zero-or-more "c") "d"))))
- (xr--expect ".+"
- '(one-or-more nonl))
- (xr--expect "\\(?:x?y\\)\\{3\\}"
- '(= 3 (opt "x") "y"))
- (xr--expect "\\(?:x?y\\)\\{3,8\\}"
- '(repeat 3 8 (opt "x") "y"))
- (xr--expect "\\(?:x?y\\)\\{3,\\}"
- '(>= 3 (opt "x") "y"))
- (xr--expect "\\(?:x?y\\)\\{,8\\}"
- '(repeat 0 8 (opt "x") "y"))
- (xr--expect "\\(?:xy\\)\\{4,4\\}"
- '(= 4 "xy"))
- (xr--expect "a\\{,\\}"
- '(zero-or-more "a"))
- (xr--expect "a\\{0\\}"
- '(repeat 0 0 "a"))
- (xr--expect "a\\{0,\\}"
- '(zero-or-more "a"))
- (xr--expect "a\\{0,0\\}"
- '(repeat 0 0 "a"))
- (xr--expect "a\\{\\}"
- '(repeat 0 0 "a"))
- (xr--expect "a\\{,1\\}"
- '(repeat 0 1 "a"))
- (xr--expect "a\\{1,\\}"
- '(>= 1 "a"))
- (xr--expect "\\(ab\\)\\(?3:cd\\)\\1\\3"
- '(seq (group "ab") (group-n 3 "cd") (backref 1) (backref 3)))
- (xr--expect "^.\\w\\W\\`\\'\\=\\b\\B\\<\\>\\_<\\_>$"
- '(seq bol nonl wordchar not-wordchar bos eos point
- word-boundary not-word-boundary bow eow
- symbol-start symbol-end eol))
- (xr--expect "\\s-\\s \\sw\\s_\\s.\\s(\\s)\\s\""
- '(seq (syntax whitespace) (syntax whitespace) (syntax word)
- (syntax symbol) (syntax punctuation)
- (syntax open-parenthesis) (syntax close-parenthesis)
- (syntax string-quote)))
- (xr--expect "\\s\\\\s/\\s$\\s'\\s<\\s>\\s!\\s|"
- '(seq (syntax escape) (syntax character-quote)
- (syntax paired-delimiter) (syntax expression-prefix)
- (syntax comment-start) (syntax comment-end)
- (syntax comment-delimiter) (syntax string-delimiter)))
- (xr--expect "\\S-\\S<"
- '(seq (not (syntax whitespace))
- (not (syntax comment-start))))
- (xr--expect "\\c0\\c1\\c2\\c3\\c4\\c5\\c6\\c7\\c8\\c9\\c<\\c>"
- '(seq (category consonant) (category base-vowel)
- (category upper-diacritical-mark)
- (category lower-diacritical-mark)
- (category tone-mark) (category symbol) (category digit)
- (category vowel-modifying-diacritical-mark)
- (category vowel-sign) (category semivowel-lower)
- (category not-at-end-of-line)
- (category not-at-beginning-of-line)))
- (xr--expect "\\cA\\cC\\cG\\cH\\cI\\cK\\cN\\cY\\c^"
- '(seq (category alpha-numeric-two-byte) (category chinese-two-byte)
- (category greek-two-byte) (category japanese-hiragana-two-byte)
- (category indian-two-byte)
- (category japanese-katakana-two-byte)
- (category korean-hangul-two-byte) (category cyrillic-two-byte)
- (category combining-diacritic)))
- (xr--expect "\\ca\\cb\\cc\\ce\\cg\\ch\\ci\\cj\\ck\\cl\\co\\cq\\cr"
- '(seq (category ascii) (category arabic) (category chinese)
- (category ethiopic) (category greek) (category korean)
- (category indian) (category japanese)
- (category japanese-katakana) (category latin) (category lao)
- (category tibetan) (category japanese-roman)))
- (xr--expect "\\ct\\cv\\cw\\cy\\c|"
- '(seq (category thai) (category vietnamese) (category hebrew)
- (category cyrillic) (category can-break)))
- (xr--expect "\\C2\\C^"
- '(seq (not (category upper-diacritical-mark))
- (not (category combining-diacritic))))
- (xr--expect "\\(?:a.\\)*?"
- '(*? "a" nonl))
- (xr--expect "\\(?:a.\\)+?"
- '(+? "a" nonl))
- (xr--expect "\\(?:a.\\)??"
- '(?? "a" nonl))
- (xr--expect "\\(?:.\\(a+\\(?:b+?c*\\)?\\)??\\)*"
- '(zero-or-more
- nonl
- (?? (group (one-or-more "a")
- (opt (+? "b")
- (zero-or-more "c"))))))
- (xr--expect "[[:alnum:][:blank:]][[:alpha:]][[:cntrl:][:digit:]]"
- '(seq (any alnum blank) alpha (any cntrl digit)))
- (xr--expect "[^[:lower:][:punct:]][^[:space:]]"
- '(seq (not (any lower punct)) (not space)))
- (xr--expect "^[a-z]*"
- '(seq bol (zero-or-more (any "a-z"))))
- (xr--expect "some[.]thing"
- "some.thing")
- (xr--expect "[^]-c]"
- '(not (any "]-c")))
- (xr--expect "[-^]"
- '(any "-" "^"))
- (xr--expect "[a-z-+/*%0-4[:xdigit:]]"
- '(any "a-z" "-" "+/*%" "0-4" xdigit))
- (xr--expect "[^]A-Za-z-]*"
- '(zero-or-more (not (any "]" "A-Za-z" "-"))))
- (xr--expect "[+*%A-Ka-k0-3${-}]"
- '(any "+*%" "A-Ka-k0-3" "$" "{-}"))
- (xr--expect ""
- "")
- (xr--expect "a\\|"
- '(or "a" ""))
- (xr--expect "\\|a"
- '(or "" "a"))
- (xr--expect "a\\|\\|b"
- '(or "a" "" "b"))
- (xr--expect "\\(?:.\\|\n\\)?\\(\n\\|.\\)*"
- '(seq (opt anything) (zero-or-more (group anything))))
- (xr--expect "\\*\\*\\* EOOH \\*\\*\\*\n"
- "*** EOOH ***\n")
- (xr--expect "\\<\\(catch\\|finally\\)\\>[^_]"
- '(seq bow (group (or "catch" "finally")) eow
- (not (any "_"))))
- (xr--expect "[ \t\n]*:\\([^:]+\\|$\\)"
- '(seq (zero-or-more (any " \t\n")) ":"
- (group (or (one-or-more (not (any ":")))
- eol))))
- (xr--expect "^a^b\\(?:^c^\\|^d^\\|e^\\)^"
- '(seq bol "a^b" (or (seq bol "c^") (seq bol "d^") "e^") "^"))
- (xr--expect "$a$b\\(?:$c$\\|$d$\\|$e$\\)$"
- '(seq "$a$b" (or (seq "$c" eol) (seq "$d" eol) (seq "$e" eol))
- eol))
- (xr--expect "*a\\|*b\\(*c\\)"
- '(or "*a" (seq "*b" (group "*c"))))
- (xr--expect "+a\\|+b\\(+c\\)"
- '(or "+a" (seq "+b" (group "+c"))))
- (xr--expect "?a\\|?b\\(?c\\)"
- '(or "?a" (seq "?b" (group "?c"))))
- (xr--expect "^**"
- '(seq bol (zero-or-more "*")))
- (xr--expect "^+"
- '(seq bol "+"))
- (xr--expect "^?"
- '(seq bol "?"))
- (xr--expect "*?a\\|^??b"
- '(or (seq (opt "*") "a") (seq bol (opt "?") "b")))
- (xr--expect "^\\{xy"
- '(seq bol "{xy"))
- (xr--expect "\\{2,3\\}"
- "{2,3}")
- (xr--expect "a\\(?:b?\\(?:c.\\)d*\\)e"
- '(seq "a" (opt "b") "c" nonl (zero-or-more "d") "e"))
- (xr--expect "a\\(?:b\\(?:c.d\\)e\\)f"
- '(seq "abc" nonl "def"))
- (xr--expect-pp "A\e\r\n\t\0 \x7f\x80\ B\xff\x02"
- "\"A\\e\\r\\n\\t\\x00 \\x7f\\200B\\xff\\x02\"\n")
- (xr--expect-pp '(?? nonl)
- "(?? nonl)\n")
- (xr--expect-pp '(repeat 1 63 "a")
- "(repeat 1 63 \"a\")\n")
- ))
-
;;; xr.el ends here
- [elpa] externals/xr c2ede95 08/13: Improved errors for bad \s and \c sequences, (continued)
- [elpa] externals/xr c2ede95 08/13: Improved errors for bad \s and \c sequences, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 8425772 01/13: Sync with ELPA: compilation workaround, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr f79d50c 12/13: Add categories L, R, . and SPC, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 2a1de75 03/13: Correct parsing of group and backref, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 8d052d6 09/13: Check for errors in \_, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 37b2bcb 06/13: Merge branch 'master' of https://github.com/mattiase/xr, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 41474cb 11/13: Accept unknown character categories, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr e1c7734 13/13: Merge branch 'externals/xr' of elpa.git (no actual change), Mattias Engdegård, 2019/02/13
- [elpa] externals/xr e8ec2d9 07/13: Add reference to the pcre2el package, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 4bf6043 05/13: Export xr-pp-rx-to-str and fix a typo, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 8532df8 02/13: Move tests to separate file,
Mattias Engdegård <=
- [elpa] externals/xr 0331e00 10/13: Recognise \sW as alias for \sw, Mattias Engdegård, 2019/02/13