branch: elpa/loopy-dash
commit a05a48768d30278949fb963153ea2bcd388c68b6
Author: okamsn <[email protected]>
Commit: GitHub <[email protected]>
Copy other testing and packaging files from the original repo. (#2)
Add:
- .elpaignore
- .dir-locals.el
- Issue template
- test files for the Dash features
- GitHub Actions workflow
---
.elpaignore | 7 +
.github/ISSUE_TEMPLATE/bug_report.md | 29 ++++
.github/workflows/emacs-matrix-tests.yml | 52 +++++++
tests/dash-tests.el | 223 +++++++++++++++++++++++++++++++
tests/install-script.el | 8 ++
tests/load-path.el | 9 ++
6 files changed, 328 insertions(+)
diff --git a/.elpaignore b/.elpaignore
new file mode 100644
index 0000000000..529e81d1b1
--- /dev/null
+++ b/.elpaignore
@@ -0,0 +1,7 @@
+tests
+Makefile
+.git
+.github
+.gitignore
+.elpaignore
+.dir-locals.el
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md
b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000000..070f8769ac
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,29 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+Suggested content:
+
+- Problem
+- Code used to produce problem
+- Emacs version
+
+If you have problems running the macro, please include the expanded code, such
as with the command `pp-macroexpand-last-sexp` or the below command
+
+``` elisp
+(defun my-pp-macroexpand-all-last-sexp (arg)
+ "Like `pp-macroexpand-last-sexp', but use `macroexpand-all'.
+With ARG, print into current buffer."
+ (interactive "P")
+ (if arg
+ (insert (pp-to-string (macroexpand-all (pp-last-sexp))))
+ (pp-display-expression (macroexpand-all (pp-last-sexp))
+ "*Pp Macroexpand Output*")))
+```
+
+though the first is usually good enough.
diff --git a/.github/workflows/emacs-matrix-tests.yml
b/.github/workflows/emacs-matrix-tests.yml
new file mode 100644
index 0000000000..fc96394f3d
--- /dev/null
+++ b/.github/workflows/emacs-matrix-tests.yml
@@ -0,0 +1,52 @@
+name: Test Emacs Matrix
+on:
+ push:
+ branches:
+ - main
+ - master
+ pull_request:
+ branches:
+ - main
+ - master
+jobs:
+ test:
+ name: 'Install and Test'
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ emacs-version:
+ - '27.2'
+ - '28.2'
+ - '29.4'
+ - 'release-snapshot'
+ # - 'snapshot'
+ steps:
+ - uses: actions/checkout@v3
+ - uses: purcell/setup-emacs@master
+ with:
+ version: ${{ matrix.emacs-version }}
+ - run: echo "💡 The ${{ github.repository }} repository has been cloned to
the runner."
+ - run: echo "🖥️ The workflow is now ready to test your code on the runner."
+ - name: Print working directory
+ run: echo "Current working directory is $PWD"
+ - name: List files in the repository
+ run: |
+ ls ${{ github.workspace }}
+ - name: Make config dir to guaranteed location. Do it before we run Emacs
the first time.
+ run: mkdir ~/.emacs.d
+ - name: Check Emacs version
+ run: emacs --version
+ - name: Clone package Loopy to sub-folder
+ run: |
+ git clone 'https://github.com/okamsn/loopy.git' ./loopy
+ ls ./loopy
+ - name: Copy package Loopy to sub-sub-folder
+ run: |
+ mkdir --verbose ./loopy/loopy
+ cp --verbose --target-directory=./loopy/loopy ./loopy/*.el
+ ls ./loopy/loopy
+ - name: Install packages
+ run: emacs -batch -l tests/install-script.el
+ - name: Dash tests
+ run: emacs -batch -l tests/load-path.el -l ert -l tests/dash-tests.el -f
ert-run-tests-batch-and-exit
+ - run: echo "🍏 This job's status is ${{ job.status }}."
diff --git a/tests/dash-tests.el b/tests/dash-tests.el
new file mode 100644
index 0000000000..d2782e1a95
--- /dev/null
+++ b/tests/dash-tests.el
@@ -0,0 +1,223 @@
+;; -*- lexical-binding: t; -*-
+;; Run these tests from project dir using:
+;; emacs -Q --batch -l ert -l tests.el -f ert-run-tests-batch-and-exit
+
+(require 'cl-lib)
+(require 'ert)
+(require 'loopy)
+(require 'loopy-dash)
+
+(ert-deftest dash-flag-default ()
+ (should (equal '(5 6)
+ (let ((loopy-default-flags '(dash)))
+ (eval (quote (loopy (list (&plist :a a :b b)
+ '((:a 3 :b 4) (:a 5 :b 6)))
+ (finally-return a b))))))))
+
+(ert-deftest dash-flag-list-destructuring ()
+ (should (equal '(1 2)
+ (eval (quote (loopy (flag dash)
+ (list (i) '((1) (2)))
+ (collect i))))))
+
+ (should (equal '(((1) 1) ((2) 2))
+ (eval (quote (loopy (flag dash)
+ (list (whole &as i) '((1) (2)))
+ (collect (list whole i)))))))
+
+ (should (equal '((1 2) (3 4))
+ (eval (quote (loopy (flag dash)
+ (list (i j) '((1 2) (3 4)))
+ (collect (list i j)))))))
+
+ (should (equal '((1 2) (3 4))
+ (eval (quote (loopy (flag dash)
+ (list (i . j) '((1 . 2) (3 . 4)))
+ (collect (list i j))))))))
+
+(ert-deftest dash-flag-array-destructuring ()
+ (should (equal '((1 2 3))
+ (eval (quote (loopy (flag dash)
+ (list [i j k] '([1 2 3]))
+ (collect (list i j k)))))))
+
+ (should (equal '((1 [2 3]))
+ (eval (quote (loopy (flag dash)
+ (list [i &rest j] '([1 2 3]))
+ (collect (list i j))))))))
+
+(ert-deftest dash-flag-default-disable ()
+ :expected-result :failed
+ (should (equal '(5 6)
+ (let ((loopy-default-flags '(dash)))
+ (eval (quote (loopy (flag -dash)
+ (list (&plist :a a :b b)
+ '((:a 3 :b 4) (:a 5 :b 6)))
+ (finally-return a b))))))))
+
+(ert-deftest dash-flag-enable-disable ()
+ :expected-result :failed
+ (should (equal '(5 6)
+ (eval (quote (loopy (flag dash -dash)
+ (list (&plist :a a :b b)
+ '((:a 3 :b 4) (:a 5 :b 6)))
+ (finally-return a b)))))))
+
+
+(ert-deftest dash-with-destructuring ()
+ (should (= 7 (eval (quote (loopy (flag dash)
+ (with ((&plist :a a :b b) '(:a 3 :b 4)))
+ (repeat 1)
+ (return (+ a b))))))))
+
+;; Make sure all variables for the needed settings are properly bound.
+(ert-deftest destructuring-settings-not-escape ()
+ (eval (quote (loopy (flag dash) (repeat 0))))
+ (should-not loopy--destructuring-for-with-vars-function)
+ (should-not loopy--destructuring-for-iteration-function)
+ (should-not loopy--destructuring-accumulation-parser))
+
+(ert-deftest dash-alist-iteration-destructuring ()
+ (should (equal '(1 2 3 4)
+ (eval (quote (loopy (flag dash)
+ (list (&alist 'a avar 'b bvar)
+ '(((a . 1) (b . 2))
+ ((a . 3) (b . 4))))
+ (collect avar)
+ (collect bvar))))))
+
+ (should (equal '(1 2 3 4)
+ (eval (quote (loopy (flag dash)
+ (list (&alist 'a 'b)
+ '(((a . 1) (b . 2))
+ ((a . 3) (b . 4))))
+ (collect a)
+ (collect b))))))
+
+ (should (equal '(1 2 3 4)
+ (eval (quote (loopy (flag dash)
+ (list (&alist :a :b)
+ '(((:a . 1) (:b . 2))
+ ((:a . 3) (:b . 4))))
+ (collect a)
+ (collect b))))))
+
+ (should (equal '(1 2 3 4)
+ (eval (quote (loopy (flag dash)
+ (list (&alist "a" "b")
+ '((("a" . 1) ("b" . 2))
+ (("a" . 3) ("b" . 4))))
+ (collect a)
+ (collect b)))))))
+
+(ert-deftest dash-alist-accumulation-destructuring ()
+ (should (equal '((1 3) (2 4))
+ (eval (quote (loopy (flag dash)
+ (list elem
+ '(((a . 1) (b . 2))
+ ((a . 3) (b . 4))))
+ (collect (&alist 'a avar 'b bvar) elem)
+ (finally-return avar bvar))))))
+
+ (should (equal '((1 3) (2 4))
+ (eval (quote (loopy (flag dash)
+ (list elem
+ '(((a . 1) (b . 2))
+ ((a . 3) (b . 4))))
+ (collect (&alist 'a 'b) elem)
+ (finally-return a b))))))
+
+ (should (equal '((1 3) (2 4))
+ (eval (quote (loopy (flag dash)
+ (list elem
+ '(((:a . 1) (:b . 2))
+ ((:a . 3) (:b . 4))))
+ (collect (&alist :a :b) elem)
+ (finally-return a b))))))
+
+ (should (equal '((1 3) (2 4))
+ (eval (quote (loopy (flag dash)
+ (list elem
+ '((("a" . 1) ("b" . 2))
+ (("a" . 3) ("b" . 4))))
+ (collect (&alist "a" "b") elem)
+ (finally-return a b)))))))
+
+(ert-deftest dash-plist-iteration-destructuring ()
+ (should (equal '(1 2 3 4)
+ (eval (quote (loopy (flag dash)
+ (list (&plist 'a avar 'b bvar)
+ '((a 1 b 2) (a 3 b 4)))
+ (collect avar)
+ (collect bvar))))))
+
+ (should (equal '(1 2 3 4)
+ (eval (quote (loopy (flag dash)
+ (list (&plist 'a 'b)
+ '((a 1 b 2) (a 3 b 4)))
+ (collect a)
+ (collect b))))))
+
+ (should (equal '(1 2 3 4)
+ (eval (quote (loopy (flag dash)
+ (list (&plist :a :b)
+ '((:a 1 :b 2) (:a 3 :b 4)))
+ (collect a)
+ (collect b))))))
+
+ ;; NOTE: This test won't work, since `plist-get' uses `eq', which fails for
+ ;; lists.
+ ;;
+ ;; (should (equal '((1 3) (2 4))
+ ;; (eval (quote (loopy (flag dash)
+ ;; (accum-opt a b)
+ ;; (list elem '(("a" 1 "b" 2) ("a" 3 "b"
4)))
+ ;; (collect (&plist "a" "b") elem)
+ ;; (finally-return a b))))))
+ )
+
+(ert-deftest dash-plist-accumulation-destructuring ()
+ (should (equal '((1 3) (2 4))
+ (eval (quote (loopy (flag dash)
+ (list elem '((a 1 b 2) (a 3 b 4)))
+ (collect (&plist 'a avar 'b bvar) elem)
+ (finally-return avar bvar))))))
+
+ (should (equal '((1 3) (2 4))
+ (eval (quote (loopy (flag dash)
+ (list elem '((a 1 b 2) (a 3 b 4)))
+ (collect (&plist 'a 'b) elem)
+ (finally-return a b))))))
+
+ (should (equal '((1 3) (2 4))
+ (eval (quote (loopy (flag dash)
+ (list elem '((:a 1 :b 2) (:a 3 :b 4)))
+ (collect (&plist :a :b) elem)
+ (finally-return a b))))))
+
+ ;; NOTE: This test won't work, since `plist-get' uses `eq', which fails for
+ ;; lists.
+ ;;
+ ;; (should (equal '((1 3) (2 4))
+ ;; (eval (quote (loopy (flag dash)
+ ;; (accum-opt a b)
+ ;; (list elem '(("a" 1 "b" 2) ("a" 3 "b"
4)))
+ ;; (collect (&plist "a" "b") elem)
+ ;; (finally-return a b))))))
+ )
+
+;; Just trying things.
+(ert-deftest dash-random-destructurings ()
+ (should (equal '((1 6) (2 7) (3 8) (4 10) (5 9))
+ (loopy (flag dash)
+ (array elem [(1 2 3 :k1 4 :k2 5)
+ (6 7 8 :k2 9 :k1 10)])
+ (collect (a b c &plist :k1 :k2) elem)
+ (finally-return a b c k1 k2))))
+
+ (should (equal '((1 6) (3 8) (4 10) (5 9))
+ (loopy (flag dash)
+ (array elem [(1 2 3 (:k1 . 4) (:k2 . 5))
+ (6 7 8 (:k2 . 9) (:k1 . 10))])
+ (collect (a _ c &alist :k1 :k2) elem)
+ (finally-return a c k1 k2)))))
diff --git a/tests/install-script.el b/tests/install-script.el
new file mode 100644
index 0000000000..c9c9ef5503
--- /dev/null
+++ b/tests/install-script.el
@@ -0,0 +1,8 @@
+(setq package-user-dir "~/.emacs.d/elpa")
+(message "Current directory: %s" default-directory)
+(require 'package)
+(package-refresh-contents)
+(message "\nInstall main package from directory:\n")
+(package-install-file (expand-file-name "loopy/loopy/" default-directory))
+(message "\nInstall from file:\n")
+(package-install-file (expand-file-name "loopy-dash.el" default-directory))
diff --git a/tests/load-path.el b/tests/load-path.el
new file mode 100644
index 0000000000..69221f0a89
--- /dev/null
+++ b/tests/load-path.el
@@ -0,0 +1,9 @@
+;; Add installed packages to load path.
+;; Don't use Seq, as we want to load the right version.
+(require 'cl-lib)
+(let ((dir (expand-file-name (if (require 'package nil t)
+ package-user-dir
+ "~/.emacs.d/elpa"))))
+ (cl-loop for i in (directory-files-recursively dir "" t)
+ when (file-directory-p i)
+ do (add-to-list 'load-path i)))