core: make-hash-table: Fix optional argument.

* src/hash.c (make_hash_table): Fix optional argument.
* src/builtins.c (mes_builtins): Update arity.
* tests/hash.test: New file.
* build-aux/check-mes.sh (TESTS): Add it.

Co-authored-by: Timothy Sample <samplet@ngyro.com>
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2019-11-10 11:12:03 +01:00 committed by Timothy Sample
parent 013c40d165
commit fb0b01e904
4 changed files with 41 additions and 2 deletions

View File

@ -38,6 +38,7 @@ tests/display.test
tests/cwv.test
tests/math.test
tests/vector.test
tests/hash.test
tests/srfi-1.test
tests/srfi-9.test
tests/srfi-13.test

View File

@ -180,7 +180,7 @@ mes_builtins (struct scm *a) /*:((internal)) */
a = init_builtin (builtin_type, "hashq-set!", 3, &hashq_set_x, a);
a = init_builtin (builtin_type, "hash-set!", 3, &hash_set_x, a);
a = init_builtin (builtin_type, "hash-table-printer", 1, &hash_table_printer, a);
a = init_builtin (builtin_type, "make-hash-table", 1, &make_hash_table, a);
a = init_builtin (builtin_type, "make-hash-table", -1, &make_hash_table, a);
/* src/lib.c */
a = init_builtin (builtin_type, "core:type", 1, &type_, a);
a = init_builtin (builtin_type, "core:car", 1, &car_, a);

View File

@ -205,11 +205,12 @@ make_hash_table_ (long size)
}
struct scm *
make_hash_table (struct scm *x)
make_hash_table (struct scm *x) /*:((arity . n)) */
{
long size = 0;
if (x->type == TPAIR)
{
x = x->car;
assert_msg (x->type == TNUMBER, "x->type == TNUMBER");
size = x->value;
}

37
tests/hash.test Executable file
View File

@ -0,0 +1,37 @@
#! /bin/sh
# -*-scheme-*-
exec ${MES-bin/mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests hash)' -s "$0" "$@"
!#
;;; -*-scheme-*-
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2022 Timothy Sample <samplet@ngyro.com>
;;;
;;; This file is part of GNU Mes.
;;;
;;; GNU Mes is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Mes is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Mes. If not, see <https://www.gnu.org/licenses/>.
(define-module (tests hash)
#:use-module (mes test))
(cond-expand
(mes
(mes-use-module (mes test)))
(else))
(pass-if "make-hash-table" (make-hash-table))
(pass-if "make-hash-table with size" (make-hash-table 10))
(result 'report)