Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
blob: a2b23acee243f70a68b3f747dc2c305240a2606a (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
<?xml version="1.0"?>
<!--
  Copyright (C) 2015, 2018 R-T Specialty, LLC.

  This file is part of tame-core.

  tame-core is free software: you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<package xmlns="http://www.lovullo.com/rater"
         xmlns:t="http://www.lovullo.com/rater/apply-template"
         core="true"
         desc="Assertions">

  <import package="base" />
  <import package="vector/cmatch" export="true" />


  This package is young;
    the intent is to provide basic assertions to ensure data
    integrity.

  \emph{N.B. The behavior of this package changed in version 1.0.0---%
          \ref{_assert_} now properly fails on non-match,
            not match.}

  The \ref{_assert_} template generates a~generic assertion using the
    provided predicates.
  If the predicates provided to the assertion fail (yields $\bot$),
    the system immediately terminates.\footnote{
      Beacuse the system stops processing once a terminating classification
        yields~$\top$,
          only one assertion will ever match,
            even if others would match if execution were to continue.}

  \ref{_assert_} implements assertions by genearting two classifications---%
    one to perform the actual assertion,
      and a terminating classification to ensure that the assertion
        yields~$\top$.

  <template name="_assert_"
            desc="Terminate on predicate failure">
    <param name="@values@" desc="Predicates" />

    <param name="@as@" desc="Generated classification name">
      <text unique="true">-assert-</text>
    </param>

    <param name="@failure@" desc="Failure description">
      <text>Assertion</text>
    </param>


    <param name="@neg_as@"
           desc="Generated name for classification to be negated">
      <text unique="true">-nassert-</text>
    </param>
    <param name="@neg_yields@"
           desc="Generated yield for classification to be negated">
      <text unique="true">_nassert</text>
    </param>


    <!-- The actual assertion will be performed by one classification... -->
    <classify as="@neg_as@" yields="@neg_yields@"
              desc="{@failure@} (assertion result)">
      <param-copy name="@values@" />
    </classify>

    <!-- ...which is in turn negated for the terminating
         classification.  The reason for this is that terminating
         classifications terminate on _match_. -->

    <classify as="@as@" desc="@failure@" terminate="true">
      <match on="@neg_yields@" value="FALSE" />
    </classify>
  </template>



  <section title="Standard Assertions">
    There is currently one standard assertion---
      \ref{_assert-nonzero_} (also called \ref{_fail-on-empty_}.

    \ref{_assert-nonzero_} terminates if \tt{@name@} is zero,
      subject to \tt{@when@},
        \tt{@class@},
        and any other provided predicates.

    <template name="_assert-nonzero_"
              desc="Fail when a value is zero">
      <param name="@values@" desc="Optional predicates to include in match" />
      <param name="@name@"   desc="Data to check (scalar, vector or otherwise)" />
      <param name="@when@"   desc="Conditional check (optional)" />
      <param name="@class@"  desc="Conditional class check" />

      <param name="@failure@" desc="Failure description">
        <param-value name="@name@" />
        <text> is empty</text>
      </param>

      <param name="@__classyields@"
             desc="Classification yield to match on">
        <param-class-to-yields name="@class@" />
      </param>


      <t:assert failure="@failure@">
        <if name="@when@">
          <match on="@when@" />
        </if>

        <if name="@class@">
          <match on="@__classyields@" />
        </if>

        <!-- include any optional conditions -->
        <param-copy name="@values@" />

        <t:match-ne on="@name@" value="ZERO" />
      </t:assert>
    </template>


    This template was previously named \ref{_fail-on-empty_},
      so an alias is provided for backwards-compatibility.
    Note that it will display a deprecation warning.

    <template name="_fail-on-empty_"
              desc="Fail when a value is zero (alias for _assert-nonzero_)">
      <param name="@values@" desc="Optional predicates to include in match" />
      <param name="@name@"   desc="Data to check (scalar, vector or otherwise)" />
      <param name="@when@"   desc="Conditional check (optional)" />
      <param name="@class@"  desc="Conditional class check" />

      <param name="@desc@" desc="Description">
        <param-value name="@name@" />
        <text> is empty</text>
      </param>


      <warning>deprecated; use _assert-nonzero_ instead.</warning>

      <t:assert-nonzero name="@name@" when="@when@" class="@class@"
                        failure="@desc@">
        <param-copy name="@values@" />
      </t:assert-nonzero>
    </template>
  </section>
</package>