summaryrefslogtreecommitdiff
path: root/furnace/callbacks/callbacks-tests.factor
blob: f9302deb6477404fdfbb2f240f8bd980bd3fc70f (plain)
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
60
61
62
63
64
65
66
67
USING: furnace furnace.actions furnace.callbacks accessors
http http.server http.server.responses tools.test
namespaces io fry sequences
splitting kernel hashtables continuations ;
IN: furnace.callbacks.tests

[ 123 ] [
    [
        <request> "GET" >>method init-request
        [
            exit-continuation set
            { }
            <action> [ [ "hello" print 123 ] show-final ] >>display
            <callback-responder>
            call-responder
        ] callcc1
    ] with-scope
] unit-test

[
    <action> [
        [
            "hello" print
            <html-content>
        ] show-page
        "byebye" print
        [ 123 ] show-final
    ] >>display
    <callback-responder> "r" set

    [ 123 ] [
        <request> init-request

        [
            exit-continuation set
            <request> "GET" >>method init-request
            { } "r" get call-responder
        ] callcc1

        body>> first

        <request>
            "GET" >>method
            dup url>> rot cont-id associate >>query drop
            dup url>> "/" >>path drop
        init-request

        [
            exit-continuation set
            { }
            "r" get call-responder
        ] callcc1

        ! get-post-get
        <request>
            "GET" >>method
            dup url>> rot "location" header query>> >>query drop
            dup url>> "/" >>path drop
        init-request

        [
            exit-continuation set
            { }
            "r" get call-responder
        ] callcc1
    ] unit-test
] with-scope