diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-12-07 22:27:35 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-12-07 22:27:35 +0100 |
commit | a1ef85b5fab8dea3f9d2144102079de198d8ee3e (patch) | |
tree | 071aef7dc5eb9a8584aa62f5f181bf2040b3b808 | |
parent | 9142bb19726b62492e2f4c6ecb8bc7a5fe9b712f (diff) | |
download | mew-a1ef85b5fab8dea3f9d2144102079de198d8ee3e.tar.gz mew-a1ef85b5fab8dea3f9d2144102079de198d8ee3e.tar.xz mew-a1ef85b5fab8dea3f9d2144102079de198d8ee3e.zip |
add hash-table record printer
-rw-r--r-- | mew.scm | 8 | ||||
-rw-r--r-- | tests/test.mew | 5 |
2 files changed, 12 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm index 917ce6c..a6ac371 100644 --- a/mew.scm +++ b/mew.scm @@ -1181,6 +1181,14 @@ (str (substring old-prompt 0 2) "^_^;" (substring old-prompt 2)))))) + (set-record-printer! 'hash-table + (lambda (h out) + (format out "#<hash-table") + (if (< 0 (hash-table-size h) 100) + (hash-table-for-each h (lambda (k v) + (format out " (~s . ~s)" k v))) + (format out " (~a)" (hash-table-size h))) + (format out ">"))) (set-pseudo-random-seed! (random-bytes)) ) diff --git a/tests/test.mew b/tests/test.mew index 589b63e..1fe7ec1 100644 --- a/tests/test.mew +++ b/tests/test.mew @@ -329,7 +329,10 @@ (test-assert (hash-table? (tbl 1 2 3 4))) (test 0 (hash-table-size (tbl))) (test 42 (get (tbl 1 2 3 42) 3)) - (test-error (tbl 1 2 3))) + (test-error (tbl 1 2 3)) + + (test "#<hash-table (0)>" (format "~a" (tbl))) + (test "#<hash-table (42 . \"foo\")>" (format "~a" (tbl 42 "foo")))) (test-group "set-at" (test #(0 42 0) (set-at #(0 0 0) 1 42)) |