Keep index synchronized with buffer state
parent
3175d9a6ac
commit
68c826243c
@ -0,0 +1,82 @@
|
||||
;;; phpinspect-toc.el --- PHP parsing and completion package -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021 Free Software Foundation, Inc
|
||||
|
||||
;; Author: Hugo Thunnissen <devel@hugot.nl>
|
||||
;; Keywords: php, languages, tools, convenience
|
||||
;; Version: 0
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'phpinspect-splayt)
|
||||
(require 'phpinspect-parser)
|
||||
|
||||
(defun phpinspect-make-toc (&optional tree)
|
||||
(let ((table (make-hash-table :test #'eq :size 20 :rehash-size 2.0)))
|
||||
(if tree
|
||||
(phpinspect-splayt-traverse-lr (meta tree)
|
||||
(puthash (phpinspect-meta-token meta) meta table))
|
||||
(setq tree (phpinspect-make-splayt)))
|
||||
|
||||
(list tree table)))
|
||||
|
||||
(define-inline phpinspect-toc-register (toc meta)
|
||||
(inline-letevals (toc meta)
|
||||
(inline-quote
|
||||
(progn
|
||||
(phpinspect-splayt-insert (phpinspect-toc-tree ,toc) (phpinspect-meta-start ,meta) ,meta)
|
||||
(puthash (phpinspect-meta-token ,meta) ,meta (phpinspect-toc-table ,toc))))))
|
||||
|
||||
(define-inline phpinspect-toc-tree (toc)
|
||||
(inline-quote (car ,toc)))
|
||||
|
||||
(define-inline phpinspect-toc-table (toc)
|
||||
(inline-quote (cadr ,toc)))
|
||||
|
||||
(defun phpinspect-toc-update (toc new-tree current-root)
|
||||
(let ((current-tree (phpinspect-toc-tree toc))
|
||||
(new-table (make-hash-table :test #'eq :size 20 :rehash-size 2.0))
|
||||
new deleted)
|
||||
|
||||
(phpinspect-splayt-traverse-lr (meta new-tree)
|
||||
(puthash (phpinspect-meta-token meta) meta new-table)
|
||||
(push meta new))
|
||||
|
||||
(phpinspect-splayt-traverse-lr (meta current-tree)
|
||||
(if (eq (phpinspect-meta-find-root meta) current-root)
|
||||
(progn
|
||||
(phpinspect-splayt-insert new-tree (phpinspect-meta-start meta) meta)
|
||||
(puthash (phpinspect-meta-token meta) meta new-table))
|
||||
(push meta deleted)))
|
||||
|
||||
(setf (phpinspect-toc-tree toc) new-tree)
|
||||
(setf (phpinspect-toc-table toc) new-table)
|
||||
|
||||
(list new deleted)))
|
||||
|
||||
(defun phpinspect-toc-token-at-point (toc point)
|
||||
(let ((result (phpinspect-splayt-find-largest-before (phpinspect-toc-tree toc) (+ point 1))))
|
||||
(and result (phpinspect-meta-overlaps-point result point) result)))
|
||||
|
||||
(defun phpinspect-toc-token-at-or-after-point (toc point)
|
||||
(phpinspect-splayt-find-smallest-after (phpinspect-toc-tree toc) (- point 1)))
|
||||
|
||||
(defun phpinspect-toc-tokens-in-region (toc start end)
|
||||
(phpinspect-splayt-find-all-between (phpinspect-toc-tree toc) start end))
|
||||
|
||||
(provide 'phpinspect-toc)
|
@ -0,0 +1,250 @@
|
||||
;;; phpinspect-token-predicates.el --- Predicates for phpinspect-parser tokens types -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021 Free Software Foundation, Inc
|
||||
|
||||
;; Author: Hugo Thunnissen <devel@hugot.nl>
|
||||
;; Keywords: php, languages, tools, convenience
|
||||
;; Version: 0
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
||||
(define-inline phpinspect-token-type-p (object type)
|
||||
"Returns t if OBJECT is a token of type TYPE.
|
||||
Type can be any of the token types returned by
|
||||
`phpinspect-parse-buffer-until-point`"
|
||||
(inline-letevals (object)
|
||||
(inline-quote
|
||||
(and (listp ,object) (eq (car ,object) ,type)))))
|
||||
|
||||
(defsubst phpinspect-object-attrib-p (token)
|
||||
(phpinspect-token-type-p token :object-attrib))
|
||||
|
||||
(defsubst phpinspect-static-attrib-p (token)
|
||||
(phpinspect-token-type-p token :static-attrib))
|
||||
|
||||
(defsubst phpinspect-attrib-p (token)
|
||||
(or (phpinspect-object-attrib-p token)
|
||||
(phpinspect-static-attrib-p token)))
|
||||
|
||||
(defun phpinspect-html-p (token)
|
||||
(phpinspect-token-type-p token :html))
|
||||
|
||||
(defun phpinspect-comma-p (token)
|
||||
(phpinspect-token-type-p token :comma))
|
||||
|
||||
(defsubst phpinspect-terminator-p (token)
|
||||
(phpinspect-token-type-p token :terminator))
|
||||
|
||||
(defsubst phpinspect-end-of-token-p (token)
|
||||
(or (phpinspect-terminator-p token)
|
||||
(phpinspect-comma-p token)
|
||||
(phpinspect-html-p token)))
|
||||
|
||||
(defsubst phpinspect-end-of-statement-p (token)
|
||||
(or (phpinspect-end-of-token-p token)
|
||||
(phpinspect-block-p token)))
|
||||
|
||||
(defsubst phpinspect-incomplete-block-p (token)
|
||||
(phpinspect-token-type-p token :incomplete-block))
|
||||
|
||||
(defsubst phpinspect-block-p (token)
|
||||
(or (phpinspect-token-type-p token :block)
|
||||
(phpinspect-incomplete-block-p token)))
|
||||
|
||||
(defun phpinspect-end-of-use-p (token)
|
||||
(or (phpinspect-block-p token)
|
||||
(phpinspect-end-of-token-p token)))
|
||||
|
||||
(defun phpinspect-static-p (token)
|
||||
(phpinspect-token-type-p token :static))
|
||||
|
||||
(defsubst phpinspect-incomplete-const-p (token)
|
||||
(phpinspect-token-type-p token :incomplete-const))
|
||||
|
||||
(defsubst phpinspect-const-p (token)
|
||||
(or (phpinspect-token-type-p token :const)
|
||||
(phpinspect-incomplete-const-p token)))
|
||||
|
||||
(define-inline phpinspect-scope-p (token)
|
||||
(inline-letevals (token)
|
||||
(inline-quote
|
||||
(or (phpinspect-token-type-p ,token :public)
|
||||
(phpinspect-token-type-p ,token :private)
|
||||
(phpinspect-token-type-p ,token :protected)))))
|
||||
|
||||
(define-inline phpinspect-namespace-p (object)
|
||||
(inline-quote
|
||||
(phpinspect-token-type-p ,object :namespace)))
|
||||
|
||||
(defun phpinspect-incomplete-class-p (token)
|
||||
(and (phpinspect-class-p token)
|
||||
(phpinspect-incomplete-block-p (car (last token)))))
|
||||
|
||||
(defun phpinspect-incomplete-namespace-p (token)
|
||||
(and (phpinspect-namespace-p token)
|
||||
(or (phpinspect-incomplete-block-p (car (last token)))
|
||||
(phpinspect-incomplete-class-p (car (last token))))))
|
||||
|
||||
(define-inline phpinspect-function-p (token)
|
||||
(inline-quote (phpinspect-token-type-p ,token :function)))
|
||||
|
||||
(define-inline phpinspect-class-p (token)
|
||||
(inline-quote (phpinspect-token-type-p ,token :class)))
|
||||
|
||||
(defun phpinspect-incomplete-method-p (token)
|
||||
(or (phpinspect-incomplete-function-p token)
|
||||
(and (phpinspect-scope-p token)
|
||||
(phpinspect-incomplete-function-p (car (last token))))
|
||||
(and (phpinspect-scope-p token)
|
||||
(phpinspect-static-p (car (last token)))
|
||||
(phpinspect-incomplete-function-p (car (last (car (last token))))))
|
||||
(and (phpinspect-scope-p token)
|
||||
(phpinspect-function-p (car (last token))))))
|
||||
|
||||
(defun phpinspect-incomplete-function-p (token)
|
||||
(and (phpinspect-function-p token)
|
||||
(phpinspect-incomplete-block-p (car (last token)))))
|
||||
|
||||
(defsubst phpinspect-incomplete-list-p (token)
|
||||
(phpinspect-token-type-p token :incomplete-list))
|
||||
|
||||
(defsubst phpinspect-list-p (token)
|
||||
(or (phpinspect-token-type-p token :list)
|
||||
(phpinspect-incomplete-list-p token)))
|
||||
|
||||
(define-inline phpinspect-declaration-p (token)
|
||||
(inline-quote
|
||||
(phpinspect-token-type-p ,token :declaration)))
|
||||
|
||||
(defsubst phpinspect-assignment-p (token)
|
||||
(phpinspect-token-type-p token :assignment))
|
||||
|
||||
(defun phpinspect-function-argument-list (php-func)
|
||||
"Get the argument list of a function"
|
||||
(seq-find #'phpinspect-list-p (seq-find #'phpinspect-declaration-p php-func nil) nil))
|
||||
|
||||
(defun phpinspect-annotation-p (token)
|
||||
(phpinspect-token-type-p token :annotation))
|
||||
|
||||
(defun phpinspect-method-annotation-p (token)
|
||||
(phpinspect-token-type-p token :method-annotation))
|
||||
|
||||
(defun phpinspect-var-annotation-p (token)
|
||||
(phpinspect-token-type-p token :var-annotation))
|
||||
|
||||
(defun phpinspect-return-annotation-p (token)
|
||||
(phpinspect-token-type-p token :return-annotation))
|
||||
|
||||
(define-inline phpinspect-class-variable-p (token)
|
||||
(inline-quote (phpinspect-token-type-p ,token :class-variable)))
|
||||
|
||||
(define-inline phpinspect-variable-p (token)
|
||||
(inline-letevals (token)
|
||||
(inline-quote
|
||||
(or (phpinspect-token-type-p ,token :variable)
|
||||
(phpinspect-token-type-p ,token :class-variable)))))
|
||||
|
||||
(defsubst phpinspect-word-p (token)
|
||||
(phpinspect-token-type-p token :word))
|
||||
|
||||
(defsubst phpinspect-incomplete-array-p (token)
|
||||
(phpinspect-token-type-p token :incomplete-array))
|
||||
|
||||
(defsubst phpinspect-array-p (token)
|
||||
(or (phpinspect-token-type-p token :array)
|
||||
(phpinspect-incomplete-array-p token)))
|
||||
|
||||
(defsubst phpinspect-incomplete-root-p (token)
|
||||
(and (phpinspect-root-p token)
|
||||
(seq-find #'phpinspect-incomplete-token-p (cdr token))))
|
||||
|
||||
(defsubst phpinspect-incomplete-token-p (token)
|
||||
(or (phpinspect-incomplete-root-p token)
|
||||
(phpinspect-incomplete-class-p token)
|
||||
(phpinspect-incomplete-block-p token)
|
||||
(phpinspect-incomplete-list-p token)
|
||||
(phpinspect-incomplete-array-p token)
|
||||
(phpinspect-incomplete-const-p token)
|
||||
(phpinspect-incomplete-function-p token)
|
||||
(phpinspect-incomplete-method-p token)
|
||||
(phpinspect-incomplete-namespace-p token)))
|
||||
|
||||
(defun phpinspect--static-terminator-p (token)
|
||||
(or (phpinspect-function-p token)
|
||||
(phpinspect-end-of-token-p token)))
|
||||
|
||||
(defun phpinspect--scope-terminator-p (token)
|
||||
(or (phpinspect-function-p token)
|
||||
(phpinspect-end-of-token-p token)
|
||||
(phpinspect-const-p token)
|
||||
(phpinspect-static-p token)))
|
||||
|
||||
(defsubst phpinspect-enclosing-token-p (token)
|
||||
"Returns t when a token can enclose other tokens"
|
||||
(or
|
||||
(phpinspect-list-p token)
|
||||
(phpinspect-block-p token)
|
||||
(phpinspect-class-p token)
|
||||
(phpinspect-function-p token)
|
||||
(phpinspect-array-p token)
|
||||
(phpinspect-scope-p token)
|
||||
(phpinspect-static-p token)
|
||||
(phpinspect-const-p token)))
|
||||
|
||||
(defun phpinspect-namespace-keyword-p (token)
|
||||
(and (phpinspect-word-p token) (string= (car (last token)) "namespace")))
|
||||
|
||||
(defun phpinspect-use-keyword-p (token)
|
||||
(and (phpinspect-word-p token) (string= (car (last token)) "use")))
|
||||
|
||||
|
||||
(defsubst phpinspect-root-p (object)
|
||||
(phpinspect-token-type-p object :root))
|
||||
|
||||
(defsubst phpinspect-namespace-or-root-p (object)
|
||||
(or (phpinspect-namespace-p object)
|
||||
(phpinspect-root-p object)))
|
||||
|
||||
(define-inline phpinspect-use-p (object)
|
||||
(inline-quote (phpinspect-token-type-p ,object :use)))
|
||||
|
||||
(defun phpinspect-comment-p (token)
|
||||
(or (phpinspect-token-type-p token :comment)
|
||||
(phpinspect-token-type-p token :doc-block)))
|
||||
|
||||
(defsubst phpinspect-class-block (class)
|
||||
(caddr class))
|
||||
|
||||
(define-inline phpinspect-namespace-is-blocked-p (namespace)
|
||||
(inline-letevals (namespace)
|
||||
(inline-quote
|
||||
(and (= (length ,namespace) 3) (phpinspect-block-p (caddr ,namespace))))))
|
||||
|
||||
(defsubst phpinspect-namespace-block (namespace)
|
||||
(when (phpinspect-namespace-is-blocked-p namespace)
|
||||
(caddr namespace)))
|
||||
|
||||
(defsubst phpinspect-function-block (php-func)
|
||||
(caddr php-func))
|
||||
|
||||
(defsubst phpinspect-not-class-p (token)
|
||||
"Apply inverse of `phpinspect-class-p' to TOKEN."
|
||||
(not (phpinspect-class-p token)))
|
||||
|
||||
(provide 'phpinspect-token-predicates)
|
@ -1 +1 @@
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) (:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use (:word "App\\Repository\\UserRepository") (:terminator ";")) (:use (:word "Doctrine\\ORM\\EntityManagerInterface") (:terminator ";")) (:use (:word "Twig\\Environment") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\Request") (:terminator ";")) (:use (:word "Symfony\\Component\\Routing\\Annotation\\Route") (:terminator ";")) (:class (:declaration (:word "class") (:word "AddressController")) (:incomplete-block (:const (:word "A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE") (:assignment "=") (:string "a value") (:terminator ";")) (:public (:const (:word "ARRAY_CONSTANT") (:assignment "=") (:array (:string "key") (:fat-arrow "=>") (:string "value") (:comma ",") (:string "key") (:fat-arrow "=>")) (:terminator ";"))) (:private (:variable "repo") (:terminator ";")) (:private (:variable "user_repo") (:terminator ";")) (:private (:variable "twig") (:terminator ";")) (:private (:variable "em") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "AddressRepository") (:variable "repo") (:comma ",") (:word "UserRepository") (:variable "user_repo") (:comma ",") (:word "Environment") (:variable "twig") (:comma ",") (:word "EntityManagerInterface") (:variable "em"))) (:block (:variable "this") (:object-attrib (:word "repo")) (:assignment "=") (:variable "repo") (:terminator ";") (:variable "this") (:object-attrib (:word "user_repo")) (:assignment "=") (:variable "user_repo") (:terminator ";") (:variable "this") (:object-attrib (:word "twig")) (:assignment "=") (:variable "twig") (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:assignment "=") (:variable "em") (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressPage") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:word "return") (:word "new") (:word "Response") (:list (:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word "render")) (:list (:string "address/create.html.twig") (:comma ",") (:array (:string "user") (:fat-arrow "=>") (:variable "user") (:comma ",")))) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:variable "address_string") (:assignment "=") (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address")) (:terminator ";") (:variable "address") (:assignment "=") (:word "new") (:word "Address") (:list (:variable "user") (:comma ",") (:variable "address_string")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "persist")) (:list (:variable "address")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "flush")) (:list) (:terminator ";") (:word "return") (:word "new") (:word "RedirectResponse") (:list (:string "/user/") (:variable "user") (:object-attrib (:word "getLoginName")) (:list) (:string "/manage")) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "deleteAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:incomplete-block (:variable "address") (:assignment "=") (:variable "this") (:object-attrib (:word "repo")) (:object-attrib (:word "find")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address"))) (:terminator ";") (:comment) (:comment) (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "remove")) (:incomplete-list (:variable "this") (:object-attrib (:word "em")) (:object-attrib nil)))))))))
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) (:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use (:word "App\\Repository\\UserRepository") (:terminator ";")) (:use (:word "Doctrine\\ORM\\EntityManagerInterface") (:terminator ";")) (:use (:word "Twig\\Environment") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\Request") (:terminator ";")) (:use (:word "Symfony\\Component\\Routing\\Annotation\\Route") (:terminator ";")) (:class (:declaration (:word "class") (:word "AddressController")) (:incomplete-block (:const (:word "A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE") (:assignment "=") (:string "a value") (:terminator ";")) (:public (:const (:word "ARRAY_CONSTANT") (:assignment "=") (:array (:string "key") (:fat-arrow "=>") (:string "value") (:comma ",") (:string "key") (:fat-arrow "=>")) (:terminator ";"))) (:private (:class-variable "repo") (:terminator ";")) (:private (:class-variable "user_repo") (:terminator ";")) (:private (:class-variable "twig") (:terminator ";")) (:private (:class-variable "em") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "AddressRepository") (:variable "repo") (:comma ",") (:word "UserRepository") (:variable "user_repo") (:comma ",") (:word "Environment") (:variable "twig") (:comma ",") (:word "EntityManagerInterface") (:variable "em"))) (:block (:variable "this") (:object-attrib (:word "repo")) (:assignment "=") (:variable "repo") (:terminator ";") (:variable "this") (:object-attrib (:word "user_repo")) (:assignment "=") (:variable "user_repo") (:terminator ";") (:variable "this") (:object-attrib (:word "twig")) (:assignment "=") (:variable "twig") (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:assignment "=") (:variable "em") (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressPage") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:word "return") (:word "new") (:word "Response") (:list (:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word "render")) (:list (:string "address/create.html.twig") (:comma ",") (:array (:string "user") (:fat-arrow "=>") (:variable "user") (:comma ",")))) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:variable "address_string") (:assignment "=") (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address")) (:terminator ";") (:variable "address") (:assignment "=") (:word "new") (:word "Address") (:list (:variable "user") (:comma ",") (:variable "address_string")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "persist")) (:list (:variable "address")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "flush")) (:list) (:terminator ";") (:word "return") (:word "new") (:word "RedirectResponse") (:list (:string "/user/") (:variable "user") (:object-attrib (:word "getLoginName")) (:list) (:string "/manage")) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "deleteAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:incomplete-block (:variable "address") (:assignment "=") (:variable "this") (:object-attrib (:word "repo")) (:object-attrib (:word "find")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address"))) (:terminator ";") (:comment) (:comment) (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "remove")) (:incomplete-list (:variable "this") (:object-attrib (:word "em")) (:object-attrib nil)))))))))
|
@ -1 +1 @@
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block (:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) (:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use (:word "App\\Repository\\UserRepository") (:terminator ";")) (:use (:word "Doctrine\\ORM\\EntityManagerInterface") (:terminator ";")) (:use (:word "Twig\\Environment") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\Request") (:terminator ";")) (:use (:word "Symfony\\Component\\Routing\\Annotation\\Route") (:terminator ";")) (:class (:declaration (:word "class") (:word "AddressController")) (:incomplete-block (:const (:word "A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE") (:assignment "=") (:string "a value") (:terminator ";")) (:public (:const (:word "ARRAY_CONSTANT") (:assignment "=") (:array (:string "key") (:fat-arrow "=>") (:string "value") (:comma ",") (:string "key") (:fat-arrow "=>")) (:terminator ";"))) (:private (:variable "repo") (:terminator ";")) (:private (:variable "user_repo") (:terminator ";")) (:private (:variable "twig") (:terminator ";")) (:private (:variable "em") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "AddressRepository") (:variable "repo") (:comma ",") (:word "UserRepository") (:variable "user_repo") (:comma ",") (:word "Environment") (:variable "twig") (:comma ",") (:word "EntityManagerInterface") (:variable "em"))) (:block (:variable "this") (:object-attrib (:word "repo")) (:assignment "=") (:variable "repo") (:terminator ";") (:variable "this") (:object-attrib (:word "user_repo")) (:assignment "=") (:variable "user_repo") (:terminator ";") (:variable "this") (:object-attrib (:word "twig")) (:assignment "=") (:variable "twig") (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:assignment "=") (:variable "em") (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressPage") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:word "return") (:word "new") (:word "Response") (:list (:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word "render")) (:list (:string "address/create.html.twig") (:comma ",") (:array (:string "user") (:fat-arrow "=>") (:variable "user") (:comma ",")))) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:variable "address_string") (:assignment "=") (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address")) (:terminator ";") (:variable "address") (:assignment "=") (:word "new") (:word "Address") (:list (:variable "user") (:comma ",") (:variable "address_string")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "persist")) (:list (:variable "address")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "flush")) (:list) (:terminator ";") (:word "return") (:word "new") (:word "RedirectResponse") (:list (:string "/user/") (:variable "user") (:object-attrib (:word "getLoginName")) (:list) (:string "/manage")) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "deleteAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:incomplete-block (:variable "address") (:assignment "=") (:variable "this") (:object-attrib (:word "repo")) (:object-attrib (:word "find")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address"))) (:terminator ";") (:comment) (:comment) (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "remove")) (:incomplete-list (:variable "this") (:object-attrib (:word "em")) (:object-attrib nil))))))))))
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block (:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) (:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use (:word "App\\Repository\\UserRepository") (:terminator ";")) (:use (:word "Doctrine\\ORM\\EntityManagerInterface") (:terminator ";")) (:use (:word "Twig\\Environment") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\Request") (:terminator ";")) (:use (:word "Symfony\\Component\\Routing\\Annotation\\Route") (:terminator ";")) (:class (:declaration (:word "class") (:word "AddressController")) (:incomplete-block (:const (:word "A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE") (:assignment "=") (:string "a value") (:terminator ";")) (:public (:const (:word "ARRAY_CONSTANT") (:assignment "=") (:array (:string "key") (:fat-arrow "=>") (:string "value") (:comma ",") (:string "key") (:fat-arrow "=>")) (:terminator ";"))) (:private (:class-variable "repo") (:terminator ";")) (:private (:class-variable "user_repo") (:terminator ";")) (:private (:class-variable "twig") (:terminator ";")) (:private (:class-variable "em") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "AddressRepository") (:variable "repo") (:comma ",") (:word "UserRepository") (:variable "user_repo") (:comma ",") (:word "Environment") (:variable "twig") (:comma ",") (:word "EntityManagerInterface") (:variable "em"))) (:block (:variable "this") (:object-attrib (:word "repo")) (:assignment "=") (:variable "repo") (:terminator ";") (:variable "this") (:object-attrib (:word "user_repo")) (:assignment "=") (:variable "user_repo") (:terminator ";") (:variable "this") (:object-attrib (:word "twig")) (:assignment "=") (:variable "twig") (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:assignment "=") (:variable "em") (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressPage") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:word "return") (:word "new") (:word "Response") (:list (:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word "render")) (:list (:string "address/create.html.twig") (:comma ",") (:array (:string "user") (:fat-arrow "=>") (:variable "user") (:comma ",")))) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:variable "address_string") (:assignment "=") (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address")) (:terminator ";") (:variable "address") (:assignment "=") (:word "new") (:word "Address") (:list (:variable "user") (:comma ",") (:variable "address_string")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "persist")) (:list (:variable "address")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "flush")) (:list) (:terminator ";") (:word "return") (:word "new") (:word "RedirectResponse") (:list (:string "/user/") (:variable "user") (:object-attrib (:word "getLoginName")) (:list) (:string "/manage")) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "deleteAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:incomplete-block (:variable "address") (:assignment "=") (:variable "this") (:object-attrib (:word "repo")) (:object-attrib (:word "find")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address"))) (:terminator ";") (:comment) (:comment) (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "remove")) (:incomplete-list (:variable "this") (:object-attrib (:word "em")) (:object-attrib nil))))))))))
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use (:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) (:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") (:word "AuthToken")) (:block (:private (:variable "token") (:terminator ";")) (:doc-block (:var-annotation (:word "App\\\\Entity\\\\User"))) (:private (:variable "user") (:terminator ";")) (:doc-block (:var-annotation (:word "bool"))) (:private (:variable "valid") (:terminator ";")) (:doc-block (:var-annotation (:word "\\DateTime"))) (:private (:variable "creation_time") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "string") (:variable "token") (:comma ",") (:word "User") (:variable "user") (:comma ",") (:word "bool") (:variable "valid") (:assignment "=") (:word "false") (:comma ",") (:word "\\DateTime") (:variable "creation_time") (:assignment "=") (:word "null"))) (:block (:variable "this") (:object-attrib (:word "token")) (:assignment "=") (:variable "token") (:terminator ";") (:variable "this") (:object-attrib (:word "user")) (:assignment "=") (:variable "user") (:terminator ";") (:variable "this") (:object-attrib (:word "valid")) (:assignment "=") (:variable "valid") (:terminator ";") (:variable "this") (:object-attrib (:word "creation_time")) (:assignment "=") (:variable "creation_time") (:word "new") (:word "\\DateTime") (:list) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getToken") (:list) (:word "string")) (:block (:word "return") (:variable "this") (:object-attrib (:word "token")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getUser") (:list) (:word "User")) (:block (:word "return") (:variable "this") (:object-attrib (:word "user")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "hasStudentRole") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "role_student")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "isValid") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "valid")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getCreationTime") (:list) (:word "\\DateTime")) (:block (:word "return") (:variable "this") (:object-attrib (:word "creation_time")) (:terminator ";")))) (:doc-block (:return-annotation (:word "DateTime[]"))) (:public (:function (:declaration (:word "function") (:word "arrayReturn") (:list) (:word "array")) (:block (:word "return") (:array (:word "new") (:word "\\DateTime") (:list)) (:terminator ";"))))))))
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use (:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) (:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") (:word "AuthToken")) (:block (:private (:class-variable "token") (:terminator ";")) (:doc-block (:var-annotation (:word "App\\\\Entity\\\\User"))) (:private (:class-variable "user") (:terminator ";")) (:doc-block (:var-annotation (:word "bool"))) (:private (:class-variable "valid") (:terminator ";")) (:doc-block (:var-annotation (:word "\\DateTime"))) (:private (:class-variable "creation_time") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "string") (:variable "token") (:comma ",") (:word "User") (:variable "user") (:comma ",") (:word "bool") (:variable "valid") (:assignment "=") (:word "false") (:comma ",") (:word "\\DateTime") (:variable "creation_time") (:assignment "=") (:word "null"))) (:block (:variable "this") (:object-attrib (:word "token")) (:assignment "=") (:variable "token") (:terminator ";") (:variable "this") (:object-attrib (:word "user")) (:assignment "=") (:variable "user") (:terminator ";") (:variable "this") (:object-attrib (:word "valid")) (:assignment "=") (:variable "valid") (:terminator ";") (:variable "this") (:object-attrib (:word "creation_time")) (:assignment "=") (:variable "creation_time") (:word "new") (:word "\\DateTime") (:list) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getToken") (:list) (:word "string")) (:block (:word "return") (:variable "this") (:object-attrib (:word "token")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getUser") (:list) (:word "User")) (:block (:word "return") (:variable "this") (:object-attrib (:word "user")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "hasStudentRole") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "role_student")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "isValid") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "valid")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getCreationTime") (:list) (:word "\\DateTime")) (:block (:word "return") (:variable "this") (:object-attrib (:word "creation_time")) (:terminator ";")))) (:doc-block (:return-annotation (:word "DateTime[]"))) (:public (:function (:declaration (:word "function") (:word "arrayReturn") (:list) (:word "array")) (:block (:word "return") (:array (:word "new") (:word "\\DateTime") (:list)) (:terminator ";"))))))))
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use (:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) (:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") (:word "AuthToken")) (:block (:private (:variable "token") (:terminator ";")) (:private (:variable "extra") (:terminator ";")) (:doc-block (:var-annotation (:word "App\\\\Entity\\\\User"))) (:private (:variable "user") (:terminator ";")) (:doc-block (:var-annotation (:word "bool"))) (:private (:variable "valid") (:terminator ";")) (:doc-block (:var-annotation (:word "\\DateTime"))) (:private (:variable "creation_time") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "string") (:variable "token") (:comma ",") (:word "User") (:variable "user") (:comma ",") (:word "bool") (:variable "valid") (:assignment "=") (:word "false") (:comma ",") (:word "\\DateTime") (:variable "creation_time") (:assignment "=") (:word "null"))) (:block (:variable "this") (:object-attrib (:word "token")) (:assignment "=") (:variable "token") (:terminator ";") (:variable "this") (:object-attrib (:word "user")) (:assignment "=") (:variable "user") (:terminator ";") (:variable "this") (:object-attrib (:word "valid")) (:assignment "=") (:variable "valid") (:terminator ";") (:variable "this") (:object-attrib (:word "creation_time")) (:assignment "=") (:variable "creation_time") (:word "new") (:word "\\DateTime") (:list) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getToken") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "token")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getUser") (:list) (:word "User")) (:block (:word "return") (:variable "this") (:object-attrib (:word "user")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "hasStudentRole") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "role_student")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "isValid") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "valid")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "anAddedFunction") (:list)) (:block (:word "return") (:variable "this") (:object-attrib (:word "extra")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getCreationTime") (:list) (:word "\\DateTime")) (:block (:word "return") (:variable "this") (:object-attrib (:word "creation_time")) (:terminator ";"))))))))
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use (:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) (:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") (:word "AuthToken")) (:block (:private (:class-variable "token") (:terminator ";")) (:private (:class-variable "extra") (:terminator ";")) (:doc-block (:var-annotation (:word "App\\\\Entity\\\\User"))) (:private (:class-variable "user") (:terminator ";")) (:doc-block (:var-annotation (:word "bool"))) (:private (:class-variable "valid") (:terminator ";")) (:doc-block (:var-annotation (:word "\\DateTime"))) (:private (:class-variable "creation_time") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "string") (:variable "token") (:comma ",") (:word "User") (:variable "user") (:comma ",") (:word "bool") (:variable "valid") (:assignment "=") (:word "false") (:comma ",") (:word "\\DateTime") (:variable "creation_time") (:assignment "=") (:word "null"))) (:block (:variable "this") (:object-attrib (:word "token")) (:assignment "=") (:variable "token") (:terminator ";") (:variable "this") (:object-attrib (:word "user")) (:assignment "=") (:variable "user") (:terminator ";") (:variable "this") (:object-attrib (:word "valid")) (:assignment "=") (:variable "valid") (:terminator ";") (:variable "this") (:object-attrib (:word "creation_time")) (:assignment "=") (:variable "creation_time") (:word "new") (:word "\\DateTime") (:list) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getToken") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "token")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getUser") (:list) (:word "User")) (:block (:word "return") (:variable "this") (:object-attrib (:word "user")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "hasStudentRole") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "role_student")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "isValid") (:list) (:word "bool")) (:block (:word "return") (:variable "this") (:object-attrib (:word "valid")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "anAddedFunction") (:list)) (:block (:word "return") (:variable "this") (:object-attrib (:word "extra")) (:terminator ";")))) (:public (:function (:declaration (:word "function") (:word "getCreationTime") (:list) (:word "\\DateTime")) (:block (:word "return") (:variable "this") (:object-attrib (:word "creation_time")) (:terminator ";"))))))))
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,41 @@
|
||||
;;; phpinspect-test-env.el --- Unit tests for phpinspect.el -*- lexical-binding: t; -*-
|
||||
|
||||
(require 'phpinspect-worker)
|
||||
(require 'phpinspect-cache)
|
||||
|
||||
;; Make sure that the worker is running. TODO: fully encapsulate the worker the
|
||||
;; data types that are used in tests so that we don't depend on some global
|
||||
;; worker object for tests.
|
||||
(phpinspect-ensure-worker)
|
||||
(phpinspect-purge-cache)
|
||||
|
||||
(defvar phpinspect-test-directory
|
||||
(file-name-directory
|
||||
(or load-file-name
|
||||
buffer-file-name))
|
||||
"Directory that phpinspect tests reside in.")
|
||||
|
||||
|
||||
(defvar phpinspect-test-php-file-directory
|
||||
(concat
|
||||
(file-name-directory
|
||||
(or load-file-name
|
||||
buffer-file-name))
|
||||
"/fixtures")
|
||||
"Directory with syntax trees of example PHP files.")
|
||||
|
||||
(defun phpinspect-test-read-fixture-data (name)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents-literally (concat phpinspect-test-php-file-directory "/" name ".eld"))
|
||||
(read (current-buffer))))
|
||||
|
||||
(defun phpinspect-test-read-fixture-serialization (name)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents-literally (concat phpinspect-test-php-file-directory "/" name ".eld"))
|
||||
(eval (read (current-buffer)))))
|
||||
|
||||
(defun phpinspect-test-parse-fixture-code (name)
|
||||
(phpinspect-parse-file
|
||||
(concat phpinspect-test-php-file-directory "/" name ".php")))
|
||||
|
||||
(provide 'phpinspect-test-env)
|
@ -0,0 +1,67 @@
|
||||
;; test-meta.el --- Unit tests for phpinspect.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Hugo Thunnissen <devel@hugot.nl>
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
||||
(require 'ert)
|
||||
(require 'phpinspect-meta)
|
||||
|
||||
(ert-deftest phpinspect-meta-start-relative-to-parent ()
|
||||
(let ((meta (phpinspect-make-meta nil 10 20 "" 'token))
|
||||
(parent1 (phpinspect-make-meta nil 9 22 "" 'token))
|
||||
(parent2 (phpinspect-make-meta nil 0 100 "" 'token)))
|
||||
(phpinspect-meta-set-parent meta parent1)
|
||||
(phpinspect-meta-set-parent parent1 parent2)
|
||||
|
||||
(should (= 10 (phpinspect-meta-start meta)))
|
||||
|
||||
(phpinspect-meta-shift parent2 20)
|
||||
(should (= 30 (phpinspect-meta-start meta)))
|
||||
|
||||
(should (phpinspect-meta-overlaps-point meta 30))))
|
||||
|
||||
(ert-deftest phpinspect-meta-iterator ()
|
||||
(let* ((meta (phpinspect-make-meta nil 10 20 "" 'token))
|
||||
(firstchild (phpinspect-make-meta nil 10 12 "" 'token))
|
||||
(secondchild (phpinspect-make-meta nil 13 15 "" 'token))
|
||||
(parent1 (phpinspect-make-meta nil 9 22 "" 'token))
|
||||
(sibling (phpinspect-make-meta nil 30 55 "" 'token))
|
||||
(parent2 (phpinspect-make-meta nil 0 100 "" 'token))
|
||||
iterator)
|
||||
(phpinspect-meta-set-parent meta parent1)
|
||||
(phpinspect-meta-set-parent parent1 parent2)
|
||||
(phpinspect-meta-set-parent sibling parent2)
|
||||
(phpinspect-meta-set-parent firstchild meta)
|
||||
(phpinspect-meta-set-parent secondchild meta)
|
||||
|
||||
(setq iterator (phpinspect-make-meta-iterator parent2))
|
||||
|
||||
(should (eq meta (phpinspect-meta-iterator-token-at-point iterator 10)))
|
||||
(should (eq sibling (phpinspect-meta-iterator-token-at-point iterator 30)))
|
||||
(should (eq meta (phpinspect-meta-iterator-token-at-point iterator 10)))
|
||||
(should (eq firstchild (phpinspect-meta-iterator-token-at-point iterator 10)))
|
||||
(should (eq secondchild (phpinspect-meta-iterator-token-at-point iterator 13)))
|
||||
(should (eq meta (phpinspect-meta-iterator-token-at-point iterator 10)))
|
||||
(should (eq firstchild (phpinspect-meta-iterator-token-at-point iterator 10)))
|
||||
(should (eq sibling (phpinspect-meta-iterator-token-at-point iterator 30)))))
|
@ -0,0 +1,50 @@
|
||||
;;; test-edtrack.el --- Unit tests for phpinspect.el -*- lexical-binding: t; -*-
|
||||
|
||||
(require 'phpinspect-toc)
|
||||
(require 'phpinspect-splayt)
|
||||
|
||||
(ert-deftest phpinspect-make-toc ()
|
||||
(let ((tokens (phpinspect-make-splayt))
|
||||
toc)
|
||||
(phpinspect-splayt-insert tokens 1 (phpinspect-make-meta nil 1 20 "" 'token1))
|
||||
(phpinspect-splayt-insert tokens 40 (phpinspect-make-meta nil 40 45 "" 'token2))
|
||||
(phpinspect-splayt-insert tokens 55 (phpinspect-make-meta nil 55 70 "" 'token3))
|
||||
|
||||
(setq toc (phpinspect-make-toc tokens))
|
||||
|
||||
(should (= 3 (hash-table-count (phpinspect-toc-table toc))))
|
||||
(should (= 3 (length (phpinspect-splayt-to-list (phpinspect-toc-tree toc)))))))
|
||||
|
||||
(ert-deftest phpinspect-update-toc ()
|
||||
(let ((tokens (phpinspect-make-splayt))
|
||||
(root (phpinspect-make-meta nil 1 200 "" 'root))
|
||||
(new-root (phpinspect-make-meta nil 1 400 "" 'root))
|
||||
(tok1 (phpinspect-make-meta nil 1 20 "" 'token1))
|
||||
(tok2 (phpinspect-make-meta nil 40 45 "" 'token2))
|
||||
(tok3 (phpinspect-make-meta nil 55 70 "" 'token3))
|
||||
(tok4 (phpinspect-make-meta nil 71 91 "" 'token4))
|
||||
new-tokens toc)
|
||||
|
||||
(phpinspect-meta-set-parent tok1 root)
|
||||
(phpinspect-meta-set-parent tok2 root)
|
||||
(phpinspect-meta-set-parent tok3 root)
|
||||
|
||||
(phpinspect-splayt-insert tokens 1 tok1)
|
||||
(phpinspect-splayt-insert tokens 40 tok2)
|
||||
(phpinspect-splayt-insert tokens 55 tok3)
|
||||
|
||||
(setq toc (phpinspect-make-toc tokens))
|
||||
|
||||
(phpinspect-meta-set-parent tok2 new-root)
|
||||
(phpinspect-meta-set-parent tok3 new-root)
|
||||
(phpinspect-meta-set-parent tok4 new-root)
|
||||
|
||||
(setq new-tokens (phpinspect-make-splayt))
|
||||
(phpinspect-splayt-insert new-tokens 71 tok4)
|
||||
|
||||
(pcase-let ((`(,result-new ,result-deleted) (phpinspect-toc-update toc new-tokens new-root)))
|
||||
(should (= 1 (length result-new)))
|
||||
(should (= 1 (length result-deleted)))
|
||||
|
||||
(should (eq tok1 (car result-deleted)))
|
||||
(should (eq tok4 (car result-new))))))
|
Loading…
Reference in New Issue