public
Description: An easy way to make web apps (in PLT Scheme)
Homepage: http://blog.leftparen.com
Clone URL: git://github.com/vegashacker/leftparen.git
Click here to lend your support to: leftparen and make a donation at www.pledgie.com !
leftparen / unit-test.ss
100644 59 lines (50 sloc) 2.212 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#lang scheme
 
(require (planet "main.ss" ("schematics" "schemeunit.plt" 3 (= 3)))
         (planet "text-ui.ss" ("schematics" "schemeunit.plt" 3 (= 3)))
         "util.scm"
         "closures.scm")
                 
(define basic-tests
  (let ((clos-key 'dummy))
    (test-suite
     "LeftParen basic test suite"
     ;; actual: expected:
     (test-equal? "numeric equality" 1 1 )
     (test-equal? "md5 hashing" (md5-string "hello") "5d41402abc4b2a76b9719d911017c592")
     (test-equal? "num closures in memory at start" (num-closures-in-memory) 0)
 
     ;; closure testing
     (test-equal? "after a closure made"
                  (begin (set! clos-key (body-as-closure-key (req) "hi"))
                         (num-closures-in-memory))
                  1)
     (test-equal? "call a closure--check it's value"
                  (call-closure clos-key 'dummy-req)
                  "hi")
 
     (test-equal? "closures are usable only once"
                  (num-closures-in-memory)
                  0)
 
     ;; now test manual closure keys
     (test-equal? "just made a manual key'd closure"
                  (begin (set! clos-key "some-key-i-made-up")
                         (body-as-closure-key (req clos-key) "cool")
                         (num-closures-in-memory))
                  1)
     (test-equal? "call the manual closure"
                  (call-closure clos-key 'dummy-req)
                  "cool")
     (test-equal? "make sure manual closures clean up too"
                  (num-closures-in-memory)
                  0)
 
     ;; test sticky closures
     (test-equal? "make a sticky closure"
                  (begin (set! clos-key (body-as-closure-key (req clos-key #:sticky)
                                                             "sticky!"))
                         (num-closures-in-memory))
                  1)
     (test-equal? "call the sticky closure"
                  (call-closure clos-key 'dummy-req)
                  "sticky!")
     (test-equal? "make sure the sticky closure sticks"
                  (num-closures-in-memory)
                  1)
                         
     )))
 
(run-tests basic-tests)