[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode e340279 082/405: Added unit tests for moving
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode e340279 082/405: Added unit tests for moving lexer-state positions |
Date: |
Sat, 13 Jul 2019 09:59:48 -0400 (EDT) |
branch: externals/phps-mode
commit e340279f93bf060ed76568e15d00bd306cf411c3
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Added unit tests for moving lexer-state positions
---
phps-lexer.el | 41 +++++++++++++++++++++++++++--------------
phps-test-lexer.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 14 deletions(-)
diff --git a/phps-lexer.el b/phps-lexer.el
index 18ee244..0478323 100644
--- a/phps-lexer.el
+++ b/phps-lexer.el
@@ -1284,8 +1284,23 @@ ANY_CHAR'
(defun phps-mode/get-moved-lexer-states (states start diff)
"Return moved lexer STATES after (or equal to) START with modification DIFF."
- ;; TODO Implement this
- )
+ (let ((old-states states)
+ (new-states '()))
+ (when old-states
+
+ ;; Iterate through states add states before start start unchanged and
the others modified with diff
+ (dolist (state-object (nreverse old-states))
+ (let ((state-start (nth 0 state-object))
+ (state-end (nth 1 state-object))
+ (state-symbol (nth 2 state-object))
+ (state-stack (nth 3 state-object)))
+ (if (>= state-start start)
+ (let ((new-state-start (+ state-start diff))
+ (new-state-end (+ state-end diff)))
+ (push (list new-state-start new-state-end state-symbol
state-stack) new-states))
+ (push state-object new-states)))))
+
+ new-states))
(defun phps-mode/lexer-move-lexer-tokens (start diff)
"Update tokens with moved lexer tokens after or equal to START with
modification DIFF."
@@ -1296,18 +1311,16 @@ ANY_CHAR'
(let ((new-tokens '()))
(when old-tokens
- ;; Iterate over all tokens, add those that are to be left unchanged and
- ;; add modified ones that are to be changed.
- (catch 'stop-iteration
- (dolist (token (nreverse old-tokens))
- (let ((token-symbol (car token))
- (token-start (car (cdr token)))
- (token-end (cdr (cdr token))))
- (if (>= token-start start)
- (let ((new-token-start (+ token-start diff))
- (new-token-end (+ token-end diff)))
- (push `(,token-symbol ,new-token-start . ,new-token-end)
new-tokens))
- (push token new-tokens))))))
+ ;; Iterate over all tokens, add those that are to be left unchanged and
add modified ones that should be changed.
+ (dolist (token (nreverse old-tokens))
+ (let ((token-symbol (car token))
+ (token-start (car (cdr token)))
+ (token-end (cdr (cdr token))))
+ (if (>= token-start start)
+ (let ((new-token-start (+ token-start diff))
+ (new-token-end (+ token-end diff)))
+ (push `(,token-symbol ,new-token-start . ,new-token-end)
new-tokens))
+ (push token new-tokens)))))
new-tokens))
diff --git a/phps-test-lexer.el b/phps-test-lexer.el
index e2401d5..629b17d 100644
--- a/phps-test-lexer.el
+++ b/phps-test-lexer.el
@@ -294,6 +294,58 @@
)
+(defun phps-mode/test-get-moved-lexer-states ()
+ "Run test for get moved lexer states."
+
+ (should (equal
+ '((68 76 1 '(1))
+ (10 67 1 '(1))
+ (1 7 1 '(1)))
+
+ (phps-mode/get-moved-lexer-states
+ '((66 74 1 '(1))
+ (8 65 1 '(1))
+ (1 7 1 '(1)))
+ 7
+ 2)))
+
+ (should (equal
+ '((67 75 1 '(1))
+ (9 66 1 '(1))
+ (2 8 1 '(1)))
+
+ (phps-mode/get-moved-lexer-states
+ '((66 74 1 '(1))
+ (8 65 1 '(1))
+ (1 7 1 '(1)))
+ 0
+ 1)))
+
+ (should (equal
+ '((66 74 1 '(1))
+ (8 65 1 '(1))
+ (1 7 1 '(1)))
+
+ (phps-mode/get-moved-lexer-states
+ '((66 74 1 '(1))
+ (8 65 1 '(1))
+ (1 7 1 '(1)))
+ 100
+ 1)))
+
+ (should (equal
+ '((64 72 1 '(1))
+ (6 63 1 '(1))
+ (1 7 1 '(1)))
+
+ (phps-mode/get-moved-lexer-states
+ '((66 74 1 '(1))
+ (8 65 1 '(1))
+ (3 9 1 '(1)))
+ 3
+ -2)))
+ )
+
(defun phps-mode/test-lexer ()
"Run test for lexer."
;; (message "-- Running all tests for lexer... --\n")
@@ -304,6 +356,7 @@
(phps-mode/test-lexer--namespaces)
(phps-mode/test-lexer--errors)
(phps-mode/test-get-moved-lexer-tokens)
+ (phps-mode/test-get-moved-lexer-states)
;; (message "\n-- Ran all tests for lexer. --")
)
- [elpa] externals/phps-mode 1be9270 068/405: Updated README, (continued)
- [elpa] externals/phps-mode 1be9270 068/405: Updated README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e57f1e1 075/405: Skipping indentation if it's already correct, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c57fb5b 073/405: Improved indentation of trailing opening brace, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 5e30a65 076/405: Added TODO items, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 94d4814 078/405: Added test for moving lexer tokens, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a59ef7b 079/405: More unit tests for moving lexer token positions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 287d934 077/405: Updated comments are made un-tested function for moving token positions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b3821a1 080/405: Updated TODOs, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f4cd90e 072/405: Updated readme and makefile for running all tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f79cf4f 081/405: Started on function for moving lexer states, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e340279 082/405: Added unit tests for moving lexer-state positions,
Stefan Monnier <=
- [elpa] externals/phps-mode 89b12ab 084/405: Added autoloads and fixed bug with assigning variable, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a10cc79 085/405: Debugging a indentation case, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e30ac0c 083/405: Started implementation of moving lexer and state position when, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8c919ac 087/405: Added failing indentation test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 69ced0d 090/405: Added another unit test for failed indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f2f41a3 088/405: Handles indentation case with } else if (...) {, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 59ba835 086/405: Fixed issue with wrong indentation at trailing opening brace, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 434c3dc 089/405: Added more failing tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 61abf7e 091/405: Added todo item, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f7f931a 092/405: Added another failing indentation test, Stefan Monnier, 2019/07/13