scm.test 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #! /bin/sh
  2. # -*-scheme-*-
  3. if [ "$MES" != guile ]; then
  4. MES_BOOT=boot-03.scm exec ${MES-mes} < $0
  5. fi
  6. exec ${MES-mes} --no-auto-compile -L ${0%/*} -L module -C module -e '(tests boot)' -s "$0" "$@"
  7. !#
  8. ;;; -*-scheme-*-
  9. ;;; GNU Mes --- Maxwell Equations of Software
  10. ;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  11. ;;;
  12. ;;; This file is part of GNU Mes.
  13. ;;;
  14. ;;; GNU Mes is free software; you can redistribute it and/or modify it
  15. ;;; under the terms of the GNU General Public License as published by
  16. ;;; the Free Software Foundation; either version 3 of the License, or (at
  17. ;;; your option) any later version.
  18. ;;;
  19. ;;; GNU Mes is distributed in the hope that it will be useful, but
  20. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. ;;; GNU General Public License for more details.
  23. ;;;
  24. ;;; You should have received a copy of the GNU General Public License
  25. ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  26. (define-module (tests scm)
  27. #:use-module (mes mes-0)
  28. #:use-module (mes test))
  29. (cond-expand
  30. (mes
  31. (primitive-load "module/mes/test.scm"))
  32. (guile-2)
  33. (guile
  34. (use-modules (ice-9 syncase))))
  35. (pass-if "first dummy" #t)
  36. (pass-if-not "second dummy" #f)
  37. (pass-if "when" (seq? (when #t 'true) 'true))
  38. (pass-if "when 2" (seq? (when #f 'true) *unspecified*))
  39. (pass-if "map" (sequal? (map identity '(1 2 3 4)) '(1 2 3 4)))
  40. (pass-if "map 2 " (sequal? (map (lambda (i a) (cons i a)) '(1 2 3 4) '(a b c d))
  41. '((1 . a) (2 . b) (3 . c) (4 . d))))
  42. (pass-if-equal "map 1,2"
  43. '((0 . a))
  44. (map (lambda (x y) (cons x y)) '(0) '(a b)))
  45. (pass-if-equal "map 2,1"
  46. '((0 . a))
  47. (map (lambda (x y) (cons x y)) '(0 1) '(a)))
  48. (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)))
  49. (pass-if "for-each 1,2"
  50. (for-each (lambda (x y) (cons x y)) '(0) '(a b)))
  51. (pass-if "for-each 2,1"
  52. (for-each (lambda (x y) (cons x y)) '(0 1) '(a)))
  53. (define xxxa 0)
  54. (pass-if "set! " (seq? (begin (set! xxxa 1) xxxa) 1))
  55. (pass-if "set! 2" (seq? (let ((a 0)) (set! a 1) a) 1))
  56. (pass-if "list-ref" (seq? (list-ref '(0 1 2) 1) 1))
  57. (pass-if "do" (sequal? (let ((acc '())) (do ((i 0 (+ i 1))) ((>= i 3)) (set! acc (cons i acc))) acc) '(2 1 0)))
  58. (pass-if ">=" (>= 3 2 1))
  59. (pass-if-equal "string-length"
  60. 0
  61. (string-length ""))
  62. (pass-if-equal "string-length 2"
  63. 3
  64. (string-length (string-append "a" "b" "c")))
  65. (pass-if-equal "string->list"
  66. '()
  67. (string->list ""))
  68. (pass-if-equal "string->list 2"
  69. '(#\a #\b #\c #\newline)
  70. (string->list "abc\n"))
  71. (pass-if "string-append" (sequal? (string-append "a" "b" "c") "abc"))
  72. (pass-if "substring" (sequal? (substring "hello world" 6) "world"))
  73. (pass-if "substring 2" (sequal? (substring "hello world" 4 7) "o w"))
  74. (pass-if "string-ref" (seq? (string-ref "hello world" 4) #\o))
  75. (pass-if "eq?" (not (eq? (string-append "a" "b" "c") "abc")))
  76. (pass-if "char" (seq? (char->integer #\A) 65))
  77. (pass-if "char 2" (seq? (char->integer #\101) (char->integer #\A)))
  78. (pass-if "char 3" (seq? (integer->char 10) #\newline))
  79. (pass-if "char 4" (seq? (integer->char 32) #\space))
  80. (pass-if "string " (sequal? (string #\a #\space #\s #\t #\r #\i #\n #\g) "a string"))
  81. (pass-if "length" (seq? (length '()) 0))
  82. (pass-if "length 2" (seq? (length '(a b c)) 3))
  83. (pass-if "make-list" (seq? (make-list 0) '()))
  84. (pass-if "make-list 1" (sequal? (make-list 1 0) '(0)))
  85. (pass-if "memq" (sequal? (memq 'a '(a b c)) '(a b c)))
  86. (pass-if "memq" (sequal? (memq 'b '(a b c)) '(b c)))
  87. (pass-if "memq" (seq? (memq 'd '(a b c)) #f))
  88. (pass-if "member" (sequal? (member '(a) '((a) b c)) '((a) b c)))
  89. (pass-if "assq-ref" (seq? (assq-ref '((b . 1) (c . 2)) 'c) 2))
  90. (pass-if "assq-ref 2" (seq? (assq-ref '((b . 1) (c . 2)) 'a) #f))
  91. (pass-if "assq-set!" (sequal? (assq-set! '((b . 1)) 'a 0) '((a . 0) (b . 1))))
  92. (pass-if "assq-set! 2" (sequal? (assq-set! '((a . 0)) 'a 1) '((a . 1))))
  93. (pass-if "assoc" (sequal? (assoc '(a . 0) '((a . 0) (b . 1) ((a . 0) aa))) '((a . 0) aa)))
  94. (pass-if-equal "assoc-set!" '((a . 0) (b . 2)) (assoc-set! '((a . 0) (b . 1)) 'b 2))
  95. (pass-if-equal "assoc-set! new" '((b . 2) (a . 0)) (assoc-set! '((a . 0)) 'b 2))
  96. (pass-if "builtin? car" (builtin? car))
  97. (pass-if "builtin? cdr" (builtin? cdr))
  98. (pass-if "builtin? cons" (builtin? cons))
  99. (pass-if "builtin? eq?" (builtin? eq?))
  100. (pass-if "builtin? if" (builtin? eq?))
  101. (when (not guile?)
  102. (pass-if "builtin? eval" (not (builtin? not))))
  103. (pass-if "procedure?" (procedure? builtin?))
  104. (pass-if "procedure?" (procedure? procedure?))
  105. (pass-if "gensym"
  106. (symbol? (gensym)))
  107. (pass-if "gensym 1"
  108. (not (eq? (gensym) (gensym))))
  109. (pass-if "gensym 2"
  110. (not (eq? (gensym) (gensym))))
  111. (pass-if "last-pair " (sequal? (last-pair '(1 2 3 4)) '(4)))
  112. (pass-if "last-pair 2" (seq? (last-pair '()) '()))
  113. ;; (pass-if "circular-list? "
  114. ;; (seq?
  115. ;; (let ((x (list 1 2 3 4)))
  116. ;; (set-cdr! (last-pair x) (cddr x))
  117. ;; (circular-list? x))
  118. ;; #t))
  119. (pass-if-equal "iota"
  120. '(0 1 2) (iota 3))
  121. (pass-if-equal "iota 0"
  122. '() (iota 0))
  123. (pass-if-equal "iota -1"
  124. '() (iota -1))
  125. (pass-if "cond-expand" (sequal? (cond-expand (foobar #f) (mes (display ": pass: *YAY*") 'mes) (guile (display ": pass: *GUILE*") 'mes)) 'mes))
  126. (pass-if "apply identity" (seq? (apply identity '(0)) 0))
  127. (pass-if "apply identity 2" (sequal? (apply identity '((0 1))) '(0 1)))
  128. (pass-if "apply append" (sequal? (apply append '((1 2) (3 4))) '(1 2 3 4)))
  129. (pass-if "char-alphabetic?" (seq? (char-alphabetic? #\a) #t))
  130. (pass-if "char-alphabetic? 2" (seq? (char-alphabetic? #\[) #f))
  131. (pass-if-equal "compose" 1 ((compose car cdr car) '((0 1 2))))
  132. (if (not guile?)
  133. (pass-if "make-vector" (sequal? (make-vector 3) #(*unspecified* *unspecified* *unspecified*))))
  134. (pass-if "make-vector 2" (sequal? (make-vector 3 1) #(1 1 1)))
  135. (pass-if-equal "binary" 5 #b101)
  136. (pass-if-equal "octal" 65 #o101)
  137. (pass-if-equal "hex" 257 #x101)
  138. (pass-if-equal "negate" #t ((negate eq?) 0 1))
  139. (pass-if-equal "const" 42 ((const 42) 1 2 3 4))
  140. (result 'report)