about summary refs log tree commit diff
path: root/users/wpcarro
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro')
-rw-r--r--users/wpcarro/emacs/pkgs/vector/default.nix21
-rw-r--r--users/wpcarro/emacs/pkgs/vector/tests.el20
-rw-r--r--users/wpcarro/emacs/pkgs/vector/vector.el (renamed from users/wpcarro/emacs/.emacs.d/wpc/vector.el)26
3 files changed, 41 insertions, 26 deletions
diff --git a/users/wpcarro/emacs/pkgs/vector/default.nix b/users/wpcarro/emacs/pkgs/vector/default.nix
new file mode 100644
index 000000000000..c0a475aaaa82
--- /dev/null
+++ b/users/wpcarro/emacs/pkgs/vector/default.nix
@@ -0,0 +1,21 @@
+{ pkgs, depot, ... }:
+
+let
+  vector = pkgs.callPackage
+    ({ emacsPackages }:
+      emacsPackages.trivialBuild {
+        pname = "vector";
+        version = "1.0.0";
+        src = ./vector.el;
+      })
+    { };
+
+  emacs = (pkgs.emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ vector ]);
+in
+vector.overrideAttrs (_old: {
+  doCheck = true;
+  checkPhase = ''
+    ${emacs}/bin/emacs -batch \
+      -l ert -l ${./tests.el} -f ert-run-tests-batch-and-exit
+  '';
+})
diff --git a/users/wpcarro/emacs/pkgs/vector/tests.el b/users/wpcarro/emacs/pkgs/vector/tests.el
new file mode 100644
index 000000000000..ffa983188229
--- /dev/null
+++ b/users/wpcarro/emacs/pkgs/vector/tests.el
@@ -0,0 +1,20 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Dependencies
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(require 'ert)
+(require 'vector)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Tests
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(ert-deftest vector-misc-tests ()
+  (let ((xs [1 2 3])
+        (ys [1 2 3]))
+    (should (= 1 (vector-get 0 ys)))
+    (vector-set 0 4 ys)
+    (should (= 1 (vector-get 0 ys)))
+    (should (= 1 (vector-get 0 xs)))
+    (vector-set! 0 4 xs)
+    (should (= 4 (vector-get 0 xs)))))
diff --git a/users/wpcarro/emacs/.emacs.d/wpc/vector.el b/users/wpcarro/emacs/pkgs/vector/vector.el
index 6b89708cefcc..87f38d7d93e2 100644
--- a/users/wpcarro/emacs/.emacs.d/wpc/vector.el
+++ b/users/wpcarro/emacs/pkgs/vector/vector.el
@@ -22,25 +22,14 @@
 
 ;;; Code:
 
-;; TODO: Consider supporting an alias named tuple for vector.
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Library
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defconst vector-enable-tests? t
-  "When t, run the tests defined herein.")
-
-;; TODO: Consider labelling variadic functions like `vector-concat*'
-;; vs. `vector-concat'.
 (defun vector-concat (&rest args)
   "Return a new vector composed of all vectors in `ARGS'."
   (apply #'vconcat args))
 
-;; TODO: Here's a sketch of a protocol macro being consumed.
-;; (definstance monoid vector
-;;   :empty (lambda () []))
-
 (defun vector-prepend (x xs)
   "Add `X' to the beginning of `XS'."
   (vector-concat `[,x] xs))
@@ -65,20 +54,5 @@ Returns a copy of `XS' with the updates."
 This function mutates XS."
   (aset xs i v))
 
-(when vector-enable-tests?
-  (let ((xs [1 2 3])
-        (ys [1 2 3]))
-    (prelude-assert (= 1 (vector-get 0 ys)))
-    (vector-set 0 4 ys)
-    (prelude-assert (= 1 (vector-get 0 ys)))
-    (prelude-assert (= 1 (vector-get 0 xs)))
-    (vector-set! 0 4 xs)
-    (prelude-assert (= 4 (vector-get 0 xs)))))
-
-;; TODO: Decide between "remove" and "delete" as the appropriate verbs.
-;; TODO: Implement this.
-;; (defun vector/delete (i xs)
-;;   "Remove the element at `I' in `XS'.")
-
 (provide 'vector)
 ;;; vector.el ends here