Compare commits

...

2 Commits

Author SHA1 Message Date
Hugo Thunnissen ec17b2f163 Start implementation of cache DSL
ci/woodpecker/push/woodpecker Pipeline failed Details
9 months ago
Hugo Thunnissen 46df6bbfb1 WIP: new cache implementation 9 months ago

@ -286,5 +286,378 @@ then returned."
(puthash "builtins" project (phpinspect--cache-projects phpinspect-stub-cache))
(setf (phpinspect--cache-read-only-p phpinspect-stub-cache) t)))
(cl-defstruct (phpinspect-cache (:constructor phpinspect-make-cache))
(groups (make-hash-table :test #'equal :size 2000 :rehash-size 1.2)))
(cl-defstruct (phpinspect-cache-type (:constructor phpinspect-make-cache-type))
(category nil)
(name nil)
(methods nil)
(variables nil))
(cl-defstruct (phpinspect-cache-namespace (:constructor phpinspect-make-cache-namespace))
(types nil)
(functions nil))
(cl-defstruct (phpinspect-cache-group (:constructor phpinspect-make-cache-group))
(namespaces (make-hash-table :test #'eq :size 2000 :rehash-size 2.0)))
(eval-and-compile
(defconst phpinspect-cache-types '(interface trait class method type
abstract-method function variable namespace)
"Types of entities that the cache can store.")
(defconst phpinspect-cache-containing-types '(class trait interface)
"Types of entities that the cache can store members for.")
(defconst phpinspect-cache-member-types '(method abstract-method function variable)
"Types of entities that the cache can store as members."))
(defun phpinspect-cache-group-get-namespace (group namespace)
(gethash namespace (phpinspect-cache-group-namespaces group)))
(defun phpinspect-cache-group-get-namespace-create (group namespace)
(or (phpinspect-cache-group-get-namespace group namespace)
(puthash namespace (phpinspect-make-cache-namespace)
(phpinspect-cache-group-namespaces group))))
(defun phpinspect-cache-namespace-get-type-create (namespace type category)
(or (phpinspect-cache-namespace-get-type namespace type category)
(push (cons (phpinspect--type-short-name type)
(phpinspect-make-cache-type :name (phpinspect--type-name-symbol type)
:category category))
(phpinspect-cache-namespace-types namespace))))
(defun phpinspect-cache-namespace-get-type (namespace type category)
(when-let ((entity
(cdr (assq (phpinspect--type-short-name type)
(phpinspect-cache-namespace-types namespace)))))
(and (or (eq 'type category)
(eq category (phpinspect-cache-type-category entity)))
entity)))
(defun phpinspect-cache-namespace-delete-type (namespace type category)
(let ((types (phpinspect-cache-namespace-types namespace))
(name (phpinspect--type-short-name type))
cell-before)
(catch 'break
(while types
(let ((type-cell (car types)))
(when (eq (car type-cell) name)
(when (or (eq 'type category)
(eq category (phpinspect-cache-type-category (cdr type-cell))))
(if cell-before
(setcdr cell-before (cdr types))
(setf (phpinspect-cache-namespace-types namespace) (cdr types)))
(throw 'break (cdr type-cell)))))
(setq cell-before types
types (cdr types))))))
(define-inline phpinspect-cache-query--do-delete (cache group param type member namespace implements extends)
(cl-assert (and (inline-const-p type) (symbolp (inline-const-val type))))
(let ((type (inline-const-val type))
delete-form)
(inline-letevals (group param member namespace implements extends)
(cond
((memq type (cons 'type phpinspect-cache-containing-types))
(if (and (inline-const-p param) (eq '* (inline-const-val param)))
(setq delete-form
(if namespace
(inline-quote
(when-let ((namespace (phpinspect-cache-group-get-namespace ,group ,namespace)))
(let (resultset)
(setf (phpinspect-cache-namespace-types namespace)
(seq-filter
(lambda (type-cell)
(if ,(if (eq type 'type) t `(eq (phpinspect-cache-type-category (cdr type-cell)) (quote ,type)))
(progn (push (cdr type-cell) resultset)
nil)
t))
(phpinspect-cache-namespace-types namespace)))
(cons 'phpinspect-cache-multiresult resultset))))
(inline-quote
(let (resultset)
(dolist (namespace (hash-table-values (phpinspect-cache-group-namespaces ,group)))
(let (new-types)
(dolist (type-cell (phpinspect-cache-namespace-types namespace))
(if ,(if (eq type 'type) t `(eq (phpinspect-cache-type-category (cdr type-cell)) (quote ,type)))
(push (cdr type-cell) resultset)
(push type-cell new-types)))
(setf (phpinspect-cache-namespace-types namespace) new-types)))
(cons 'phpinspect-cache-multiresult resultset)))))
(setq delete-form
(inline-quote
(let* ((namespace (phpinspect-cache-group-get-namespace-create
,group
(or ,namespace (phpinspect--type-namespace ,param)))))
(phpinspect-cache-namespace-delete-type namespace ,param (quote ,type)))))))
(t (inline-error "Delete not supported for entity type %s" type))))
delete-form))
(defun phpinspect-cache-namespace-get-function (namespace func-name)
(cdr (assq func-name (phpinspect-cache-namespace-functions namespace))))
(define-inline phpinspect-cache-query--do-insert (cache group param type member namespace implements extends)
(cl-assert (and (inline-const-p type) (symbolp (inline-const-val type))))
(let ((type (inline-const-val type))
register-form)
(inline-letevals (group param member namespace implements extends)
(cond
((memq type (cons 'type phpinspect-cache-containing-types))
(setq register-form
(inline-quote
(let* ((namespace (phpinspect-cache-group-get-namespace-create
,group
(or ,namespace (phpinspect--type-namespace ,param)))))
(phpinspect-cache-namespace-get-type-create namespace ,param (quote ,type))))))
((and (eq 'function type) (not member))
(setq register-form
(inline-quote
(let ((namespace (phpinspect-cache-group-get-namespace-create
,group (or ,namespace (phpinspect--function-namespace ,param)))))
(or (when-let ((existing (assq (phpinspect--function-name-symbol ,param)
(phpinspect-cache-namespace-functions namespace))))
(setcdr existing ,param))
(cdar (push (cons (phpinspect--function-name-symbol ,param) ,param)
(phpinspect-cache-namespace-functions namespace))))))))
(t (inline-error "Insert not supported for entity type %s" type))))
register-form))
(define-inline phpinspect-cache-query--do-get (cache group param type member namespace implements extends)
(cl-assert (and (inline-const-p type) (symbolp (inline-const-val type))))
(let ((type (inline-const-val type))
get-form)
(inline-letevals (group param member namespace implements extends)
(cond
((memq type (cons 'type phpinspect-cache-containing-types))
(if (and (inline-const-p param) (eq '* (inline-const-val param)))
(setq get-form
(if namespace
(inline-quote
(when-let ((namespace (phpinspect-cache-group-get-namespace ,group ,namespace)))
(cons 'phpinspect-cache-multiresult
(mapcar #'cdr (phpinspect-cache-namespace-types namespace)))))
(inline-quote
(cons 'phpinspect-cache-multiresult
(mapcan (lambda (namespace) (mapcar #'cdr (phpinspect-cache-namespace-types namespace)))
(hash-table-values (phpinspect-cache-group-namespaces ,group)))))))
(setq get-form
(inline-quote
(progn
(when-let* ((namespace (phpinspect-cache-group-get-namespace
,group
(or ,namespace (phpinspect--type-namespace ,param)))))
(phpinspect-cache-namespace-get-type namespace ,param (quote ,type))))))))
((and (eq 'function type) (not member))
(setq get-form
(if ,namespace
(inline-quote
(when-let ((namespace (phpinspect-cache-group-get-namespace ,group ,namespace)))
(phpinspect-cache-namespace-get-function namespace ,param)))
(inline-quote
(let (resultset)
(dolist (namespace (hash-table-values (phpinspect-cache-group-namespaces ,group)))
(when-let ((func (phpinspect-cache-namespace-get-function namespace ,param)))
(push func resultset)))
(cons 'phpinspect-cache-multiresult resultset))))
(t (inline-error "Get not supported for entity type %s" type))))
get-form))
(defmacro phpinspect-cache-query--wrap-action (action cache group param type member namespace implements extends)
(let ((cache-sym (gensym "cache"))
(group-sym (gensym "group"))
(param-sym (gensym "param"))
(member-sym (gensym "member"))
(namespace-sym (gensym "namespace"))
(implements-sym (gensym "implements"))
(extends-sym (gensym "extends")))
`(let ((,param-sym ,param))
(if (and (sequencep ,param-sym) (not (phpinspect-name-p ,param-sym)))
(let* ((,cache-sym ,cache)
(,group-sym ,group)
(,member-sym ,member)
(,namespace-sym ,namespace)
(,implements-sym ,implements)
(,extends-sym ,extends)
(result (cons 'phpinspect-cache-multiresult nil))
(result-rear result))
(seq-doseq (p ,param-sym)
(when-let ((action-result
(,action ,cache-sym ,group-sym p ,type ,member-sym ,namespace-sym ,implements-sym ,extends-sym)))
(setq result-rear
(setcdr result-rear
(cons action-result nil)))))
result)
(,action ,cache ,group ,param ,type ,member ,namespace ,implements ,extends)))))
(defun phpinspect-cache-query--compile-groups (cache group-specs intent)
(cl-assert (phpinspect-cache-p cache))
(let (groups)
(if group-specs
(dolist (spec group-specs)
(cl-assert (listp spec))
(cl-assert (memq (car spec) '(project label))
t "Spec car must be the symbol `project' or `label'")
(let ((group (gethash spec (phpinspect-cache-groups cache))))
(when (and (eq :insert intent) (not group))
(setq group (puthash spec (phpinspect-make-cache-group) (phpinspect-cache-groups cache))))
(push group groups)))
(if (eq :insert intent)
(error "Cannot insert without defining cache group")
(setq groups (hash-table-values (phpinspect-cache-groups cache)))))
groups))
(define-inline phpinspect-cache-transact (cache group-specs &rest query)
(declare (indent 2))
(cl-assert (listp query))
(let (type intent intent-param member namespace implements extends key value)
(condition-case err
(progn
(while (setq key (pop query))
(cl-assert (keywordp key) t "Query keys must be keywords, %s provided" key)
(setq value (pop query))
(cl-assert value t "Key %s has no value" key)
(pcase key
((or :insert :get :delete)
(when intent
(inline-error "Defined duplicate intent: %s, %s" intent key))
(setq intent key
intent-param value))
(:as (cl-assert (and (inline-const-p value)
(memq (inline-const-val value) phpinspect-cache-types))
t ":type must be one of %s" phpinspect-cache-types)
(setq type (inline-const-val value)))
(:member-of (setq member value))
(:in (setq namespace value))
(:implementing (setq implements value))
(:extending (setq extends value))
(_ (error "Unexpected query keyword %s" key))))
;; Query validation
(unless type
(error "Providing entity type with keyword :as is required."))
(when (and member (not (memq type phpinspect-cache-member-types)))
(error "Keyword :member-of can only be used for types %s" phpinspect-cache-member-types))
(when (and extends (not (memq type '(class trait interface type))))
(error "Keyword :extending cannot be used for types other than %s" '(class trait interface)))
(when (eq :insert intent)
(when (and (memq type '(variable method abstract-method)) (not member))
(error "Variable and methods must be member of %s." phpinspect-cache-containing-types))
(when (eq 'type type)
(error ":as 'type cannot be used for insertions.")))
(when (and intent (not intent-param))
(error "Intent %s must have a parameter %s" intent)))
(t (inline-error "phpinspect-cache-transact: %s" err)))
(inline-letevals (group-specs intent-param cache type member namespace implements extends)
(let* ((action-args `(,intent-param (quote ,type) ,member ,namespace ,implements ,extends))
(action (pcase intent
(:insert 'phpinspect-cache-query--do-insert)
(:delete 'phpinspect-cache-query--do-delete)
(:get 'phpinspect-cache-query--do-get)
(_ (inline-error "Invalid intent %s" intent)))))
(inline-quote
(let ((groups (phpinspect-cache-query--compile-groups ,cache ,group-specs ,intent))
resultset)
,(cons 'phpinspect-cache-query--validate (cons intent action-args))
(dolist (group groups)
(when-let ((result ,(cons 'phpinspect-cache-query--wrap-action
(cons action (cons cache (cons 'group action-args))))))
(if (and (listp result) (eq 'phpinspect-cache-multiresult (car result)))
(setq resultset (nconc resultset (cdr result)))
(push result resultset))))
resultset))))))
(defun phpinspect-cache-query--validate (intent intent-param type member namespace implements extends)
(and
;; Validate intent-param
(cond
((phpinspect--type-p intent-param)
(cond
((not (memq type '(class trait interface type)))
(error "Cannot use intent-param of type phpinspect--type when querying for %s" type))
((and (phpinspect--type-fully-qualified intent-param)
namespace)
(error "Use of fully qualified type %s while specifying namespace %s in query"
intent-param namespace)))
t)
((phpinspect-name-p intent-param) t)
((listp intent-param)
(if (memq type '(class trait interface type))
(unless (seq-every-p #'phpinspect--type-p intent-param)
(error "Each intent param must be of type `phpinspect--type'. Got: %s" intent-param))
(pcase intent
(:insert
(unless (or (seq-every-p #'phpinspect--variable-p intent-param)
(seq-every-p #'phpinspect--function-p intent-param))
(error "Each intent param must be an instance of `phpinspect--function' or `phpinspect--variable'")))
(:get
(unless (seq-every-p #'phpinspect-name-p intent-param)
(error "Each intent param must be a name, got: %s" intent-param)))
(:delete
(unless (or (seq-every-p #'phpinspect-name-p intent-param)
(seq-every-p #'phpinspect--variable-p intent-param)
(seq-every-p #'phpinspect--function-p intent-param))
(error "Each intent param must be an instance of `phpinspect--function', `phpinspect--variable' or `phpinspect-name'")))))
t)
((eq '* intent-param)
(unless (memq intent '(:get :delete))
(error "Wildcard '* cannot be used with intent %s" intent)))
((phpinspect--function-p intent-param)
(cond
((not (memq intent '(:insert :delete)))
(error "`phpinspect--function' can only be used as parameter for :insert and :delete intents."))
((not (memq type '(function method abstract-method)))
(error "Inserting/deleting `phpinspect--function' as type %s is not supported" type)))
t)
(t (error "Unsupported intent-param %s" intent-param)))
;; Validate member
(cond
((phpinspect--type-p member) t)
((not member) t)
(t (error "unsupported member type (allowed `phpinspect--type'): %s" member)))
;; Validate namespace
(cond
((phpinspect-name-p namespace) t)
((not namespace) t)
(t (error "unsupported namespace type (allowed `phpinspect-name'): %s" namespace)))
;; Validate implements
(cond
((listp implements)
(unless (seq-every-p #'phpinspect--type-p implements)
(error "Each parameter of :implementing must be of type `phpinspect--type'. Got: %s" implements))
t)
((phpinspect--type-p implements) t)
((not implements) t)
(t (error "unsupported parameter for :implementing (allowed `phpinspect--type': %s" implements)))
;; Validate extends
(cond
((listp extends)
(unless (seq-every-p #'phpinspect--type-or-name-p extends)
(error "Each parameter of :extending must be of type `phpinspect--type'. Got: %s" extends))
t)
((phpinspect--type-p extends) t)
((not extends) t)
(t (error "unsupported parameter for :extending (allowed `phpinspect--type': %s" extends)))))
;;; phpinspect.el ends here
(provide 'phpinspect-cache)

@ -106,9 +106,6 @@ buffer position to insert the use statement at."
buffer namespace-token))
(t (phpinspect-message "No import found for type %s" typename))))))
(defun phpinspect-namespace-part-of-typename (typename)
(string-trim-right typename "\\\\?[^\\]+"))
(defalias 'phpinspect-fix-uses-interactive #'phpinspect-fix-imports
"Alias for backwards compatibility")

@ -55,6 +55,17 @@ that the collection is expected to contain")
`(phpinspect--make-type-generated
,@(phpinspect--wrap-plist-name-in-symbol property-list)))
(defun phpinspect-namespace-part-of-typename (typename)
(string-trim-right typename "\\\\?[^\\]+"))
(defun phpinspect--type-namespace (type)
(phpinspect-intern-name
(phpinspect-namespace-part-of-typename (phpinspect--type-name type))))
(defun phpinspect--type-short-name (type)
(phpinspect-intern-name
(phpinspect--get-bare-class-name-from-fqn (phpinspect--type-name type))))
(defun phpinspect--make-types (type-names)
(mapcar (lambda (name) (phpinspect--make-type :name name))
type-names))
@ -248,6 +259,12 @@ as first element and the type as second element.")
"A phpinspect--type object representing the the
return type of the function."))
(defun phpinspect--function-namespace (func)
(let ((namespace (phpinspect-namespace-part-of-typename (phpinspect--function-name func))))
(when (string= "" namespace)
(setq namespace "\\"))
(phpinspect-intern-name namespace)))
(defmacro phpinspect--make-function (&rest property-list)
`(phpinspect--make-function-generated
,@(phpinspect--wrap-plist-name-in-symbol property-list)))

@ -128,6 +128,12 @@ level of START-FILE in stead of `default-directory`."
(or (gethash name phpinspect-names)
(puthash name name phpinspect-names)))
(define-inline phpinspect-name-p (name)
(inline-letevals (name)
(inline-quote
(and (consp ,name)
(eq 'phpinspect-name (car ,name))))))
(defsubst phpinspect--wrap-plist-name-in-symbol (property-list)
(let ((new-plist)
(wrap-value))

@ -5,12 +5,12 @@ rm *.elc
for file in ./*.el; do
echo 'Compiling '"$file"' ...'
cask emacs -batch -L . --eval '(progn '"(require 'comp)"' (setq byte-compile-error-on-warn t native-compile-target-directory (car native-comp-eln-load-path)) (nreverse native-comp-eln-load-path))' -f batch-byte+native-compile "$file" || break
emacs -batch -L . --eval '(progn '"(require 'comp)"' (setq byte-compile-error-on-warn t native-compile-target-directory (car native-comp-eln-load-path)) (nreverse native-comp-eln-load-path))' -f batch-byte+native-compile "$file" || break
done
for file in ./**/*.el; do
echo 'Compiling '"$file"' ...'
cask emacs -batch -L . --eval '(progn '"(require 'comp)"' (setq byte-compile-error-on-warn t native-compile-target-directory (car native-comp-eln-load-path)) (nreverse native-comp-eln-load-path))' -f batch-byte+native-compile "$file" || break
emacs -batch -L . --eval '(progn '"(require 'comp)"' (setq byte-compile-error-on-warn t native-compile-target-directory (car native-comp-eln-load-path)) (nreverse native-comp-eln-load-path))' -f batch-byte+native-compile "$file" || break
done

@ -0,0 +1,226 @@
; test-cache.el --- Unit tests for phpinspect.el -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 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-cache)
(ert-deftest phpinspect-cache-insert-type ()
(let ((cache (phpinspect-make-cache))
result)
(phpinspect-cache-transact cache '((label test))
:insert (phpinspect--make-type :name "\\TestClass") :as 'class)
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestClass") :as 'class))
(should result)
(should (listp result))
(should (= 1 (length result)))
(should (phpinspect-cache-type-p (car result)))
(phpinspect-cache-transact cache '((label test))
:insert (phpinspect--make-type :name "\\TestInterface") :as 'interface)
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestInterface") :as 'interface))
(should result)
(should (listp result))
(should (= 1 (length result)))
(should (phpinspect-cache-type-p (car result)))
;; When a query defines an entity category other than the one the existing
;; entity was inserted as, nothing should be returned.
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestInterface") :as 'class))
(should-not result)
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestInterface") :as 'type))
(should result)
(setq result
(phpinspect-cache-transact cache '((label test))
:get `(,(phpinspect--make-type :name "\\TestInterface")
,(phpinspect--make-type :name "\\TestClass"))
:as 'type))
(should result)
(should (= 2 (length result)))
(should (seq-every-p #'phpinspect-cache-type-p result))
(setq result
(phpinspect-cache-transact cache '((label test))
:get `(,(phpinspect--make-type :name "\\TestInterface")
,(phpinspect--make-type :name "\\TestClass"))
:as 'interface))
(should result)
(should (= 1 (length result)))
(should (seq-every-p #'phpinspect-cache-type-p result))
(setq result
(phpinspect-cache-transact cache '((label test))
:get '* :as 'type))
(should result)
(should (= 2 (length result)))
(should (seq-every-p #'phpinspect-cache-type-p result))
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestClass") :as 'type))
(should result)
(setq result
(phpinspect-cache-transact cache '((label test))
:delete (phpinspect--make-type :name "\\TestClass") :as 'type))
(should result)
(should (phpinspect-cache-type-p (car result)))
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestClass") :as 'type))
(should-not result)
(setq result
(phpinspect-cache-transact cache '((label test))
:delete (phpinspect--make-type :name "\\TestClass") :as 'type))
(should-not result)
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestInterface") :as 'type))
(should result)
(setq result
(phpinspect-cache-transact cache '((label test))
:delete (phpinspect--make-type :name "\\TestInterface") :as 'class))
(should-not result)
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestInterface") :as 'type))
(should result)
(setq result
(phpinspect-cache-transact cache '((label test))
:delete (phpinspect--make-type :name "\\TestInterface") :as 'interface))
(should result)
(setq result
(phpinspect-cache-transact cache '((label test))
:get (phpinspect--make-type :name "\\TestInterface") :as 'type))
(should-not result)))
(ert-deftest phpinspect-cache-namespace-query ()
(let ((cache (phpinspect-make-cache))
result)
(phpinspect-cache-transact cache '((label test))
:insert (list (phpinspect--make-type :name "\\Namespace1\\TestClass")
(phpinspect--make-type :name "\\Namespace2\\TestClass")
(phpinspect--make-type :name "\\Namespace2\\TestClass1"))
:as 'class)
(setq result (phpinspect-cache-transact cache '((label test))
:get '* :as 'class :in (phpinspect-intern-name "\\Namespace1")))
(should result)
(should (= 1 (length result)))
(should (eq (phpinspect-intern-name "\\Namespace1\\TestClass")
(phpinspect-cache-type-name (car result))))
(setq result (phpinspect-cache-transact cache '((label test))
:get '* :as 'class :in (phpinspect-intern-name "\\Namespace2")))
(should result)
(should (= 2 (length result)))))
(ert-deftest phpinspect-cache-delete-wildcard-types ()
(let ((cache (phpinspect-make-cache))
result)
(phpinspect-cache-transact cache '((label test))
:insert (list (phpinspect--make-type :name "\\Namespace1\\TestClass")
(phpinspect--make-type :name "\\Namespace2\\TestClass")
(phpinspect--make-type :name "\\Namespace2\\TestClass1"))
:as 'class)
(phpinspect-cache-transact cache '((label test))
:delete '* :as 'class)
(should-not (phpinspect-cache-transact cache '((label test))
:get '* :as 'class))))
(ert-deftest phpinspect-cache-delete-wildcard-namespace-types ()
(let ((cache (phpinspect-make-cache))
result)
(phpinspect-cache-transact cache '((label test))
:insert (list (phpinspect--make-type :name "\\Namespace1\\TestClass")
(phpinspect--make-type :name "\\Namespace2\\TestClass")
(phpinspect--make-type :name "\\Namespace2\\TestClass1"))
:as 'class)
(phpinspect-cache-transact cache '((label test))
:delete '* :as 'class :in (phpinspect-intern-name "\\Namespace2"))
(setq result (phpinspect-cache-transact cache '((label test)) :get '* :as 'class))
(should result)
(should (= 1 (length result)))
(should (eq (phpinspect-intern-name "\\Namespace1\\TestClass")
(phpinspect-cache-type-name (car result))))))
(ert-deftest phpinspect-cache-insert-function ()
(let ((cache (phpinspect-make-cache))
result)
(setq result (phpinspect-cache-transact cache '((label test))
:insert (phpinspect--make-function :name "test_func")
:as 'function))
(should result)
(should (phpinspect--function-p (car result)))
(should (= 1 (length result)))
(setq result (phpinspect-cache-transact cache '((label test))
:get (phpinspect-intern-name "test_func")
:as 'function))
(should result)
(should (phpinspect--function-p (car result)))
(should (= 1 (length result)))
(setq result (phpinspect-cache-transact cache '((label test))
:delete (phpinspect-intern-name "test_func")
:as 'function))
(should (phpinspect--function-p (car result)))
(should (= 1 (length result)))))
Loading…
Cancel
Save