2016-10-16 15:34:51 +00:00
|
|
|
#! /bin/sh
|
|
|
|
# -*-scheme-*-
|
2017-03-26 19:06:19 +00:00
|
|
|
MES=${MES-$(dirname $0)/../scripts/mes}
|
|
|
|
echo ' ()' | cat $(dirname $0)/../module/mes/base-0.mes $0 /dev/stdin | $MES $MES_FLAGS "$@"
|
2016-10-16 15:34:51 +00:00
|
|
|
#paredit:||
|
|
|
|
exit $?
|
|
|
|
!#
|
|
|
|
|
2016-07-09 11:23:58 +00:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
|
|
|
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
;;;
|
2016-12-07 19:26:41 +00:00
|
|
|
;;; This file is part of Mes.
|
2016-07-09 11:23:58 +00:00
|
|
|
;;;
|
|
|
|
;;; 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.
|
|
|
|
;;;
|
|
|
|
;;; 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 Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-10-12 21:40:11 +00:00
|
|
|
(mes-use-module (mes scm))
|
2016-12-07 19:26:41 +00:00
|
|
|
(mes-use-module (srfi srfi-0))
|
2016-10-12 21:40:11 +00:00
|
|
|
(mes-use-module (mes test))
|
|
|
|
|
2016-07-18 20:43:16 +00:00
|
|
|
(pass-if "first dummy" #t)
|
|
|
|
(pass-if-not "second dummy" #f)
|
|
|
|
|
2016-07-25 12:39:56 +00:00
|
|
|
(pass-if "when" (seq? (when #t 'true) 'true))
|
|
|
|
(pass-if "when 2" (seq? (when #f 'true) *unspecified*))
|
2016-07-18 20:43:16 +00:00
|
|
|
|
2016-07-18 20:52:12 +00:00
|
|
|
(pass-if "map" (sequal? (map identity '(1 2 3 4)) '(1 2 3 4)))
|
|
|
|
(pass-if "map 2 " (sequal? (map (lambda (i a) (cons i a)) '(1 2 3 4) '(a b c d))
|
2016-07-24 10:40:44 +00:00
|
|
|
'((1 . a) (2 . b) (3 . c) (4 . d))))
|
|
|
|
(pass-if "for-each" (sequal? (let ((acc '())) (for-each (lambda (x) (set! acc (cons x acc))) '(1 2 3 4)) acc) '(4 3 2 1)))
|
2016-07-18 20:43:16 +00:00
|
|
|
(define xxxa 0)
|
2016-07-18 20:52:12 +00:00
|
|
|
(pass-if "set! " (seq? (begin (set! xxxa 1) xxxa) 1))
|
|
|
|
(pass-if "set! 2" (seq? (let ((a 0)) (set! a 1) a) 1))
|
2016-07-25 12:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
(pass-if "list-ref" (seq? (list-ref '(0 1 2) 1) 1))
|
|
|
|
|
|
|
|
(pass-if "do" (sequal? (let ((acc '())) (do ((i 0 (+ i 1))) ((>= i 3)) (set! acc (cons i acc))) acc) '(2 1 0)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-25 23:14:28 +00:00
|
|
|
(pass-if-equal "string-length"
|
|
|
|
0
|
|
|
|
(string-length ""))
|
|
|
|
(pass-if-equal "string-length 2"
|
|
|
|
3
|
|
|
|
(string-length (string-append "a" "b" "c")))
|
|
|
|
(pass-if-equal "string->list"
|
|
|
|
'()
|
|
|
|
(string->list ""))
|
|
|
|
(pass-if-equal "string->list 2"
|
|
|
|
'(#\a #\b #\c #\newline)
|
|
|
|
(string->list "abc\n"))
|
|
|
|
|
2016-07-18 20:52:12 +00:00
|
|
|
(pass-if "string-append" (sequal? (string-append "a" "b" "c") "abc"))
|
2016-07-24 22:06:18 +00:00
|
|
|
(pass-if "substring" (sequal? (substring "hello world" 6) "world"))
|
|
|
|
(pass-if "substring 2" (sequal? (substring "hello world" 4 7) "o w"))
|
|
|
|
(pass-if "string-ref" (seq? (string-ref "hello world" 4) #\o))
|
2016-07-18 20:59:33 +00:00
|
|
|
(pass-if "eq?" (not (eq? (string-append "a" "b" "c") "abc")))
|
2016-07-18 20:52:12 +00:00
|
|
|
(pass-if "char" (seq? (char->integer #\A) 65))
|
|
|
|
(pass-if "char 2" (seq? (char->integer #\101) (char->integer #\A)))
|
|
|
|
(pass-if "char 3" (seq? (integer->char 10) #\newline))
|
|
|
|
(pass-if "char 4" (seq? (integer->char 32) #\space))
|
|
|
|
(pass-if "string " (sequal? (string #\a #\space #\s #\t #\r #\i #\n #\g) "a string"))
|
|
|
|
(pass-if "length" (seq? (length '()) 0))
|
|
|
|
(pass-if "length 2" (seq? (length '(a b c)) 3))
|
2016-10-21 08:51:09 +00:00
|
|
|
(pass-if "make-list" (seq? (make-list 0) '()))
|
|
|
|
(pass-if "make-list 1" (sequal? (make-list 1 0) '(0)))
|
2016-07-18 20:52:12 +00:00
|
|
|
(pass-if "memq" (sequal? (memq 'a '(a b c)) '(a b c)))
|
|
|
|
(pass-if "memq" (sequal? (memq 'b '(a b c)) '(b c)))
|
|
|
|
(pass-if "memq" (seq? (memq 'd '(a b c)) #f))
|
|
|
|
(pass-if "member" (sequal? (member '(a) '((a) b c)) '((a) b c)))
|
2016-07-22 23:38:25 +00:00
|
|
|
(pass-if "assq-ref" (seq? (assq-ref '((b . 1) (c . 2)) 'c) 2))
|
|
|
|
(pass-if "assq-ref 2" (seq? (assq-ref '((b . 1) (c . 2)) 'a) #f))
|
|
|
|
(pass-if "assq-set!" (sequal? (assq-set! '((b . 1)) 'a 0) '((a . 0) (b . 1))))
|
|
|
|
(pass-if "assq-set! 2" (sequal? (assq-set! '((a . 0)) 'a 1) '((a . 1))))
|
2016-07-24 10:08:21 +00:00
|
|
|
(pass-if "assoc" (sequal? (assoc '(a . 0) '((a . 0) (b . 1) ((a . 0) aa))) '((a . 0) aa)))
|
2016-07-11 18:58:30 +00:00
|
|
|
|
2016-10-21 09:14:33 +00:00
|
|
|
(pass-if "builtin? car" (builtin? car))
|
|
|
|
(pass-if "builtin? cdr" (builtin? cdr))
|
|
|
|
(pass-if "builtin? cons" (builtin? cons))
|
|
|
|
(pass-if "builtin? eq?" (builtin? eq?))
|
|
|
|
(pass-if "builtin? if" (builtin? eq?))
|
|
|
|
(when (not guile?)
|
|
|
|
(pass-if "builtin? eval" (not (builtin? not))))
|
2016-07-18 20:43:16 +00:00
|
|
|
(pass-if "procedure?" (procedure? builtin?))
|
|
|
|
(pass-if "procedure?" (procedure? procedure?))
|
2016-12-28 21:26:07 +00:00
|
|
|
(pass-if "gensym"
|
|
|
|
(symbol? (gensym)))
|
|
|
|
(pass-if "gensym 1"
|
|
|
|
(not (eq? (gensym) (gensym))))
|
|
|
|
(pass-if "gensym 2"
|
|
|
|
(not (eq? (gensym) (gensym))))
|
2016-07-22 07:00:32 +00:00
|
|
|
|
2016-07-23 06:17:49 +00:00
|
|
|
(pass-if "last-pair " (sequal? (last-pair '(1 2 3 4)) '(4)))
|
2016-07-24 10:08:21 +00:00
|
|
|
(pass-if "last-pair 2" (seq? (last-pair '()) '()))
|
2016-07-23 06:17:49 +00:00
|
|
|
;; (pass-if "circular-list? "
|
|
|
|
;; (seq?
|
|
|
|
;; (let ((x (list 1 2 3 4)))
|
|
|
|
;; (set-cdr! (last-pair x) (cddr x))
|
|
|
|
;; (circular-list? x))
|
|
|
|
;; #t))
|
|
|
|
|
2016-12-20 18:25:26 +00:00
|
|
|
(pass-if-equal "iota"
|
|
|
|
'(0 1 2) (iota 3))
|
|
|
|
|
|
|
|
(pass-if-equal "iota 0"
|
|
|
|
'() (iota 0))
|
|
|
|
|
2017-03-24 20:45:19 +00:00
|
|
|
(pass-if-equal "iota -1"
|
|
|
|
'() (iota -1))
|
2016-12-20 18:25:26 +00:00
|
|
|
|
2016-07-24 10:08:21 +00:00
|
|
|
(pass-if "reverse" (sequal? (reverse '(1 2 3)) '(3 2 1)))
|
|
|
|
|
2016-07-23 13:17:03 +00:00
|
|
|
(pass-if "cond-expand" (sequal? (cond-expand (foobar #f) (mes (display ": pass: *YAY*") 'mes) (guile (display ": pass: *GUILE*") 'mes)) 'mes))
|
2016-07-23 10:54:34 +00:00
|
|
|
|
2016-07-24 11:27:05 +00:00
|
|
|
(pass-if "apply identity" (seq? (apply identity '(0)) 0))
|
|
|
|
(pass-if "apply identity 2" (sequal? (apply identity '((0 1))) '(0 1)))
|
|
|
|
(pass-if "apply append" (sequal? (apply append '((1 2) (3 4))) '(1 2 3 4)))
|
|
|
|
|
2016-07-24 15:35:31 +00:00
|
|
|
(pass-if "char-alphabetic?" (seq? (char-alphabetic? #\a) #t))
|
|
|
|
(pass-if "char-alphabetic? 2" (seq? (char-alphabetic? #\[) #f))
|
|
|
|
|
2016-10-10 20:42:05 +00:00
|
|
|
(result 'report)
|