aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/documentation.lux
blob: 37aff45441d1480f79ac5bdb81a14575ff512072 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(.require
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [control
    ["[0]" try]
    ["[0]" exception]]
   [data
    ["[0]" text (.use "[1]#[0]" equivalence)
     ["%" \\format]]
    [format
     ["md" markdown]]]
   ["[0]" meta (.only)
    ["[0]" code (.only)
     ["<[1]>" \\parser]]
    ["[0]" macro (.only)
     [syntax (.only syntax)]
     ["[0]" template]]]]]
 [\\library
  ["[0]" /]])

(def macro_error
  (syntax (_ [macro <code>.any])
    (function (_ compiler)
      {try.#Success [compiler (list (code.bit (case ((macro.expansion macro) compiler)
                                                {try.#Failure error}
                                                true
                                                
                                                {try.#Success _}
                                                false)))]})))

(def description
  (syntax (_ [])
    (at meta.monad each
        (|>> %.nat code.text list)
        meta.seed)))

(template.with_locals [g!default]
  (with_expansions ['definition_description' (..description)
                    'sub_description' (..description)
                    'super_description' (..description)]
    (these (def .public g!default
             Nat
             123)

           (def documentation
             (/.documentation /.documentation
               'definition_description'))

           (def .public test
             Test
             (<| (_.covering /._)
                 (all _.and
                      (_.for [/.Definition]
                             (all _.and
                                  (_.coverage [/.default]
                                    (case (`` (/.default (,, (template.symbol [.._] [g!default]))))
                                      (pattern (list definition))
                                      (and (|> definition
                                               (the /.#definition)
                                               (text#= (template.text [g!default])))
                                           (|> definition
                                               (the /.#documentation)
                                               md.markdown
                                               (text#= "")
                                               not))

                                      _
                                      false))
                                  (_.coverage [/.documentation]
                                    (case ..documentation
                                      (pattern (list documentation))
                                      (and (|> documentation
                                               (the /.#definition)
                                               (text#= (template.text [/.documentation])))
                                           (|> documentation
                                               (the /.#documentation)
                                               md.markdown
                                               (text.contains? 'definition_description')))

                                      _
                                      false))
                                  ))
                      (_.for [/.Module]
                             (all _.and
                                  (_.coverage [/.module /.markdown]
                                    (let [sub (`` (/.module /._
                                                            (,, (template.text ['sub_description']))
                                                            []
                                                            []))
                                          super (`` (/.module .._
                                                              (,, (template.text ['super_description']))
                                                              [..documentation]
                                                              [sub]))]
                                      (and (text.contains? (template.text ['sub_description'])
                                                           (/.markdown sub))
                                           (text.contains? (/.markdown sub)
                                                           (/.markdown super))
                                           (text.contains? (template.text ['super_description'])
                                                           (/.markdown super))
                                           (case ..documentation
                                             (pattern (list documentation))
                                             (text.contains? (md.markdown (the /.#documentation documentation))
                                                             (/.markdown super))

                                             _
                                             false))))
                                  ))
                      (_.coverage [/.unqualified_symbol]
                        (`` (and (,, (with_template [<example>]
                                       [(macro_error <example>)]
                                       
                                       [(/.default g!default)]
                                       [(/.documentation g!default
                                          (,, (template.text ['definition_description'])))]
                                       [(/.module g!default
                                                  ""
                                                  [..documentation]
                                                  [sub])]
                                       )))))
                      )))))
  )