[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-matchit 6fd4c56855 198/244: clean code, more c unit t
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-matchit 6fd4c56855 198/244: clean code, more c unit test |
Date: |
Thu, 6 Jan 2022 02:59:01 -0500 (EST) |
branch: elpa/evil-matchit
commit 6fd4c56855e14793fd0a4fd646f7add4372ab927
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
clean code, more c unit test
---
evil-matchit-c.el | 20 +++--
tests/evil-matchit-tests.el | 191 ++++++++++++++++++++++++--------------------
2 files changed, 117 insertions(+), 94 deletions(-)
diff --git a/evil-matchit-c.el b/evil-matchit-c.el
index 71dd697b62..6bd20124d1 100644
--- a/evil-matchit-c.el
+++ b/evil-matchit-c.el
@@ -40,13 +40,19 @@
;;;###autoload
(defun evilmi-c-get-tag ()
- (evilmi-sdk-get-tag evilmi-c-match-tags evilmi-c-extract-keyword-howtos))
+ "Get tag at point."
+ (evilmi-sdk-get-tag evilmi-c-match-tags
+ evilmi-c-extract-keyword-howtos))
;;;###autoload
-(defun evilmi-c-jump (rlt num)
+(defun evilmi-c-jump (info num)
+ "Use INFO to jump NUM times."
(let* ((old-pos (point))
- (pos (evilmi-sdk-jump rlt num evilmi-c-match-tags
evilmi-c-extract-keyword-howtos))
- (orig-tag (and rlt (nth 3 (cadr rlt)))))
+ (new-pos (evilmi-sdk-jump info
+ num
+ evilmi-c-match-tags
+ evilmi-c-extract-keyword-howtos))
+ (orig-tag (and info (nth 3 (cadr info)))))
;; Place cursor over last case of 'switch' statement and press %:
;; Should go back to beginning of switch:
@@ -58,11 +64,11 @@
;; }
(when (and (string= orig-tag "case")
;; failed to find matching tag
- (not pos))
+ (not new-pos))
(goto-char old-pos)
;; Goto outer bracket
(backward-up-list)
- (setq pos (beginning-of-line)))
- pos))
+ (setq new-pos (beginning-of-line)))
+ new-pos))
(provide 'evil-matchit-c)
diff --git a/tests/evil-matchit-tests.el b/tests/evil-matchit-tests.el
index 277f4df229..697f09a67b 100644
--- a/tests/evil-matchit-tests.el
+++ b/tests/evil-matchit-tests.el
@@ -69,96 +69,113 @@
(should (eq major-mode 'fundamental-mode)))))
(ert-deftest evilmi-test-javascript ()
- (let* ((str "function hello() {\n console.log('hello world');\n}"))
- (with-temp-buffer
- (insert str)
- (js-mode)
- ;; for javascript, jump from anywhere in function beginning
- (goto-char (+ 3 (point-min)))
- (evilmi-jump-items)
- (should (eq (following-char) ?}))
-
- ;; jump from start again
- (goto-char (point-min))
- (search-forward "{")
- (evilmi-jump-items)
- (should (eq (following-char) ?}))
- ;; jump back
- (evilmi-jump-items)
- (should (eq (following-char) ?{))
-
- ;; jump between ends of string can't be tested.
- ;; because font face is not useable in batch mode
-
- (should (eq major-mode 'js-mode)))))
+ (with-temp-buffer
+ (insert "function hello() {\n console.log('hello world');\n}")
+ (js-mode)
+ ;; for javascript, jump from anywhere in function beginning
+ (goto-char (+ 3 (point-min)))
+ (evilmi-jump-items)
+ (should (eq (following-char) ?}))
+
+ ;; jump from start again
+ (goto-char (point-min))
+ (search-forward "{")
+ (evilmi-jump-items)
+ (should (eq (following-char) ?}))
+ ;; jump back
+ (evilmi-jump-items)
+ (should (eq (following-char) ?{))
+
+ ;; jump between ends of string can't be tested.
+ ;; because font face is not useable in batch mode
+
+ (should (eq major-mode 'js-mode))))
(ert-deftest evilmi-test-html ()
- (let* ((str "<html lang=\"en\">\n<head>\n<link rel=\"icon\"
href=\"%PUBLIC_URL%/favicon.ico\" />\n</head>\n<body>\n<p>Hello
world!</p>\n</body>\n</html>"))
- (with-temp-buffer
- (insert str)
- (html-mode)
-
- ;; jump from start again
- (goto-char (point-min))
- (search-forward "<head")
- ;; Please note it jumps to line feed
- (evilmi-jump-items)
- (goto-char (1- (point)))
- (should (eq (following-char) ?>))
- (should (string= (thing-at-point 'symbol) "/head"))
-
- ;; self closing tag
- (goto-char (point-min))
- (search-forward "<link")
- (evilmi-jump-items)
- (goto-char (1- (point)))
- (should (eq (following-char) ?>))
- (should (string= (thing-at-point 'symbol) "/"))
- (evilmi-jump-items)
- (should (eq (following-char) ?<))
- (forward-char)
- (should (string= (thing-at-point 'word) "link"))
-
- ;; tags in one line
- (goto-char (point-min))
- (search-forward "<p")
- (evilmi-jump-items)
- (goto-char (1- (point)))
- (should (eq (following-char) ?>))
- (should (string= (thing-at-point 'symbol) "/p"))
-
- (should (eq major-mode 'html-mode)))))
+ (with-temp-buffer
+ (insert "<html lang=\"en\">\n<head>\n<link rel=\"icon\"
href=\"%PUBLIC_URL%/favicon.ico\" />\n</head>\n<body>\n<p>Hello
world!</p>\n</body>\n</html>")
+ (html-mode)
+
+ ;; jump from start again
+ (goto-char (point-min))
+ (search-forward "<head")
+ ;; Please note it jumps to line feed
+ (evilmi-jump-items)
+ (goto-char (1- (point)))
+ (should (eq (following-char) ?>))
+ (should (string= (thing-at-point 'symbol) "/head"))
+
+ ;; self closing tag
+ (goto-char (point-min))
+ (search-forward "<link")
+ (evilmi-jump-items)
+ (goto-char (1- (point)))
+ (should (eq (following-char) ?>))
+ (should (string= (thing-at-point 'symbol) "/"))
+ (evilmi-jump-items)
+ (should (eq (following-char) ?<))
+ (forward-char)
+ (should (string= (thing-at-point 'word) "link"))
+
+ ;; tags in one line
+ (goto-char (point-min))
+ (search-forward "<p")
+ (evilmi-jump-items)
+ (goto-char (1- (point)))
+ (should (eq (following-char) ?>))
+ (should (string= (thing-at-point 'symbol) "/p"))
+
+ (should (eq major-mode 'html-mode))))
(ert-deftest evilmi-test-c ()
- (let* ((str "#ifdef CONFIG_COMPAT\n#ifndef TEST1\nstruct mtip_s {\n int
v1;\n}\n#endif\n#endif\nstatic int fn1()\n{\nprintf(\"hello world\");\n}\nint a
= 3;"))
- (with-temp-buffer
- (insert str)
- (c-mode)
-
- ;; jump from start
- (goto-char (point-min))
- ;; test #ifdef
- (evilmi-jump-items)
- (should (string= "endif" (thing-at-point 'symbol)))
- ;; test #ifndef
- (forward-line -1)
- (evilmi-jump-items)
- (should (eq (point) (line-beginning-position)))
- (should (eq (following-char) ?#))
- (forward-char)
- (should (string= "ifndef" (thing-at-point 'symbol)))
-
- ;; jump from function begin to end
- (goto-char (point-min))
- (search-forward "static int");
- (evilmi-jump-items)
- (should (eq (following-char) ?}))
- (should (string= (evilmi-sdk-curline) "}"))
- ;; jump back
- (evilmi-jump-items)
- (should (eq (following-char) ?{))
- (should (string= (evilmi-sdk-curline) "{"))
-
- (should (eq major-mode 'c-mode)))))
+ (with-temp-buffer
+ (insert "#ifdef CONFIG_COMPAT\n#ifndef TEST1\nstruct mtip_s {\n int
v1;\n}\n#endif\n#endif\n"
+ "static int fn1()\n{\nprintf(\"hello world\");\n}\nint a = 3;\n"
+ "switch(c) {\ncase 'a':\nbreak;\ncase 'b':\nbreak;\n}\n")
+ (c-mode)
+
+ ;; jump from start
+ (goto-char (point-min))
+ ;; test #ifdef
+ (evilmi-jump-items)
+ (should (string= "endif" (thing-at-point 'symbol)))
+ ;; test #ifndef
+ (forward-line -1)
+ (evilmi-jump-items)
+ (should (eq (point) (line-beginning-position)))
+ (should (eq (following-char) ?#))
+ (forward-char)
+ (should (string= "ifndef" (thing-at-point 'symbol)))
+
+ ;; jump from function begin to end
+ (goto-char (point-min))
+ (search-forward "static int");
+ (evilmi-jump-items)
+ (should (eq (following-char) ?}))
+ (should (string= (evilmi-sdk-curline) "}"))
+ ;; jump back
+ (evilmi-jump-items)
+ (should (eq (following-char) ?{))
+ (should (string= (evilmi-sdk-curline) "{"))
+
+ ;; jump in switch statement
+ (goto-char (point-min))
+ (search-forward "switch");
+ (evilmi-jump-items)
+ (should (eq (following-char) ?c))
+ (should (string= (thing-at-point 'symbol) "case"))
+ (should (string-match "case 'a'" (evilmi-sdk-curline)))
+ ;; goto next case statement
+ (evilmi-jump-items)
+ (should (eq (following-char) ?c))
+ (should (string= (thing-at-point 'symbol) "case"))
+ (should (string-match "case 'b'" (evilmi-sdk-curline) ))
+ ; jump back
+ (evilmi-jump-items)
+ (should (eq (following-char) ?{))
+ (message "(point)=%s" (point))
+ (should (string-match "switch(c)" (evilmi-sdk-curline) ))
+
+ (should (eq major-mode 'c-mode))))
(ert-run-tests-batch-and-exit)
;;; evil-matchit-tests.el ends here
- [nongnu] elpa/evil-matchit 9b228b097a 242/244: easier to add own rules, (continued)
- [nongnu] elpa/evil-matchit 9b228b097a 242/244: easier to add own rules, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 3417dbb275 117/244: Add ocaml support, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 80413a836a 121/244: Merge pull request #79 from msaffer/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 47894a6cc0 151/244: Merge pull request #93 from AitBits/patch-2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 4c6b8f412f 159/244: Add autoload definitions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 1c428e192b 149/244: ocaml use font-lock-doc-face for comment, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 0845b2a0bf 178/244: Merge pull request #109 from neojski/add-double-semicolon, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 11aa990ecb 177/244: Merge pull request #110 from leungbk/elisp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 11d98debf8 187/244: Merge pull request #115 from dajva/jump_motion, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit bc31e7d594 199/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 6fd4c56855 198/244: clean code, more c unit test,
ELPA Syncer <=
- [nongnu] elpa/evil-matchit 24dcd74a55 205/244: support terminal in Emacs, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ede6382955 206/244: enhance verilog mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 721d0a9c56 211/244: More ocaml tests, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit fccad4255b 217/244: Merge pull request #128 from leungbk/byte-comp, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 593c2d53a7 224/244: `evilmi-sdk-simple-jump': skip comments, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit f397504270 204/244: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit 2df3a62a8b 222/244: Add a regression test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d7ad7f712b 235/244: emacs 28 changed API define-obsolete-function-alias. It is EVIL code. Not my code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit d1f59ad941 225/244: Merge pull request #131 from nbfalcon/bugfix/evilmi-sdk-simple-jump-whitespace, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-matchit ccc2cc8a62 221/244: `evilmi-sdk-simple-jump': skip whitespace, ELPA Syncer, 2022/01/06