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

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

[elpa] externals/phps-mode 795053b 013/405: Lexer unit tests using start


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 795053b 013/405: Lexer unit tests using start and ends as well
Date: Sat, 13 Jul 2019 09:59:30 -0400 (EDT)

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

    Lexer unit tests using start and ends as well
---
 phps-lexer.el      |  10 +++-
 phps-test-lexer.el | 158 ++++++++++++++++++++++-------------------------------
 2 files changed, 73 insertions(+), 95 deletions(-)

diff --git a/phps-lexer.el b/phps-lexer.el
index c5713b3..7907b06 100644
--- a/phps-lexer.el
+++ b/phps-lexer.el
@@ -835,7 +835,10 @@
           (progn
             ;; Handle the '' case
             (if (looking-at-p "'")
-                (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start (+ 
end 1))
+                (progn
+                  ;; (message "Empty single quoted string from %s to %s" end 
(+ end 1))
+                  (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING end (+ 
end 1))
+                  (forward-char))
               (progn
                 ;; Unclosed single quotes
                 ;; (message "Single quoted string never ends..")
@@ -874,7 +877,10 @@
           (progn
             ;; Handle the "" case
             (if (looking-at-p "\"")
-                (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start (+ 
end 1))
+                (progn
+                  ;; (message "Empty double quoted string from %s to %s" end 
(+ end 1))
+                  (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING end (+ 
end 1))
+                  (forward-char))
               (progn
                 ;; (message "Found no ending quote, skipping to end")
                 (phps-mode/RETURN_TOKEN 'T_ERROR start (point-max))
diff --git a/phps-test-lexer.el b/phps-test-lexer.el
index 0d329a0..e7d75fb 100644
--- a/phps-test-lexer.el
+++ b/phps-test-lexer.el
@@ -54,45 +54,35 @@
      (kill-buffer test-buffer)
      ))
 
-(defun phps-mode/token-stream-to-string (token-stream)
-  "Return a string from a TOKEN-STREAM."
-  (let ((return ""))
-    (dolist (item token-stream)
-      (setq return (concat return (format " %s" (car item)))))
-    return))
+(defun phps-mode/token-stream-to-string (IGNORE))
 
 (defun phps-mode/test-lexer--script-boundaries ()
   "Run test for lexer."
 
   (phps-mode/with-test-buffer
    "<?php\t$var=1; exit $var;\t?>"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_VARIABLE = T_LNUMBER ; T_EXIT 
T_VARIABLE ; ; T_CLOSE_TAG"))))
+   (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/with-test-buffer
    "<?php\nexit;\n?>"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_EXIT ; ; T_CLOSE_TAG"))))
+   (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/with-test-buffer
    "<?php exit; ?>"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_EXIT ; ; T_CLOSE_TAG"))))
+   (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/with-test-buffer
    "<html><head>blabla</head<body>\n\n \t<?php\nexit;\n?>\n\n</body></html>"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_EXIT ; ; T_CLOSE_TAG"))))
+   (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/with-test-buffer
    "\n\n \t<html><title>echo 
\"Blaha\";</title><?php\n\n\nexit?>\n\n<html><random /></html><?php exit ?>"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_EXIT ; T_CLOSE_TAG T_OPEN_TAG 
T_EXIT ; T_CLOSE_TAG"))))
+   (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)))))
 
   )
 
@@ -101,45 +91,38 @@
 
   (phps-mode/with-test-buffer
    "<?php echo $var = array('');"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_VARIABLE = T_ARRAY ( 
T_CONSTANT_ENCAPSED_STRING ) ;"))))
+     (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 26 . 
27) (")" 27 . 28) (";" 28 . 29)))))
 
   (phps-mode/with-test-buffer
    "<?php if 
(empty($parameters[self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME])) { 
$parameters[self::PARAMETER_CONFIGURATION_INTERNAL_FILENAME] = ''; }"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_IF ( T_EMPTY ( T_VARIABLE [ 
T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING ] ) ) { T_VARIABLE [ T_STRING 
T_PAAMAYIM_NEKUDOTAYIM T_STRING ] = T_CONSTANT_ENCAPSED_STRING ; }"))))
+   (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 146 . 147) (";" 147 . 148) ("}" 149 . 
150)))))
 
   (phps-mode/with-test-buffer
    "<?php echo $var = array(\"\");"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_VARIABLE = T_ARRAY ( 
T_CONSTANT_ENCAPSED_STRING ) ;"))))
+   (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 26 . 
27) (")" 27 . 28) (";" 28 . 29)))))
 
   (phps-mode/with-test-buffer
    "<?php echo $var = array('abc' => '123');"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_VARIABLE = T_ARRAY ( 
T_CONSTANT_ENCAPSED_STRING T_DOUBLE_ARROW T_CONSTANT_ENCAPSED_STRING ) ;"))))
+   (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/with-test-buffer
    "<?php $var = []; "
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_VARIABLE = [ ] ;"))))
+   (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/with-test-buffer
    "<?php echo isset($backtrace[1]['file']) ? 'yes' : 'no'; "
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_ISSET ( T_VARIABLE [ 
T_LNUMBER ] [ T_CONSTANT_ENCAPSED_STRING ] ) ? T_CONSTANT_ENCAPSED_STRING : 
T_CONSTANT_ENCAPSED_STRING ;"))))
+   (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/with-test-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 [...]
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_VARIABLE T_EXIT T_DIE 
T_FUNCTION T_RETURN T_YIELD_FROM T_YIELD T_TRY T_CATCH T_FINALLY T_THROW T_IF 
T_ELSEIF T_ENDIF T_ELSE T_WHILE T_ENDWHILE T_DO T_FOR T_ENDFOR T_FOREACH 
T_ENDFOREACH T_DECLARE T_ENDDECLARE T_INSTANCEOF T_AS T_SWITCH T_ENDSWITCH 
T_CASE T_DEFAULT T_BREAK T_CONTINUE T_GOTO T_ECHO T_PRINT T_CLASS T_INTERFACE 
T_TRAIT T_EXTENDS T_IMPLEMENTS T_PAAMAYIM_NEKUDOTAYIM T_NS_SEPARATOR T_ELLIPSIS 
T_COALESCE T_NEW T_CLONE T_VAR T_INT_ [...]
+   (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,74 +131,68 @@
 
   (phps-mode/with-test-buffer
    "<?php $var->property;"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_VARIABLE T_OBJECT_OPERATOR 
T_STRING ;"))))
+   (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/with-test-buffer
    "<?php echo \"My $variable is here\"; echo \"you know\";"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO \" 
T_ENCAPSED_AND_WHITESPACE T_VARIABLE T_CONSTANT_ENCAPSED_STRING \" ; T_ECHO 
T_CONSTANT_ENCAPSED_STRING ;"))))
+   (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/with-test-buffer
    "<?php echo \"My ${variable} is here 1\";"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO \" 
T_ENCAPSED_AND_WHITESPACE T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME } 
T_CONSTANT_ENCAPSED_STRING \" ;"))))
+   (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/with-test-buffer
    "<?php echo \"Mine {$first_variable} is here and my $second is there.\";"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO \" 
T_ENCAPSED_AND_WHITESPACE T_CURLY_OPEN T_VARIABLE } T_CONSTANT_ENCAPSED_STRING 
T_VARIABLE T_CONSTANT_ENCAPSED_STRING \" ;"))))
+   (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/with-test-buffer
    "<?php echo \" Hello $variable[0], how are you?\";"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO \" 
T_ENCAPSED_AND_WHITESPACE T_VARIABLE T_NUM_STRING ] T_CONSTANT_ENCAPSED_STRING 
\" ;"))))
+   (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/with-test-buffer
    "<?php echo <<<\"MYLABEL\"\nline 1\n line 2\nMYLABEL\n;"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_START_HEREDOC 
T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC ;"))))
+   (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/with-test-buffer
    "<?php echo <<<MYLABEL\nline 1\n line 2\nMYLABEL\n;"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_START_HEREDOC 
T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC ;"))))
+   (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/with-test-buffer
    "<?php echo <<<\"MYLABEL\"\nMYLABEL\n"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_START_HEREDOC 
T_END_HEREDOC"))))
+   (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/with-test-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"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_START_HEREDOC 
T_ENCAPSED_AND_WHITESPACE T_VARIABLE T_ENCAPSED_AND_WHITESPACE 
T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME } T_ENCAPSED_AND_WHITESPACE 
T_CURLY_OPEN T_VARIABLE } T_ENCAPSED_AND_WHITESPACE T_VARIABLE T_NUM_STRING ] 
T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC ;"))))
+   (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/with-test-buffer
    "<?php echo <<<'MYLABEL'\nline 1\n line 2\nMYLABEL;\n"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_START_HEREDOC 
T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC ;"))))
+   (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/with-test-buffer
    "<?php `echo \"HELLO\"`;"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG ` T_CONSTANT_ENCAPSED_STRING ` 
;"))))
+   (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/with-test-buffer
    "<?php `echo \"HELLO $variable or {$variable2} or ${variable3} or 
$variable[index][0] here\"`;"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG ` T_CONSTANT_ENCAPSED_STRING 
T_VARIABLE T_CONSTANT_ENCAPSED_STRING T_CURLY_OPEN T_VARIABLE } 
T_CONSTANT_ENCAPSED_STRING T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME } 
T_CONSTANT_ENCAPSED_STRING T_VARIABLE T_STRING ] T_CONSTANT_ENCAPSED_STRING ` 
;"))))
+   (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)))))
 
   )
 
