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

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

[elpa] externals/phps-mode 4a27c44 147/405: Added support for naming uni


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 4a27c44 147/405: Added support for naming unit tests to better find failures
Date: Sat, 13 Jul 2019 10:00:02 -0400 (EDT)

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

    Added support for naming unit tests to better find failures
---
 phps-mode-test-functions.el | 48 +++++++++++++++++++++++++++++++++------------
 phps-mode-test-lexer.el     | 40 ++++++++++++++++++++++++++++++++++++-
 phps-mode-test.el           |  8 ++++----
 3 files changed, 79 insertions(+), 17 deletions(-)

diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 680d1b1..d560ab8 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -48,28 +48,24 @@
 (defun phps-mode-test-functions-get-lines-indent ()
   "Test `phps-mode-functions-get-lines-indent' function."
 
-  ;; Mixed HTML/PHP
-
   (phps-mode-test-with-buffer
    "<html><head><title><?php\nif ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n}\n} ?></title><body>Bla bla</body></html>"
+   "Mixed HTML/PHP"
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0 
0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
-  ;; Inline control structures
+  (phps-mode-test-with-buffer
+   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\nendif;\necho true;\n"
+   "Alternative control structures"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0)) (7 (0 0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
   (phps-mode-test-with-buffer
    "<?php\nif (true)\n    echo 'Something';\nelse\n    echo 'Something 
else';\necho true;\n"
+   "Inline control structures"
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
1))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
-  ;; Alternative control structures
-
-  (phps-mode-test-with-buffer
-   "<?php\nif (true):\n    echo 'Something';\nelse:\n    echo 'Something 
else';\nendif;\necho true;\n"
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
-
-  ;; DOC-COMMENT
-
   (phps-mode-test-with-buffer
    "<?php\n/**\n* Bla\n*/"
+   "DOC-COMMENT"
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 1))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
   ;; TODO CASE, DEFAULT
@@ -78,7 +74,6 @@
 
   ;; TODO Multi-line assignments
 
-
   )
 
 ;; TODO Add unit tests for HEREDOC and NOWDOC regions as well
@@ -89,6 +84,7 @@
   ;; Curly bracket tests
   (phps-mode-test-with-buffer
    "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
+   nil
    (goto-char 69)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -103,6 +99,7 @@
 
   (phps-mode-test-with-buffer
    "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title2;\n\n} ?></title><body>Bla bla</body></html>"
+   nil
    (goto-char 98)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -117,6 +114,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\n$variable = array(\n'random3'\n);\n$variable = true;\n"
+   nil
    (goto-char 28)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -132,6 +130,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\n/**\n* My first line\n* My second line\n**/\n"
+   nil
    (goto-char 20)
    (phps-mode-functions-indent-line)
    ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
@@ -148,6 +147,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\n/**\n* My first line\n* My second line\n**/\n"
+   nil
    (goto-char 46)
    (phps-mode-functions-indent-line)
    ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
@@ -164,6 +164,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nadd_filter(\n\"views_{$screen->id}\",'__return_empty_array'\n);"
+   nil
    (goto-char 25)
    (phps-mode-functions-indent-line)
    ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
@@ -180,6 +181,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif (empty(\n$this->var\n) && !empty($this->var)\n) {\n$this->var = 
'abc123';\n}\n"
+   nil
    (goto-char 54)
    (phps-mode-functions-indent-line)
    ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
@@ -196,6 +198,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif (myFirstCondition()) {\n    $this->var = 'abc123';\n    } else 
if (mySeconCondition()) {\n    $this->var = 'def456';\n}\n"
+   nil
    (goto-char 68)
    (phps-mode-functions-indent-line)
    ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
@@ -212,6 +215,7 @@
   
   (phps-mode-test-with-buffer
    "<?php\nif (myRandomCondition()):\necho 'Something here';\n    else:\n    
echo 'Something else here 8';\nendif;\n"
+   nil
    (goto-char 62)
    (phps-mode-functions-indent-line)
    ;; (message "Tokens %s" phps-mode-lexer-tokens)
@@ -229,6 +233,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nswitch (myRandomCondition()) {\ncase 'Something here':\necho 
'Something else here';\n}\n"
+   nil
    (goto-char 65)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -243,6 +248,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif (myRandomCondition())\n    echo 'Something here';\n    echo 
'Something else here';\n"
+   nil
    (goto-char 60)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -257,6 +263,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nmyFunction(\n    array(\n        'random' => 'abc',\n        ),\n   
 $var5\n);\n"
+   nil
    (goto-char 65)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -271,6 +278,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\n$var =\n'random string';\n"
+   nil
    (goto-char 20)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -285,6 +293,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif (empty($this->var)):\n$this->var = 'abc123';\n    endif;"
+   nil
    (goto-char 30)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
@@ -303,6 +312,7 @@
 
   (phps-mode-test-with-buffer
    "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
+   nil
    (goto-char 15)
    (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 5 
nil)) (phps-mode-functions-get-current-line-data))))
 
@@ -313,6 +323,7 @@
 
   (phps-mode-test-with-buffer
    "<html><head><title></title><body>Bla bla</body></html>"
+   nil
    (goto-char 15)
    (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 nil 
nil)) (phps-mode-functions-get-current-line-data))))
 
