From 4007e8daca4d960c91ba38d5ee4778dbab5b0020 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 15 Apr 2023 13:33:58 +0100 Subject: 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. --- tests/issue.scm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'tests') 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 +;;; Copyright © 2022, 2023 Arun Isaac ;;; ;;; 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)))) + (stringstring key1) + (maybe-symbol->string key2)))))))) (test-begin "issue") -- cgit v1.2.3