Skip to content

Commit

Permalink
Properly merge autoload entries
Browse files Browse the repository at this point in the history
fixes #19
  • Loading branch information
Steven Rémot committed Feb 21, 2017
1 parent ed0bbff commit dcaaf15
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
27 changes: 26 additions & 1 deletion ede-php-autoload-composer.el
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,31 @@ BASE-DIR is the prefix dir to add to each autoload path."

autoloads))

(defun ede-php-autoload-composer--merge-autoload-paths (base-paths new-paths)
"Merge two paths in a autoload file in one.
BASE-PATHS and NEW-PATHS are either string opr list of strings.
It will output a list of strings with each of base and new paths in it."
(let ((list-base-path (if (stringp base-paths) (list base-paths) base-paths))
(list-new-paths (if (stringp new-paths) (list new-paths) new-paths)))
(append list-base-path list-new-paths)))

(defun ede-php-autoload-composer--merge-autoload-entries (base-entries new-entries)
"Merge two autoload entries (right after the autoload entry).
BASE-ENTRIES and NEW-ENTRIES are the entries to merge."
(let ((current-entries base-entries)
pair
pair-path)
(cl-loop for (ns . paths) in new-entries do
(setq pair (assoc ns current-entries)
pair-path (cdr pair))
(if pair
(setf (cdr pair) (ede-php-autoload-composer--merge-autoload-paths pair-path paths))
(setq current-entries (push (cons ns paths) current-entries))))
current-entries))

(defun ede-php-autoload-composer-merge-autoloads (base-autoloads new-autoloads)
"Merge two internal autoload definitions in one.
Expand All @@ -156,7 +181,7 @@ NEW-AUTOLOADS will be merged into BASE-AUTOLOADS. BASE-AUTOLOADS will be mutate

autoloads (plist-put autoloads
key
(append
(ede-php-autoload-composer--merge-autoload-entries
(plist-get autoloads key)
value))

Expand Down
20 changes: 16 additions & 4 deletions test/ede-php-autoload-composer-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@
'(:psr-0 (("Test" . "test/")) :psr-4 (("Test3" . "test3/")))
'(:psr-0 (("Test2" . "test2/")) :psr-4 (("Test4" . "test4/"))))

'(:psr-0 (("Test" . "test/")
("Test2" . "test2/"))
:psr-4 (("Test3" . "test3/")
("Test4" . "test4/"))))))
'(:psr-0 (("Test2" . "test2/")
("Test" . "test/"))
:psr-4 (("Test4" . "test4/")
("Test3" . "test3/"))))))

(ert-deftest ede-php-autoload-composer-merge-autoloads-concats-files-merged-part ()
"`ede-php-autoload-composer-merge-autoloads' should merge paths with the same key."
(should (equal

(ede-php-autoload-composer-merge-autoloads
'(:psr-0 (("Test" . "test/")) :psr-4 (("Test3" . "test3/")))
'(:psr-0 (("Test" . "test2/")) :psr-4 (("Test4" . "test4/"))))

'(:psr-0 (("Test" . ("test/" "test2/")))
:psr-4 (("Test4" . "test4/")
("Test3" . "test3/"))))))

(ert-deftest ede-php-autoload-composer-define-visitor ()
"`:define-visitors' should define a visitor according to its step."
Expand Down

0 comments on commit dcaaf15

Please sign in to comment.