@@ -323,6 +334,7 @@
 
   (phps-mode-test-with-buffer
    "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
+   nil
    (goto-char 50)
    (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 5 
nil)) (phps-mode-functions-get-current-line-data))))
 
@@ -333,6 +345,7 @@
 
   (phps-mode-test-with-buffer
    "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) {\n 
echo $title;\n} } ?></title><body>Bla bla</body></html>"
+   nil
    (goto-char 72)
    (should (equal (list (list t 2 0 0 0 0 10 nil) (list t 2 0 0 0 0 13 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -343,6 +356,7 @@
 
   (phps-mode-test-with-buffer
    "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) { echo 
$title; } } ?></title><body>Bla bla</body></html>"
+   nil
    (goto-char 100)
    (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 17 
nil)) (phps-mode-functions-get-current-line-data))))
 
@@ -353,6 +367,7 @@
 
   (phps-mode-test-with-buffer
    "<?php /**\n * My first line\n * My second line\n **/"
+   nil
    (goto-char 9)
    (should (equal (list (list nil 0 0 0 0 0 nil nil) (list t 0 0 0 0 0 1 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -363,6 +378,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\n$variable = array(\n'random4');\n$variable = true;\n"
+   nil
    (goto-char 29)
    (should (equal (list (list t 0 1 0 0 0 4 nil) (list t 0 0 0 0 0 7 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -373,6 +389,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\n$var = [\n    'random' => [\n        'hello',\n    ],\n];\n"
+   nil
    (goto-char 46)
    (should (equal (list (list t 0 0 2 0 0 6 nil) (list t 0 0 2 0 0 8 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -385,6 +402,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif ($myCondition)\n    echo 'was here';\necho 'was here 2';\n"
+   nil
    (goto-char 60)
    (should (equal (list (list t 0 0 0 0 0 7 nil) (list t 0 0 0 0 0 10 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -395,6 +413,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif ($myCondition) echo 'was here'; echo 'was here 2';\n"
+   nil
    (goto-char 55)
    (should (equal (list (list t 0 0 0 0 0 0 nil) (list t 0 0 0 0 0 10 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -405,6 +424,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif ($myCondition)\n    echo 'was here';\nelse\n    echo 'was here 
2';\n"
+   nil
    (goto-char 57)
    (should (equal (list (list t 0 0 0 1 0 8 nil) (list t 0 0 0 0 0 11 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -417,6 +437,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif ($myCondition):\n    echo 'was here';\nendif;\necho 'was here 
2';\n"
+   nil
    (goto-char 41)
    (should (equal (list (list t 0 0 0 0 1 5 nil) (list t 0 0 0 0 1 8 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -427,6 +448,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif ($myCondition):    echo 'was here';\nendif;\necho 'was here 
4';\n"
+   nil
    (goto-char 32)
    (should (equal (list (list t 0 0 0 0 0 0 nil) (list t 0 0 0 0 1 8 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -437,6 +459,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif ($myCondition):\n    echo 'was here';\nelse:\n    echo 'was here 
2';\nendif;\n"
+   nil
    (goto-char 44)
    (should (equal (list (list t 0 0 0 0 1 5 nil) (list t 0 0 0 0 1 8 nil)) 
(phps-mode-functions-get-current-line-data))))
 
@@ -447,6 +470,7 @@
 
   (phps-mode-test-with-buffer
    "<?php\nif ($myCondition):\n    echo 'was here';\nelse:\n    echo 'was here 
2';\nendif;\n"
+   nil
    (goto-char 79)
    (should (equal (list (list t 0 0 0 0 0 10 nil) (list t 0 0 0 0 0 15 nil)) 
(phps-mode-functions-get-current-line-data))))
 
diff --git a/phps-mode-test-lexer.el b/phps-mode-test-lexer.el
index 10f870c..e1d9497 100644
--- a/phps-mode-test-lexer.el
+++ b/phps-mode-test-lexer.el
@@ -40,26 +40,31 @@
 
   (phps-mode-test-with-buffer
    "<?php\t$var=1; exit $var;\t?>"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) ("=" 11 . 12) 
(T_LNUMBER 12 . 13) (";" 13 . 14) (T_EXIT 15 . 19) (T_VARIABLE 20 . 24) (";" 24 
. 25) (";" 26 . 28) (T_CLOSE_TAG 26 . 28)))))
 
   (phps-mode-test-with-buffer
    "<?php\nexit;\n?>"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_EXIT 7 . 11) (";" 11 . 12) (";" 13 . 
15) (T_CLOSE_TAG 13 . 15)))))
 
   (phps-mode-test-with-buffer
    "<?php exit; ?>"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_EXIT 7 . 11) (";" 11 . 12) (";" 13 . 
15) (T_CLOSE_TAG 13 . 15)))))
 
   (phps-mode-test-with-buffer
    "<html><head>blabla</head<body>\n\n \t<?php\nexit;\n?>\n\n</body></html>"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 35 . 41) (T_EXIT 41 . 45) (";" 45 . 46) (";" 
47 . 50) (T_CLOSE_TAG 47 . 50)))))
 
   (phps-mode-test-with-buffer
    "\n\n \t<html><title>echo 
\"Blaha\";</title><?php\n\n\nexit?>\n\n<html><random /></html><?php exit ?>"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 39 . 45) (T_EXIT 47 . 51) (";" 51 . 54) 
(T_CLOSE_TAG 51 . 54) (T_OPEN_TAG 78 . 84) (T_EXIT 84 . 88) (";" 89 . 91) 
(T_CLOSE_TAG 89 . 91)))))
 
@@ -70,74 +75,88 @@
 
   (phps-mode-test-with-buffer
    "<?php echo $var = array('');"
+   nil
      (should (equal phps-mode-lexer-tokens
                     '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_VARIABLE 12 . 16) 
("=" 17 . 18) (T_ARRAY 19 . 24) ("(" 24 . 25) (T_CONSTANT_ENCAPSED_STRING 25 . 
27) (")" 27 . 28) (";" 28 . 29)))))
 
   (phps-mode-test-with-buffer
    "<?php if 
(empty($parameters[self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME])) { 
$parameters[self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME] = ''; }"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_IF 7 . 9) ("(" 10 . 11) (T_EMPTY 11 
. 16) ("(" 16 . 17) (T_VARIABLE 17 . 28) ("[" 28 . 29) (T_STRING 29 . 33) 
(T_PAAMAYIM_NEKUDOTAYIM 33 . 35) (T_STRING 35 . 76) ("]" 76 . 77) (")" 77 . 78) 
(")" 78 . 79) ("{" 80 . 81) (T_VARIABLE 82 . 93) ("[" 93 . 94) (T_STRING 94 . 
98) (T_PAAMAYIM_NEKUDOTAYIM 98 . 100) (T_STRING 100 . 141) ("]" 141 . 142) ("=" 
143 . 144) (T_CONSTANT_ENCAPSED_STRING 145 . 147) (";" 147 . 148) ("}" 149 . 
150)))))
 
   (phps-mode-test-with-buffer
    "<?php echo $var = array(\"\");"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_VARIABLE 12 . 16) 
("=" 17 . 18) (T_ARRAY 19 . 24) ("(" 24 . 25) (T_CONSTANT_ENCAPSED_STRING 25 . 
27) (")" 27 . 28) (";" 28 . 29)))))
 
   (phps-mode-test-with-buffer
    "<?php echo $var = array('abc' => '123');"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_VARIABLE 12 . 16) 
("=" 17 . 18) (T_ARRAY 19 . 24) ("(" 24 . 25) (T_CONSTANT_ENCAPSED_STRING 25 . 
30) (T_DOUBLE_ARROW 31 . 33) (T_CONSTANT_ENCAPSED_STRING 34 . 39) (")" 39 . 40) 
(";" 40 . 41)))))
 
   (phps-mode-test-with-buffer
    "<?php $var = []; "
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) ("=" 12 . 13) ("[" 
14 . 15) ("]" 15 . 16) (";" 16 . 17)))))
 
   (phps-mode-test-with-buffer
    "<?php $var = ''; $var = 'abc'; "
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) ("=" 12 . 13) 
(T_CONSTANT_ENCAPSED_STRING 14 . 16) (";" 16 . 17) (T_VARIABLE 18 . 22) ("=" 23 
. 24) (T_CONSTANT_ENCAPSED_STRING 25 . 30) (";" 30 . 31)))))
 
   (phps-mode-test-with-buffer
    "<?php\nswitch (myRandomCondition()) {\ncase 'Something here':\necho 
'Something else here';\n}\n"
+   nil
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_SWITCH 7 . 13) ("(" 14 . 15) 
(T_STRING 15 . 32) ("(" 32 . 33) (")" 33 . 34) (")" 34 . 35) ("{" 36 . 37) 
(T_CASE 38 . 42) (T_CONSTANT_ENCAPSED_STRING 43 . 59) (":" 59 . 60) (T_ECHO 61 
. 65) (T_CONSTANT_ENCAPSED_STRING 66 . 87) (";" 87 . 88) ("}" 89 . 90)))))
 
   (phps-mode-test-with-buffer
    "<?php $var = \"\"; $var = \"abc\"; $var = \"abc\\def\\ghj\";"
+   nil
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) ("=" 12 . 13) 
(T_CONSTANT_ENCAPSED_STRING 14 . 16) (";" 16 . 17) (T_VARIABLE 18 . 22) ("=" 23 
. 24) (T_CONSTANT_ENCAPSED_STRING 25 . 30) (";" 30 . 31) (T_VARIABLE 32 . 36) 
("=" 37 . 38) (T_CONSTANT_ENCAPSED_STRING 39 . 52) (";" 52 . 53)))))
 
   (phps-mode-test-with-buffer
    "<?php echo isset($backtrace[1]['file']) ? 'yes' : 'no'; "
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_ISSET 12 . 17) ("(" 
17 . 18) (T_VARIABLE 18 . 28) ("[" 28 . 29) (T_LNUMBER 29 . 30) ("]" 30 . 31) 
("[" 31 . 32) (T_CONSTANT_ENCAPSED_STRING 32 . 38) ("]" 38 . 39) (")" 39 . 40) 
("?" 41 . 42) (T_CONSTANT_ENCAPSED_STRING 43 . 48) (":" 49 . 50) 
(T_CONSTANT_ENCAPSED_STRING 51 . 55) (";" 55 . 56)))))
 
   (phps-mode-test-with-buffer
    "<?php myFunction(); "
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_STRING 7 . 17) ("(" 17 . 18) (")" 18 
. 19) (";" 19 . 20)))))
 
   (phps-mode-test-with-buffer
    "<?php // echo 'random';?><!--</div>-->"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_COMMENT 7 . 24) (";" 24 . 26) 
