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

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

[elpa] externals/phps-mode 4fa9341 030/405: Started with unit tests for


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 4fa9341 030/405: Started with unit tests for indentation
Date: Sat, 13 Jul 2019 09:59:33 -0400 (EDT)

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

    Started with unit tests for indentation
---
 phps-lexer.el              | 28 ++++++++++++++++++----------
 phps-test-lexer.el         | 18 ++++++++++++++++++
 sample-php-files/class.php |  2 +-
 3 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/phps-lexer.el b/phps-lexer.el
index 52c2a5a..979a383 100644
--- a/phps-lexer.el
+++ b/phps-lexer.el
@@ -1261,6 +1261,7 @@ ANY_CHAR'
   "Return information about point in tokens."
   ;; (message "Point: %s in %s" (point) phps-mode/lexer-tokens)
   (let ((position (point))
+        (line-end (line-end-position))
         (in-scripting nil)
         (brace-level 0)
         (parenthesis-level 0)
@@ -1272,19 +1273,26 @@ ANY_CHAR'
               (end (cdr (cdr item))))
           ;; (message "Token: %s Start: %s End: %s Item: %s" token start end 
item)
 
-          (when (> start position)
+          (when (> start line-end)
             ;; (message "Stopping iteration at: %s %s" start position)
             (throw 'stop-iteration nil))
 
-          (pcase token
-            ('T_OPEN_TAG (setq in-scripting t))
-            ('T_OPEN_TAG_WITH_ECHO (setq in-scripting t))
-            ('T_CLOSE_TAG (setq in-scripting nil))
-            ("{" (setq brace-level (+ brace-level 1)))
-            ("}" (setq brace-level (- brace-level 1)))
-            ("(" (setq parenthesis-level (+ parenthesis-level 1)))
-            (")" (setq parenthesis-level (- parenthesis-level 1)))
-            (_))
+          ;; When start of token is equal or less to current point
+          (when (<= start position)
+            (pcase token
+              ('T_OPEN_TAG (setq in-scripting t))
+              ('T_OPEN_TAG_WITH_ECHO (setq in-scripting t))
+              ('T_CLOSE_TAG (setq in-scripting nil))
+              ("{" (setq brace-level (+ brace-level 1)))
+              ("(" (setq parenthesis-level (+ parenthesis-level 1)))
+              (")" (setq parenthesis-level (- parenthesis-level 1)))
+              (_)))
+
+          ;; When start of token is equal or less to end of curent line
+          (when (<= start line-end)
+            (pcase token
+              ("}" (setq brace-level (- brace-level 1)))
+              (_)))
           
           )))
     (let ((data (list in-scripting brace-level parenthesis-level 
inline-function-level)))
diff --git a/phps-test-lexer.el b/phps-test-lexer.el
index 5db8f02..c96499c 100644
--- a/phps-test-lexer.el
+++ b/phps-test-lexer.el
@@ -306,6 +306,23 @@
 
   )
 
+(defun phps-mode/test-indentation ()
+  "Test for indentation."
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
+   (goto-char 69)
+   (phps-mode/indent-line)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal buffer-contents  "<html><head><title><?php if 
($myCondition) {\n    if ($mySeconCondition) {\necho $title;\n\n} 
?></title><body>Bla bla</body></html>")))
+   (goto-char 85)
+   (phps-mode/indent-line)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal buffer-contents  "<html><head><title><?php if 
($myCondition) {\n    if ($mySeconCondition) {\n        echo $title;\n\n} 
?></title><body>Bla bla</body></html>")))
+   (goto-char 98)
+   (phps-mode/indent-line)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal buffer-contents  "<html><head><title><?php if 
($myCondition) {\n    if ($mySeconCondition) {\n        echo $title;\n\n    } 
?></title><body>Bla bla</body></html>")))))
+
 (defun phps-mode/test-lexer ()
   "Run test for lexer."
   ;; (message "-- Running all tests for lexer... --\n")
@@ -316,6 +333,7 @@
   (phps-mode/test-lexer--namespaces)
   (phps-mode/test-lexer--errors)
   (phps-mode/test-lexer--get-point-data)
+  (phps-mode/test-indentation)
   ;; (message "\n-- Ran all tests for lexer. --")
   )
 
diff --git a/sample-php-files/class.php b/sample-php-files/class.php
index fef6bfe..50c292a 100644
--- a/sample-php-files/class.php
+++ b/sample-php-files/class.php
@@ -17,7 +17,7 @@ class MyClass {
     }
 
     public function myMethod2() {
-       echo "Some stuff here 2";
+        echo "Some stuff here 2";
     }
 
     public function myMethod3() {



reply via email to

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