aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/function/contract.lux
blob: 90494e7f092c466689e5f5a926a2cb4ea4a111f1 (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
(.require
 [library
  [lux (.except if loop)
   ["$" documentation]
   [data
    [text (.only \n)
     ["%" \\format (.only format)]]]]]
 [\\library
  ["[0]" /]])

(.def .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [($.default /.pre_condition_failed)
             ($.default /.post_condition_failed)

             ($.documentation /.pre
               (format "Pre-conditions."
                       \n "Given a test and an expression to run, only runs the expression if the test passes."
                       \n "Otherwise, an error is raised.")
               [(pre (i.= +4 (i.+ +2 +2))
                     (foo +123 +456 +789))])

             ($.documentation /.post
               (format "Post-conditions."
                       \n "Given a predicate and an expression to run, evaluates the expression and then tests the output with the predicate."
                       \n "If the predicate returns #1, returns the value of the expression."
                       \n "Otherwise, an error is raised.")
               [(post i.even?
                      (i.+ +2 +2))])]
            []))