(T_CLOSE_TAG 24 . 26)))))
 
   (phps-mode-test-with-buffer
    "<?php //echo $contact_position;?><!--</div>-->"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_COMMENT 7 . 32) (";" 32 . 34) 
(T_CLOSE_TAG 32 . 34)))))
 
 
   (phps-mode-test-with-buffer
    "<?php echo isset($backtrace[1]['file']) ? 'yes' : 'no';\n//a random 
comment\n// another random comment\n/**\n * More comments\n* More\n **/\necho 
$backtrace; ?>"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_ISSET 12 . 17) ("(" 
17 . 18) (T_VARIABLE 18 . 28) ("[" 28 . 29) (T_LNUMBER 29 . 30) ("]" 30 . 31) 
("[" 31 . 32) (T_CONSTANT_ENCAPSED_STRING 32 . 38) ("]" 38 . 39) (")" 39 . 40) 
("?" 41 . 42) (T_CONSTANT_ENCAPSED_STRING 43 . 48) (":" 49 . 50) 
(T_CONSTANT_ENCAPSED_STRING 51 . 55) (";" 55 . 56) (T_COMMENT 57 . 75) 
(T_COMMENT 76 . 101) (T_DOC_COMMENT 102 . 134) (T_ECHO 135 . 139) (T_VARIABLE 
140 . 150) (";" 150 . 151) (";" 152 . 154)  [...]
 
   (phps-mode-test-with-buffer
    "<?php $var EXIT die function return yield from yield try catch finally 
throw if elseif endif else while endwhile do for endfor foreach endforeach 
declare enddeclare instanceof as switch endswitch case default break continue 
goto echo print class interface trait extends implements :: \\ ... ?? new clone 
var (int) (integer) (real) (double) (float) (string) (binary) (array) (object) 
(boolean) (bool) (unset) eval include include_once require require_once 
namespace use insteadof global is [...]
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) (T_EXIT 12 . 16) 
(T_DIE 17 . 20) (T_FUNCTION 21 . 29) (T_RETURN 30 . 36) (T_YIELD_FROM 37 . 48) 
(T_YIELD 48 . 53) (T_TRY 54 . 57) (T_CATCH 58 . 63) (T_FINALLY 64 . 71) 
(T_THROW 72 . 77) (T_IF 78 . 80) (T_ELSEIF 81 . 87) (T_ENDIF 88 . 93) (T_ELSE 
94 . 98) (T_WHILE 99 . 104) (T_ENDWHILE 105 . 113) (T_DO 114 . 116) (T_FOR 117 
. 120) (T_ENDFOR 121 . 127) (T_FOREACH 128 . 135) (T_ENDFOREACH 136 . 146) 
(T_DECLARE 147 . 154) (T_ENDDECLA [...]
 
@@ -148,82 +167,97 @@
 
   (phps-mode-test-with-buffer
    "<?php $var->property;"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) (T_OBJECT_OPERATOR 
11 . 13) (T_STRING 13 . 21) (";" 21 . 22)))))
 
   ;; Double quoted strings with variables
   (phps-mode-test-with-buffer
    "<?php echo \"My $variable is here\"; echo \"you know\";"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) ("\"" 12 . 13) 