@@ -224,15 +201,13 @@
 
   (phps-mode/with-test-buffer
    "<?php\nnamespace MyNameSpace{\n\tclass MyClass {\n\t\tpublic function 
__construct() {\n\t\t\texit;\n\t\t}\n\t}\n}\n"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_NAMESPACE T_STRING { T_CLASS 
T_STRING { T_PUBLIC T_FUNCTION T_STRING ( ) { T_EXIT ; } } }"))))
+   (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/with-test-buffer
    "<?php\nNAMESPACE MyNameSpace;\nCLASS MyClass {\n\tpublic function 
__construct() {\n\t\texit;\n\t}\n}\n"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_NAMESPACE T_STRING { T_CLASS 
T_STRING { T_PUBLIC T_FUNCTION T_STRING ( ) { T_EXIT ; } } }"))))
+   (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) ("}" 90 . 
91)))))
   )
 
 (defun phps-mode/test-lexer--errors ()
@@ -240,21 +215,18 @@
 
   (phps-mode/with-test-buffer
    "<?php\necho \"My neverending double quotation\n"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_ECHO T_ERROR"))))
+   (should (equal phps-mode/lexer-tokens
+                  '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_ERROR 12 . 45)))))
 
   (phps-mode/with-test-buffer
    "<?php\n`My neverending backquotes\n"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG ` T_ERROR"))))
+   (should (equal phps-mode/lexer-tokens
+                  '((T_OPEN_TAG 1 . 7) ("`" 7 . 8) (T_ERROR 8 . 34)))))
 
   (phps-mode/with-test-buffer
    "<?php\n<<<LABEL\nMy neverending heredoc\ngoes on forever\n"
-   (let* ((tokens phps-mode/lexer-tokens)
-          (string-tokens (phps-mode/token-stream-to-string tokens)))
-     (should (equal string-tokens " T_OPEN_TAG T_START_HEREDOC T_ERROR"))))
+   (should (equal phps-mode/lexer-tokens
+                  '((T_OPEN_TAG 1 . 7) (T_START_HEREDOC 7 . 16) (T_ERROR 16 . 
55)))))
 
 )
 



reply via email to

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