diff options
author | Arun Isaac | 2023-04-15 13:33:58 +0100 |
---|---|---|
committer | Arun Isaac | 2023-04-15 13:33:58 +0100 |
commit | 4007e8daca4d960c91ba38d5ee4778dbab5b0020 (patch) | |
tree | 885435eaf4c5860737d00e77c94b421e5ac2abde | |
parent | dab45c2753089898214abebf4840267264b53a19 (diff) | |
download | tissue-4007e8daca4d960c91ba38d5ee4778dbab5b0020.tar.gz tissue-4007e8daca4d960c91ba38d5ee4778dbab5b0020.tar.lz tissue-4007e8daca4d960c91ba38d5ee4778dbab5b0020.zip |
tests: Sort alist entries after converting hashtable.
The order of entries in an association list is insignificant. Sorting
association list entries prevents tests from breaking simply because
the order of the entries is different.
* tests/issue.scm: Import (ice-9 match).
(hashtable->alist): Sort alist entries after converting
hashtable. Document this in the docstring.
-rw-r--r-- | tests/issue.scm | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tests/issue.scm b/tests/issue.scm index 22982db..db2595f 100644 --- a/tests/issue.scm +++ b/tests/issue.scm @@ -1,5 +1,5 @@ ;;; tissue --- Text based issue tracker -;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net> +;;; Copyright © 2022, 2023 Arun Isaac <arunisaac@systemreboot.net> ;;; ;;; This file is part of tissue. ;;; @@ -19,6 +19,7 @@ (import (rnrs hashtables) (srfi srfi-64) (srfi srfi-71) + (ice-9 match) (tissue issue)) (define hashtable-prepend! @@ -31,10 +32,20 @@ (@@ (tissue issue) file-details)) (define (hashtable->alist hashtable) + "Convert @var{hashtable} to association list with keys sorted as +strings." (let ((keys values (hashtable-entries hashtable))) - (map cons - (vector->list keys) - (vector->list values)))) + (sort (map cons + (vector->list keys) + (vector->list values)) + (match-lambda* + (((key1 . _) (key2 . _)) + (let ((maybe-symbol->string (lambda (x) + (if (symbol? x) + (symbol->string x) + x)))) + (string<? (maybe-symbol->string key1) + (maybe-symbol->string key2)))))))) (test-begin "issue") |