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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 365d739 324/405: Changed structure of integra


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 365d739 324/405: Changed structure of integration tests
Date: Sat, 13 Jul 2019 10:00:41 -0400 (EDT)

branch: externals/phps-mode
commit 365d739857caa158ee93514c06e94924377e71d0
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Changed structure of integration tests
---
 phps-mode-test-integration.el | 61 ++++++++--------------------------------
 phps-mode-test.el             | 65 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 75 insertions(+), 51 deletions(-)

diff --git a/phps-mode-test-integration.el b/phps-mode-test-integration.el
index 999679b..2c80f8b 100644
--- a/phps-mode-test-integration.el
+++ b/phps-mode-test-integration.el
@@ -30,6 +30,7 @@
 
 
 (autoload 'phps-mode-test-with-buffer "phps-mode-test")
+(autoload 'phps-mode-test-incremental-vs-intial-buffer "phps-mode-test")
 (autoload 'phps-mode-functions-indent-line "phps-mode-functions")
 (autoload 'phps-mode-functions-get-lines-indent "phps-mode-functions")
 (autoload 'phps-mode-functions-get-imenu "phps-mode-functions")
@@ -42,71 +43,33 @@
 (defun phps-mode-test-integration-incremental ()
   "Test for object-oriented PHP file."
 
-    (phps-mode-test-with-buffer
+  (phps-mode-test-incremental-vs-intial-buffer
    "<?php\nnamespace myNamespace\n{\n    class myClass\n    {\n        public 
function myFunction()\n        {\n            echo 'my statement';\n        }\n 
   }\n}\n"
-   "Integration-test for regular PHP with namespaces, classes and functions"
+   "Integration-test 1 for regular PHP with namespaces, classes and functions"
 
-   ;; Tokens
-   ;; (message "Tokens %s" phps-mode-lexer-tokens)
-   (should (equal (phps-mode-lexer-get-tokens) '((T_OPEN_TAG 1 . 7) 
(T_NAMESPACE 7 . 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) 
(T_STRING 41 . 48) ("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) 
(T_STRING 79 . 89) ("(" 89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 
118) (T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) ("}" 143 . 144) 
("}" 149 . 150) ("}" 151 . 152))))
-
-   ;; Indentation
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (2 
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (1 0)) (11 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))
+   ;; Make changes
+   (goto-char 144)
+   (insert "\n\n        public function myFunctionB()\n        {\n            
echo 'my second statement';\n        }\n")
+   (should (equal (phps-mode-functions-get-buffer-changes-start) 144)))
 
-   ;; Imenu
-   (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17) 
("\\myNamespace\\myClass" . 41) ("\\myNamespace\\myClass->myFunction()" . 79))))
+  (phps-mode-test-incremental-vs-intial-buffer
+   "<?php\nnamespace myNamespace\n{\n    class myClass\n    {\n        public 
function myFunction()\n        {\n            echo 'my statement';\n        }\n 
   }\n}\n"
+   "Integration-test 2 for regular PHP with namespaces, classes and functions"
 
    ;; Make changes
    (goto-char 144)
    (insert "\n\n        public function myFunctionB()\n        {\n            
echo 'my second statement';\n        }\n")
-
-   ;; Verify stored point of change
    (should (equal (phps-mode-functions-get-buffer-changes-start) 144))
-
-   ;; Run incremental lexer
    (phps-mode-lexer-run-incremental)
 
-   ;; TODO Should maybe change this to a more more simpler way
-   ;; like compare lexer tokens, indent and imenu with same contents in a new 
buffer
-
-   ;; Tokens
-   ;; (message "Tokens %s" (phps-mode-lexer-get-tokens))
-   (should (equal (phps-mode-lexer-get-tokens) '((T_OPEN_TAG 1 . 7) 
(T_NAMESPACE 7 . 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) 
(T_STRING 41 . 48) ("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) 
(T_STRING 79 . 89) ("(" 89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 
118) (T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) (";" 133 . 134) 
("}" 143 . 144) (T_PUBLIC 154 . 160) (T_FUNCTION 161 . 169) (T_STRING 170 . 
181) ("(" 181 . 182) (")" 182 . 183) ("{" 192 . 19 [...]
-
-   ;; Indentation
-   ;; (message "indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (2 
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (2 0)) (11 (2 0)) (12 (2 0)) (13 (3 0)) 
(14 (2 0)) (15 (2 0)) (16 (1 0)) (17 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent))))
-
-   ;; Imenu
-   (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17) 
("\\myNamespace\\myClass" . 41) ("\\myNamespace\\myClass->myFunction()" . 79) 
("\\myNamespace\\myClass->myFunctionB()" . 170))))
-
    ;; Remove first function
    (goto-char 55)
    (push-mark nil t t)
    (goto-char 145)
    (execute-kbd-macro (kbd "<backspace>"))
+   (should (equal (phps-mode-functions-get-buffer-changes-start) 55)))
 
