aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world/net/http/header.lux
blob: 50b25f24bace5b5e109704f3e8694d36d136bea2 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["|" pipe]
    ["[0]" try (.use "[1]#[0]" functor)]
    ["[0]" exception]]
   [data
    ["[0]" text (.use "[1]#[0]" equivalence)]]
   [math
    ["[0]" random (.only Random) (.use "[1]#[0]" monad)]
    [number
     ["[0]" nat (.use "[1]#[0]" equivalence)]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   [//
    ["[0]" mime (.use "[1]#[0]" equivalence)]
    ["[0]" cookie (.only Cookie)]]]])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [expected_content_length random.nat
         expected_content_type (random.either (random#in mime.javascript)
                                              (random#in mime.jpeg))
         expected_location (random.either (random#in "http://example.com/yolo")
                                          (random#in "http://example.com/meme"))
         header_name (random.lower_case 1)
         expected_header_value (random.upper_case 1)
         .let [header (is (/.Header Text)
                          [/.#name header_name
                           /.#in (|>>)
                           /.#out (|>> {try.#Success})])]])
      (all _.and
           (_.coverage [/.Headers /.empty /.unknown]
             (|> /.empty
                 (/.one header)
                 (|.when
                   {try.#Success _}
                   false

                   {try.#Failure error}
                   (exception.match? /.unknown error))))
           (_.coverage [/.Header /.#name /.#in /.#out
                        /.has /.one]
             (|> /.empty
                 (/.has header expected_header_value)
                 (/.one header)
                 (try#each (same? expected_header_value))
                 (try.else false)))
           (_.coverage [/.content_length]
             (|> /.empty
                 (/.has /.content_length expected_content_length)
                 (/.one /.content_length)
                 (try#each (nat#= expected_content_length))
                 (try.else false)))
           (_.coverage [/.content_type]
             (|> /.empty
                 (/.has /.content_type expected_content_type)
                 (/.one /.content_type)
                 (try#each (mime#= expected_content_type))
                 (try.else false)))
           (_.coverage [/.location]
             (|> /.empty
                 (/.has /.location expected_location)
                 (/.one /.location)
                 (try#each (text#= expected_location))
                 (try.else false)))
           (do !
             [name (random.upper_case 1)
              expected_value (random.lower_case 1)
              .let [cookie (is (Cookie Text)
                               [cookie.#name name
                                cookie.#in (|>>)
                                cookie.#out (|>> {try.#Success})])
                    expected_jar (|> cookie.empty
                                     (cookie.has cookie expected_value))]]
             (_.coverage [/.set_cookies]
               (|> /.empty
                   (/.has /.set_cookies expected_jar)
                   (/.one /.set_cookies)
                   (try#each (at cookie.equivalence = expected_jar))
                   (try.else false))))
           )))