emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]