aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/ao_assertions.org
blob: c6b09bbb1369e6c579e76036bf2393c39d0ebc84 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#+TITLE: Emacs config file written in org-mode
#+AUTHOR: Ralph Amissah
#+EMAIL: ralph.amissah@gmail.com
#+STARTUP: indent
#+LANGUAGE: en
#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+OPTIONS: author:nil email:nil creator:nil timestamp:nil
#+OPTIONS: ^:nil _:nil
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+TAGS: Amissah(A) Class(c) WEB(W) noexport(n)
#+FILETAGS: :sdp:ao:

* assertions
** mixin template: assertions on markup document structure
#+name: ao_assertions
#+BEGIN_SRC d                                                  :exports none
mixin template AssertionsOnMarkupDocumentStructure() {
  auto assertions_doc_structure(string[string] object, uint[string] lv) {
    if (lv["h3"] > 0) {
      assert(lv["h0"] > 0);
      assert(lv["h1"] > 0);
      assert(lv["h2"] > 0);
      assert(lv["h3"] > 0);
    } else if (lv["h2"] > 0) {
      assert(lv["h0"] > 0);
      assert(lv["h1"] > 0);
      assert(lv["h2"] > 0);
      assert(lv["h3"] == 0);
    } else if (lv["h1"] > 0) {
      assert(lv["h0"] > 0);
      assert(lv["h1"] > 0);
      assert(lv["h2"] == 0);
      assert(lv["h3"] == 0);
    } else if (lv["h0"] > 0) {
      assert(lv["h0"] > 0);
      assert(lv["h1"] == 0);
      assert(lv["h2"] == 0);
      assert(lv["h3"] == 0);
    } else {
      assert(lv["h0"] == 0);
      assert(lv["h1"] == 0);
      assert(lv["h2"] == 0);
      assert(lv["h3"] == 0);
    }
    if (lv["h7"] > 0) {
      assert(lv["h4"] > 0);
      assert(lv["h5"] > 0);
      assert(lv["h6"] > 0);
      assert(lv["h7"] > 0);
    } else if (lv["h6"] > 0) {
      assert(lv["h4"] > 0);
      assert(lv["h5"] > 0);
      assert(lv["h6"] > 0);
      assert(lv["h7"] == 0);
    } else if (lv["h5"] > 0) {
      assert(lv["h4"] > 0);
      assert(lv["h5"] > 0);
      assert(lv["h6"] == 0);
      assert(lv["h7"] == 0);
    } else if (lv["h4"] > 0) {
      assert(lv["h4"] > 0);
      assert(lv["h5"] == 0);
      assert(lv["h6"] == 0);
      assert(lv["h7"] == 0);
    } else {
      assert(lv["h4"] == 0);
      assert(lv["h5"] == 0);
      assert(lv["h6"] == 0);
      assert(lv["h7"] == 0);
    }
    if (lv["h0"] == 0) {
      assert(lv["h0"] == 0);
      assert(lv["h1"] == 0);
      assert(lv["h2"] == 0);
      assert(lv["h3"] == 0);
      assert(lv["h4"] == 0);
      assert(lv["h5"] == 0);
      assert(lv["h6"] == 0);
      assert(lv["h7"] == 0);
    }
    if (lv["h1"] == 0) {
      assert(lv["h1"] == 0);
      assert(lv["h2"] == 0);
      assert(lv["h3"] == 0);
    }
    if (lv["h2"] == 0) {
      assert(lv["h2"] == 0);
      assert(lv["h3"] == 0);
    }
    if (lv["h3"] == 0) {
      assert(lv["h3"] == 0);
    }
    if (lv["h4"] == 0) {
      assert(lv["h4"] == 0);
      assert(lv["h5"] == 0);
      assert(lv["h6"] == 0);
      assert(lv["h7"] == 0);
    }
    if (lv["h5"] == 0) {
      assert(lv["h5"] == 0);
      assert(lv["h6"] == 0);
      assert(lv["h7"] == 0);
    }
    if (lv["h6"] == 0) {
      assert(lv["h6"] == 0);
      assert(lv["h7"] == 0);
    }
    if (lv["h6"] == 0) {
      assert(lv["h7"] == 0);
    }
    switch (to!string(object["lev"])) {
    case "A":
      if (lv["h0"]==0) {
        assert(lv["h0"] == 0);
        assert(lv["h1"] == 0);
        assert(lv["h2"] == 0);
        assert(lv["h3"] == 0);
        assert(lv["h4"] == 0);
        assert(lv["h5"] == 0);
        assert(lv["h6"] == 0);
        assert(lv["h7"] == 0);
      } else {
        assert(lv["h0"] == 0,"error should not enter level A a second time");
      }
      break;
    case "B":
      if (lv["h1"]==0) {
        assert(lv["h0"] > 0);
        assert(lv["h1"] == 0); //
        assert(lv["h2"] == 0);
        assert(lv["h3"] == 0);
      } else {                 // (lv["h1"] >0)
        assert(lv["h0"] > 0);
        assert(lv["h1"] > 0);  //
      }
      break;
    case "C":
      if (lv["h2"]==0) {
        assert(lv["h0"] > 0);
        assert(lv["h1"] > 0);
        assert(lv["h2"] == 0); //
        assert(lv["h3"] == 0);
      } else {                 // (lv["h2"] > 0)
        assert(lv["h0"] > 0);
        assert(lv["h1"] > 0);
        assert(lv["h2"] > 0);  //
      }
      break;
    case "D":
      if (lv["h3"]==0) {
        assert(lv["h0"] > 0);
        assert(lv["h1"] > 0);
        assert(lv["h2"] > 0);
        assert(lv["h3"] == 0); //
      } else {                 // (lv["h3"] >0)
        assert(lv["h0"] > 0);
        assert(lv["h1"] > 0);
        assert(lv["h2"] > 0);
        assert(lv["h3"] > 0);
      }
      break;
    case "1":
      if (lv["h4"]==0) {
        assert(lv["h0"] > 0);
        assert(lv["h4"] == 0); //
      } else {                 // (lv["h4"] >0)
        assert(lv["h0"] > 0);
        assert(lv["h4"] > 0);  //
      }
      break;
    case "2":
      if (lv["h5"]==0) {
        assert(lv["h0"] > 0);
        assert(lv["h4"] > 0);
        assert(lv["h5"] == 0); //
      } else {                 // (lv["h5"] >0)
        assert(lv["h0"] > 0);
        assert(lv["h4"] > 0);
        assert(lv["h5"] > 0);  //
      }
      break;
    case "3":
      if (lv["h6"]==0) {
        assert(lv["h0"] > 0);
        assert(lv["h4"] > 0);
        assert(lv["h5"] > 0);
        assert(lv["h6"] == 0); //
      } else {                 // (lv["h6"] >0)
        assert(lv["h0"] > 0);
        assert(lv["h4"] > 0);
        assert(lv["h5"] > 0);
        assert(lv["h6"] > 0);  //
      }
      break;
    case "4":
      if (lv["h7"]==0) {
        assert(lv["h0"] > 0);
        assert(lv["h4"] > 0);
        assert(lv["h5"] > 0);
        assert(lv["h6"] > 0);
        assert(lv["h7"] == 0); //
      } else {                 // (lv["h7"] >0)
        assert(lv["h0"] > 0);
        assert(lv["h4"] > 0);
        assert(lv["h5"] > 0);
        assert(lv["h6"] > 0);
        assert(lv["h7"] > 0);  //
      }
      break;
    default:
      break;
    }
  }
}
#+end_src
** mixin template: assertions on blocks
#+name: ao_assertions
#+BEGIN_SRC d                                                  :exports none
mixin template AssertionsOnBlocks() {
  auto assertions_flag_types_block_status_none_or_closed(int[string] flag_type) {
    assert(
      (flag_type["code"] == 0) || (flag_type["code"] == 2),
      "code block status: none or closed");
    assert(
      (flag_type["poem"] == 0) || (flag_type["poem"] == 2),
      "poem status: none or closed");
    assert(
      (flag_type["table"] == 0) || (flag_type["table"] == 2),
      "table status: none or closed");
    assert(
      (flag_type["group"] == 0) || (flag_type["group"] == 2),
      "group block status: none or closed");
    assert(
      (flag_type["block"] == 0) || (flag_type["block"] == 2),
      "block status: none or closed");
  }
}
#+end_src

* tangle
** code structure:                                           :ao_assertions.d:
#+name: tangle_ao_assertions
#+BEGIN_SRC d  :tangle ../lib/sdp/ao_assertions.d  :exports none :noweb yes
/*
  assertions
  ao_assertions.d
*/
<<ao_assertions>>
#+end_src