Test Suite

The wisp test-suite consists of a large number of wisp-snippets and the corresponding scheme-code.

A wisp-implementation may call itself compliant with the wisp test-suite if the code tree parsed from the wisp file is the same as a code tree parsed from the equivalent Scheme file.

A wisp-implementation may call itself a compliant wisp pre-processor if it successfully converts each wisp-snippet into the corresponging scheme-snippet. Blank lines at the end of the file and non-functional white-space in the produced scheme-file do not matter for this purpose.

This test-suite is also available in the wisp repository along with a script-runner (runtests.sh) which tests the reference wisp-implementation with GNU Guile against this testsuite.1

1 tests/syntax-underscore.w

define : a b c
_ d e
___ f
___ g h
__  . i

define : _
_  display "hello\n"

\_

2 tests/syntax-underscore.scm

(define (a b c)
  (d e
    (f)
    (g h)
    i))

(define (_)
   (display "hello\n"))

(_)

3 tests/syntax-strings-parens.w

; Test linebreaks in strings and brackets

. "flubbub

flabbab"

hrug (nadda
madda gadda "shoktom
 mee"  " sep  
ka"
  hadda)
    gom

flu

sum [foo
bar] barz {1 + [* 2 2]}

mara {
li
+
lo - (mabba)
}

4 tests/syntax-strings-parens.scm

; Test linebreaks in strings and brackets

"flubbub

flabbab"

(hrug (nadda
madda gadda "shoktom
 mee"  " sep  
ka"
  hadda)
    (gom))

(flu)

(sum [foo
bar] barz {1 + [* 2 2]})

(mara {
li
+
lo - (mabba)
})

5 tests/syntax-indent.w

define 
  hello who
  format #t "Hello ~A\n" who

define
    let
      :
        a 1
        b 2
        c 3
      format #t "a: ~A, b: ~A, c: ~A"
                   + a 2
                   .        b      c

6 tests/syntax-indent.scm

