From 4c9de6677e43a6bc071c9c08649f0ed17cdb1750 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 23 Jun 2024 12:18:41 -0500 Subject: [PATCH] Fix testing of nested objects --- t/activity-vocabulary.lisp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/t/activity-vocabulary.lisp b/t/activity-vocabulary.lisp index 0b7d3e3..48126f3 100644 --- a/t/activity-vocabulary.lisp +++ b/t/activity-vocabulary.lisp @@ -60,15 +60,23 @@ ensuring they are semantically equivalent. White-space and key order are ignored (lambda (cell-a cell-b) (apply predicate (list (car cell-a) (car cell-b)))))) +(defun ensure-list (item) + "Ensure ITEM is either a list or the sole member of a new list." + (if (listp item) + item + (list item))) + (defun hash-table-sorted-alist (table &optional (predicate #'string<)) "Return a sorted associative list containing the keys and values of TABLE. Any nested hash-tables found as values are also sorted, recursively." (sort-alist (mapcar (lambda (cell) (cons (car cell) - (if (hash-table-p (cdr cell)) - (hash-table-sorted-alist (cdr cell)) - (cdr cell)))) + (mapcar (lambda (cell-item) + (if (hash-table-p cell-item) + (hash-table-sorted-alist cell-item) + cell-item)) + (ensure-list (cdr cell))))) (alexandria:hash-table-alist table)) predicate))