(T_ENCAPSED_AND_WHITESPACE 13 . 16) (T_VARIABLE 16 . 25) 
(T_CONSTANT_ENCAPSED_STRING 25 . 33) ("\"" 33 . 34) (";" 34 . 35) (T_ECHO 36 . 
40) (T_CONSTANT_ENCAPSED_STRING 41 . 51) (";" 51 . 52)))))
 
   (phps-mode-test-with-buffer
    "<?php echo \"My ${variable} is here 1\";"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) ("\"" 12 . 13) 
(T_ENCAPSED_AND_WHITESPACE 13 . 16) (T_DOLLAR_OPEN_CURLY_BRACES 16 . 18) 
(T_STRING_VARNAME 18 . 26) ("}" 26 . 27) (T_CONSTANT_ENCAPSED_STRING 27 . 37) 
("\"" 37 . 38) (";" 38 . 39)))))
 
   (phps-mode-test-with-buffer
    "<?php echo \"Mine {$first_variable} is here and my $second is there.\";"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) ("\"" 12 . 13) 
(T_ENCAPSED_AND_WHITESPACE 13 . 18) (T_CURLY_OPEN 18 . 19) (T_VARIABLE 19 . 34) 
("}" 34 . 35) (T_CONSTANT_ENCAPSED_STRING 35 . 51) (T_VARIABLE 51 . 58) 
(T_CONSTANT_ENCAPSED_STRING 58 . 68) ("\"" 68 . 69) (";" 69 . 70)))))
 
   (phps-mode-test-with-buffer
    "<?php echo \" Hello $variable[0], how are you?\";"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) ("\"" 12 . 13) 