(define 
  (hello who)
  (format #t "Hello ~A\n" who))

(define
    (let
      (
        (a 1)
        (b 2)
        (c 3))
      (format #t "a: ~A, b: ~A, c: ~A"
                   (+ a 2)
                          b      c)))

7 tests/syntax-empty.w


8 tests/syntax-empty.scm


9 tests/syntax-dot.w

define : foo
  . "bar"

define : bar
  ' 1
    . . 2 ; pair

display : foo
newline
display : bar
newline

10 tests/syntax-dot.scm

(define (foo)
  "bar")

(define (bar)
  '(1
    . 2 )); pair

(display (foo))
(newline)
(display (bar))
(newline)

11 tests/syntax-colon.w

let
  :
    a 1
    b 2
  let
    :
      :
        . c 3
    format #t "a: ~A, b: ~A, c: ~A"
              .    a      b      c

: a

define : hello
  display "hello\n"

let
  : a 1
    b 2
  format #t "a: ~A, b: ~A"
            .    a      b

let : : a ' :

let 
  :    ; foo
    a
      '

:
  a

define : \:
  hello

\:

12 tests/syntax-colon.scm

(let
  (
    (a 1)
    (b 2))
  (let
    (
      (
        c 3))
    (format #t "a: ~A, b: ~A, c: ~A"
                 a      b      c)))

((a))

(define (hello)
  (display "hello\n"))

(let
  ((a 1)
    (b 2))
  (format #t "a: ~A, b: ~A"
               a      b))

(let ((a '())))

(let 
  (    ; foo
    (a
      '())))

(
  (a))

(define (:)
  (hello))

(:)

13 tests/sublist.w

; sublists allow to start single line function calls with a colon ( : ).

define : a b c
  let : : e . f
        . g

14 tests/sublist.scm

; sublists allow to start single line function calls with a colon ( : ).

(define (a b c)
  (let ((e . f))
        g))

15 tests/hashbang.w

#!/usr/bin/wisp.py # !#
; This tests hashbang lines

16 tests/hashbang.scm

#!/usr/bin/wisp.py # !#
; This tests hashbang lines

17 tests/readable-tests.w

define : fibfast n
      if : < n 2
      . n           
      fibup n 2 1 0 

define : fibup maxnum count n-1 n-2
       if : = maxnum count
         + n-1  n-2
         fibup maxnum 
               + count 1 
               + n-1 n-2 
               . n-1

define : factorial n
       if : <= n 1
         . 1
         * n 
           factorial : - n 1

define (gcd x y)
       if (= y 0)
       . x
       gcd y
         rem x y

define : add-if-all-numbers lst
       call/cc 
         lambda : exit
                let loop 
                  : 
                    lst lst 
                    sum 0
                  if : null? lst
                     . sum
                     if : not : number? : car lst
                        exit #f
                        + : car lst
                          loop : cdr lst

18 tests/readable-tests.scm

(define (fibfast n)
      (if (< n 2))
      n           
      (fibup n 2 1 0 ))

(define (fibup maxnum count n-1 n-2)
       (if (= maxnum count)
         (+ n-1  n-2)
         (fibup maxnum 
               (+ count 1 )
               (+ n-1 n-2 )
               n-1)))

(define (factorial n)
       (if (<= n 1)
         1
         (* n 
           (factorial (- n 1)))))

(define (gcd x y)
       (if (= y 0))
       x
       (gcd y
         (rem x y)))

(define (add-if-all-numbers lst)
       (call/cc 
         (lambda (exit)
                (let loop 
                  (
                    (lst lst )
                    (sum 0))
                  (if (null? lst)
                     sum
                     (if (not (number? (car lst)))
                        (exit #f)
                        (+ (car lst)
                          (loop (cdr lst)))))))))

19 tests/quotecolon.w

#!/home/arne/wisp/wisp-multiline.sh  
; !#
define a 1 ; test whether ' : correctly gets turned into '(
; and whether brackets in commments are treated correctly.

define a ' : 1 2 3

define
  a b
  c

20 tests/quotecolon.scm

#!/home/arne/wisp/wisp-multiline.sh  
; !#
(define a 1 ); test whether ' : correctly gets turned into '(
; and whether brackets in commments are treated correctly.

(define a '(1 2 3))

(define
  (a b)
  (c))

21 tests/namedlet.w

#!/home/arne/wisp/wisp-multiline.sh  
; !#
define : hello who
  display who

let hello
  : who 0
  if : = who 5
    display who
    hello : + 1 who

22 tests/namedlet.scm

#!/home/arne/wisp/wisp-multiline.sh  
; !#
(define (hello who)
  (display who))

(let hello
  ((who 0))
  (if (= who 5)
    (display who)
    (hello (+ 1 who))))

23 tests/flexible-parameter-list.w

; Test using a . as first parameter on a line by prefixing it with a second .
define
  a i
    . . b
  unless : >= i : length b
    display : number->string : length b 
    display : list-ref b i
    newline
    apply a ( + i 1 ) b


a 0 "123" "345" "567"

24 tests/flexible-parameter-list.scm

; Test using a . as first parameter on a line by prefixing it with a second .
(define
  (a i
    . b)
  (unless (>= i (length b))
    (display (number->string (length b )))
    (display (list-ref b i))
    (newline)
    (apply a ( + i 1 ) b)))


(a 0 "123" "345" "567")

25 tests/factorial.w

;; short version
; note: once you use one inline colon, all the following forms on that
; line will get closed at the end of the line

define : factorial n
  if : zero? n
    . 1
    * n : factorial : - n 1

display : factorial 5 


;; more vertical space, less colons
define : factorial n
  if : zero? n
    . 1
    * n 
      factorial 
        - n 1

display : factorial 5

26 tests/factorial.scm

;; short version
; note: once you use one inline colon, all the following forms on that
; line will get closed at the end of the line

(define (factorial n)
  (if (zero? n)
    1
    (* n (factorial (- n 1)))))

(display (factorial 5 ))


;; more vertical space, less colons
(define (factorial n)
  (if (zero? n)
    1
    (* n 
      (factorial 
        (- n 1)))))

(display (factorial 5 ))

27 tests/example.w

define (a b c)
  let
    : 
      d "i am a string
do not break me!"
      : 
  ; comment: 0
        f
; comment : 1
        ` g ; comment " : " 2
      : 
        h (I am in brackets:
           do not : change "me")
        . i
  , 'j k

  . l

; comment

  a c

define : b :n o
  . "second defun : with a docstring!"
  message "I am here"
  . t

define : c e f
  : g
  :
    h
      i
    j
  ' :
  k
  . l
  . : m

define : _ \:
__
__ . \:

\_ b

define : d 
      let 
          : a b
            c d

a : : : c

let 
    : a b
      c

let : : a b

. a

28 tests/example.scm

(define (a b c)
  (let
    (
      (d "i am a string
do not break me!")
      (
  ; comment: 0
        (f)
; comment : 1
        `(g )); comment " : " 2
      (
        (h (I am in brackets:
           do not : change "me"))
        i)))
  ,('j k)

  l

; comment

  (a c))

(define (b :n o)
  "second defun : with a docstring!"
  (message "I am here")
  t)

(define (c e f)
  ((g))
  (
    (h
      (i))
    (j))
  '(())
  (k)
  l
  (m))

(define (_ :)

   :)

(_ b)

(define (d)
      (let 
          ((a b)
            (c d))))

(a (((c))))

(let 
    ((a b)
      (c)))

(let ((a b)))

a

29 tests/continuation.w

a b c d e
  . f g h
  . i j k

concat "I want " 
    getwish from me
    . " - " username

30 tests/continuation.scm

(a b c d e
  f g h
  i j k)

(concat "I want " 
    (getwish from me)
    " - " username)

Footnotes:

1

To run the tests in the wisp testsuite with a separately built GNU Guile, you can use any given guile interpreter by adjusting the following command: PATH=~/guile-2.0.11/meta:${PATH} ./runtests.sh

Author: Arne Babenhauserheide

Created: 2014-12-23 Di 22:50

Emacs 24.3.1 (Org mode 8.2.6)

Validate