-   ;; Verify stored point of change
-   (should (equal (phps-mode-functions-get-buffer-changes-start) 55))
-
-   ;; Run incremental lexer
-   (phps-mode-lexer-run-incremental)
-
-   ;; Tokens
-   ;; (message "Tokens %s" (phps-mode-lexer-get-tokens))
-   (should (equal (phps-mode-lexer-get-tokens) '((T_OPEN_TAG 1 . 7) 
(T_NAMESPACE 7 . 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) 
(T_STRING 41 . 48) ("{" 53 . 54) ("{" 53 . 54) (T_PUBLIC 64 . 70) (T_FUNCTION 
71 . 79) (T_STRING 80 . 91) ("(" 91 . 92) (")" 92 . 93) ("{" 102 . 103) (T_ECHO 
116 . 120) (T_CONSTANT_ENCAPSED_STRING 121 . 142) (";" 142 . 143) ("}" 152 . 
153) ("}" 159 . 160) ("}" 161 . 162))))
-
-   ;; Imenu
-   (should (equal (phps-mode-functions-get-imenu) '(("\\myNamespace" . 17) 
("\\myNamespace\\myClass" . 41) ("\\myNamespace\\myClass->myFunctionB()" . 80) 
)))
-
-   ;; Indentation
-   (message "indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (2 
0)) (7 (2 0)) (8 (2 0)) (9 (3 0)) (10 (2 0)) (11 (2 0)) (12 (1 0)) (13 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))
-
-
-   )
-
-)
+  )
 
 (defun phps-mode-test-integration ()
   "Run test for integration."
diff --git a/phps-mode-test.el b/phps-mode-test.el
index 1fd37a9..c95027b 100644
--- a/phps-mode-test.el
+++ b/phps-mode-test.el
@@ -1,6 +1,6 @@
 ;;; phps-mode-test.el --- Commons for tests -*- lexical-binding: t -*-
 
-;; Copyright (C) 2018 Christian Johansson
+;; Copyright (C) 2018-2019 Christian Johansson
 
 ;; This file is not part of GNU Emacs.
 
@@ -27,6 +27,67 @@
 
 
 (autoload 'phps-mode "phps-mode")
+(autoload 'phps-mode-lexer-get-tokens "phps-mode-lexer")
+(autoload 'phps-mode-functions-get-imenu "phps-mode-functions")
+(autoload 'phps-mode-functions-get-lines-indent "phps-mode-functions")
+(autoload 'should "ert")
+
+(defmacro phps-mode-test-incremental-vs-intial-buffer (source &optional title 
&rest change)
+  "Set up test buffer with SOURCE, TITLE, apply CHANGE and compare incremental 
values with initial values."
+  `(let ((test-buffer-incremental (generate-new-buffer "test-incremental"))
+         (incremental-tokens nil)
+         (incremental-imenu nil)
+         (incremental-indent nil)
+         (incremental-buffer nil)
+         (test-buffer-initial (generate-new-buffer "test-initial"))
+         (initial-tokens nil)
+         (initial-imenu nil)
+         (initial-indent nil)
+         (initial-buffer nil))
+
+     ;; Setup incremental buffer
+     (switch-to-buffer test-buffer-incremental)
+     (insert ,source)
+     (goto-char 0)
+     (when (and (boundp 'phps-mode-functions-verbose)
+                phps-mode-functions-verbose)
+       (message "\nTesting incremental buffer '%s':\n'%s'\n" ,title ,source))
+     (phps-mode)
+     ,@change
+     (phps-mode-lexer-run-incremental)
+     (setq incremental-tokens (phps-mode-lexer-get-tokens))
+     (setq incremental-imenu (phps-mode-functions-get-imenu))
+     (setq incremental-indent (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
+     (setq incremental-buffer (buffer-substring-no-properties (point-min) 
(point-max)))
+     (kill-buffer test-buffer-incremental)
+
+     ;; Setup incremental buffer
+     (switch-to-buffer test-buffer-initial)
+     (insert incremental-buffer)
+     (goto-char 0)
+     (when (and (boundp 'phps-mode-functions-verbose)
+                phps-mode-functions-verbose)
+       (message "\nTesting initial buffer '%s':\n'%s'\n" ,title 
incremental-buffer))
+     (phps-mode)
+     (setq initial-tokens (phps-mode-lexer-get-tokens))
+     (setq initial-imenu (phps-mode-functions-get-imenu))
+     (setq initial-indent (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
+     (setq initial-buffer (buffer-substring-no-properties (point-min) 
(point-max)))
+     (kill-buffer test-buffer-initial)
+
+     ;; Run tests
+     (when (and (boundp 'phps-mode-functions-verbose)
+                phps-mode-functions-verbose)
+       (message "\nComparing tokens, lines indent and imenu between 
buffer:\n\n'%s'\n\nand:\n\n'%s'\n" initial-buffer incremental-buffer))
+     (should (equal initial-buffer incremental-buffer))
+     ;; (message "Initial tokens: %s\n" initial-tokens)
+     ;; (message "Incremental tokens: %s\n" incremental-tokens)
+     (should (equal initial-tokens incremental-tokens))
+     (should (equal initial-indent incremental-indent))
+     (should (equal initial-imenu incremental-imenu))
+
+     (when ,title
+       (message "\nPassed incremental tests for '%s'\n" ,title))))
 
 (defmacro phps-mode-test-with-buffer (source &optional title &rest body)
   "Set up test buffer with SOURCE, TITLE and BODY."
@@ -36,7 +97,7 @@
      (goto-char 0)
      (when (and (boundp 'phps-mode-functions-verbose)
                 phps-mode-functions-verbose)
-       (message "\nTesting buffer:\n'%s'\n" ,source))
+       (message "\nTesting buffer '%s':\n'%s'\n" ,title ,source))
      (phps-mode)
      ,@body
      (kill-buffer test-buffer)



reply via email to

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