(T_ENCAPSED_AND_WHITESPACE 13 . 20) (T_VARIABLE 20 . 30) (T_NUM_STRING 30 . 31) 
("]" 31 . 32) (T_CONSTANT_ENCAPSED_STRING 32 . 46) ("\"" 46 . 47) (";" 47 . 
48)))))
 
   ;; Heredoc
   (phps-mode-test-with-buffer
    "<?php echo <<<\"MYLABEL\"\nline 1\n line 2\nMYLABEL\n;"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_START_HEREDOC 12 . 
25) (T_ENCAPSED_AND_WHITESPACE 25 . 39) (T_END_HEREDOC 39 . 47) (";" 48 . 
49)))))
 
   (phps-mode-test-with-buffer
    "<?php echo <<<MYLABEL\nline 1\n line 2\nMYLABEL\n;"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_START_HEREDOC 12 . 
23) (T_ENCAPSED_AND_WHITESPACE 23 . 37) (T_END_HEREDOC 37 . 45) (";" 46 . 
47)))))
 
   (phps-mode-test-with-buffer
    "<?php echo <<<\"MYLABEL\"\nMYLABEL\n"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_START_HEREDOC 12 . 
25) (T_END_HEREDOC 25 . 33)))))
 
   ;; Test heredoc with variables $, {$, ${ here
   (phps-mode-test-with-buffer
    "<?php echo <<<\"MYLABEL\"\nline 1 $variable1\n line 2\n${variable2} line 
3\n line {$variable3} here\nline 5 $variable[3] here\nMYLABEL;\n"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_START_HEREDOC 12 . 
25) (T_ENCAPSED_AND_WHITESPACE 25 . 32) (T_VARIABLE 32 . 42) 
(T_ENCAPSED_AND_WHITESPACE 42 . 51) (T_DOLLAR_OPEN_CURLY_BRACES 51 . 53) 
(T_STRING_VARNAME 53 . 62) ("}" 62 . 63) (T_ENCAPSED_AND_WHITESPACE 63 . 77) 
(T_CURLY_OPEN 77 . 78) (T_VARIABLE 78 . 88) ("}" 88 . 89) 
(T_ENCAPSED_AND_WHITESPACE 89 . 102) (T_VARIABLE 102 . 112) (T_NUM_STRING 112 . 
113) ("]" 113 . 114) (T_ENCAPSED_AND_WHITESPACE 114 . 119) (T_END_ [...]
 
   ;; Nowdoc
   (phps-mode-test-with-buffer
    "<?php echo <<<'MYLABEL'\nline 1\n line 2\nMYLABEL;\n"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_START_HEREDOC 12 . 
25) (T_ENCAPSED_AND_WHITESPACE 25 . 39) (T_END_HEREDOC 39 . 47) (";" 47 . 
48)))))
 
   ;; Backquotes
   (phps-mode-test-with-buffer
    "<?php `echo \"HELLO\"`;"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) ("`" 7 . 8) (T_CONSTANT_ENCAPSED_STRING 
8 . 20) ("`" 20 . 21) (";" 21 . 22)))))
 
   (phps-mode-test-with-buffer
    "<?php `echo \"HELLO $variable or {$variable2} or ${variable3} or 
$variable[index][0] here\"`;"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) ("`" 7 . 8) (T_CONSTANT_ENCAPSED_STRING 
8 . 20) (T_VARIABLE 20 . 29) (T_CONSTANT_ENCAPSED_STRING 29 . 33) (T_CURLY_OPEN 
33 . 34) (T_VARIABLE 34 . 44) ("}" 44 . 45) (T_CONSTANT_ENCAPSED_STRING 45 . 
49) (T_DOLLAR_OPEN_CURLY_BRACES 49 . 51) (T_STRING_VARNAME 51 . 60) ("}" 60 . 
61) (T_CONSTANT_ENCAPSED_STRING 61 . 65) (T_VARIABLE 65 . 75) (T_STRING 75 . 
80) ("]" 80 . 81) (T_CONSTANT_ENCAPSED_STRING 81 . 90) ("`" 90 . 91) (";" 91 . 
92)))))
 
   (phps-mode-test-with-buffer
    "<?php $wpdb->posts; ?>"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 12) (T_OBJECT_OPERATOR 
12 . 14) (T_STRING 14 . 19) (";" 19 . 20) (";" 21 . 23) (T_CLOSE_TAG 21 . 
23)))))
 
   (phps-mode-test-with-buffer
    "<?php $var = \"SELECT post_parent FROM $wpdb->posts WHERE ID = 
'\".$id.\"'\"; ?>"
+   nil
    ;; (message "Tokens 1: %s" phps-mode-lexer-tokens)
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 11) ("=" 12 . 13) ("\"" 
14 . 15) (T_ENCAPSED_AND_WHITESPACE 15 . 39) (T_VARIABLE 39 . 44) 
(T_OBJECT_OPERATOR 44 . 46) (T_STRING 46 . 51) (T_CONSTANT_ENCAPSED_STRING 51 . 
64) ("\"" 64 . 65) ("." 65 . 66) (T_VARIABLE 66 . 69) ("." 69 . 70) 
(T_CONSTANT_ENCAPSED_STRING 70 . 73) (";" 73 . 74) (";" 75 . 77) (T_CLOSE_TAG 
75 . 77)))))
 
   (phps-mode-test-with-buffer
    "<?php $wpdb->get_var(\"SELECT post_parent FROM $wpdb->posts WHERE ID = 
'\".$id.\"'\"); ?>"
+   nil
    ;; (message "Tokens 2: %s" phps-mode-lexer-tokens)
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 12) (T_OBJECT_OPERATOR 
12 . 14) (T_STRING 14 . 21) ("(" 21 . 22) ("\"" 22 . 23) 
(T_ENCAPSED_AND_WHITESPACE 23 . 47) (T_VARIABLE 47 . 52) (T_OBJECT_OPERATOR 52 
. 54) (T_STRING 54 . 59) (T_CONSTANT_ENCAPSED_STRING 59 . 72) ("\"" 72 . 73) 
("." 73 . 74) (T_VARIABLE 74 . 77) ("." 77 . 78) (T_CONSTANT_ENCAPSED_STRING 78 
. 81) (")" 81 . 82) (";" 82 . 83) (";" 84 . 86) (T_CLOSE_TAG 84 . 86)))))
@@ -237,12 +271,13 @@
 
   (phps-mode-test-with-buffer
    "<?php\nnamespace MyNameSpace{\n\tclass MyClass {\n\t\tpublic function 
__construct() {\n\t\t\texit;\n\t\t}\n\t}\n}\n"
-   
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_NAMESPACE 7 . 16) (T_STRING 17 . 28) 
("{" 28 . 29) (T_CLASS 31 . 36) (T_STRING 37 . 44) ("{" 45 . 46) (T_PUBLIC 49 . 
55) (T_FUNCTION 56 . 64) (T_STRING 65 . 76) ("(" 76 . 77) (")" 77 . 78) ("{" 79 
. 80) (T_EXIT 84 . 88) (";" 88 . 89) ("}" 92 . 93) ("}" 95 . 96) ("}" 97 . 
98)))))
 
   (phps-mode-test-with-buffer
    "<?php\nNAMESPACE MyNameSpace;\nCLASS MyClass {\n\tpublic function 
__construct() {\n\t\texit;\n\t}\n}\n"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_NAMESPACE 7 . 16) (T_STRING 17 . 28) 
(";" 28 . 29) (T_CLASS 30 . 35) (T_STRING 36 . 43) ("{" 44 . 45) (T_PUBLIC 47 . 
53) (T_FUNCTION 54 . 62) (T_STRING 63 . 74) ("(" 74 . 75) (")" 75 . 76) ("{" 77 
. 78) (T_EXIT 81 . 85) (";" 85 . 86) ("}" 88 . 89) ("}" 90 . 91)))))
   )
@@ -252,16 +287,19 @@
 
   (phps-mode-test-with-buffer
    "<?php\necho \"My neverending double quotation\n"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_ERROR 12 . 45)))))
 
   (phps-mode-test-with-buffer
    "<?php\n`My neverending backquotes\n"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) ("`" 7 . 8) (T_ERROR 8 . 34)))))
 
   (phps-mode-test-with-buffer
    "<?php\n<<<LABEL\nMy neverending heredoc\ngoes on forever\n"
+   nil
    (should (equal phps-mode-lexer-tokens
                   '((T_OPEN_TAG 1 . 7) (T_START_HEREDOC 7 . 16) (T_ERROR 16 . 
55)))))
 
diff --git a/phps-mode-test.el b/phps-mode-test.el
index 60479b4..ffdad6f 100644
--- a/phps-mode-test.el
+++ b/phps-mode-test.el
@@ -28,8 +28,8 @@
 
 (autoload 'phps-mode "phps-mode")
 
-(defmacro phps-mode-test-with-buffer (source &rest body)
-  "Set up test buffer with SOURCE and BODY."
+(defmacro phps-mode-test-with-buffer (source &optional title &rest body)
+  "Set up test buffer with SOURCE, TITLE and BODY."
   `(let ((test-buffer (generate-new-buffer "test")))
      (switch-to-buffer test-buffer)
      (insert ,source)
@@ -38,8 +38,8 @@
      (phps-mode)
      ,@body
      (kill-buffer test-buffer)
-     ))
-
+     (when ,title
+       (message "\nPassed tests for '%s'\n" ,title))))
 
 (provide 'phps-mode-test)
 



reply via email to

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