lawspec 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -1
- package/README.md +34 -26
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +6 -23
- package/bin/lawspec.mjs +148 -65
- package/build.json +245 -177
- package/builtin-data-names.mjs +73 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/examples/native-payments/clojure/lawspec.json +13 -2
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +14 -3
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +14 -3
- package/examples/native-payments/swift/lawspec.json +14 -3
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +57 -53
- package/examples/packages/shop-domain/src/domain.lawspec +36 -33
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +5 -4
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +6 -4
- package/examples/rc1/authorization-snapshots.lawspec +113 -0
- package/examples/rc1/banner-filenames.lawspec +64 -0
- package/examples/rc1/bit-codec.lawspec +57 -0
- package/examples/rc1/bounded-witness-search.lawspec +151 -0
- package/examples/rc1/conflicting-requirements.lawspec +31 -0
- package/examples/rc1/constructive-witnesses.lawspec +120 -0
- package/examples/rc1/documentary-review.lawspec +43 -0
- package/examples/rc1/empty-domains.lawspec +47 -0
- package/examples/rc1/finite-integer-domains.lawspec +76 -0
- package/examples/rc1/law-metadata.lawspec +30 -0
- package/examples/rc1/native-payments.lawspec +108 -0
- package/examples/rc1/nesting/rrr.lawspec +34 -0
- package/examples/rc1/nesting/rru.lawspec +57 -0
- package/examples/rc1/nesting/rur.lawspec +58 -0
- package/examples/rc1/nesting/ruu.lawspec +78 -0
- package/examples/rc1/nesting/urr.lawspec +53 -0
- package/examples/rc1/nesting/uru.lawspec +73 -0
- package/examples/rc1/nesting/uur.lawspec +74 -0
- package/examples/rc1/nesting/uuu.lawspec +96 -0
- package/examples/rc1/order-workflow.lawspec +127 -0
- package/examples/rc1/parcel-measurements.lawspec +93 -0
- package/examples/rc1/picture-records.lawspec +52 -0
- package/examples/rc1/picture-tuples.lawspec +48 -0
- package/examples/rc1/record-payloads.lawspec +57 -0
- package/examples/rc1/recursive-records.lawspec +65 -0
- package/examples/rc1/refund-conformance.lawspec +45 -0
- package/examples/rc1/refund-policy.lawspec +89 -0
- package/examples/rc1/requirement-composition.lawspec +90 -0
- package/examples/rc1/structural-records.lawspec +54 -0
- package/examples/rc1-authoring.lawspec +57 -0
- package/examples/specs/abilities.lawspec +67 -65
- package/examples/specs/ability_imports.lawspec +58 -57
- package/examples/specs/actors.lawspec +23 -22
- package/examples/specs/algebra.lawspec +142 -141
- package/examples/specs/approvals.lawspec +16 -15
- package/examples/specs/async_bindings.lawspec +10 -9
- package/examples/specs/async_fetch.lawspec +12 -11
- package/examples/specs/atoi_codec.lawspec +16 -15
- package/examples/specs/boolean_flags.lawspec +10 -9
- package/examples/specs/builtins.lawspec +73 -72
- package/examples/specs/canonical_url.lawspec +14 -13
- package/examples/specs/collections.lawspec +153 -154
- package/examples/specs/composition.lawspec +70 -66
- package/examples/specs/concurrent_collections.lawspec +8 -7
- package/examples/specs/consistency.lawspec +4 -3
- package/examples/specs/contracts.lawspec +80 -79
- package/examples/specs/crypto.lawspec +26 -25
- package/examples/specs/ctc.lawspec +148 -0
- package/examples/specs/currying.lawspec +32 -31
- package/examples/specs/data_types.lawspec +50 -49
- package/examples/specs/distribution.lawspec +57 -56
- package/examples/specs/domain_modeling.lawspec +48 -47
- package/examples/specs/durations.lawspec +39 -38
- package/examples/specs/equivalent.lawspec +25 -24
- package/examples/specs/failures.lawspec +64 -63
- package/examples/specs/finite_data.lawspec +32 -31
- package/examples/specs/flow_stack.lawspec +64 -63
- package/examples/specs/gadt_expressions.lawspec +50 -49
- package/examples/specs/generation.lawspec +115 -114
- package/examples/specs/handler_bindings.lawspec +42 -40
- package/examples/specs/handles.lawspec +2 -1
- package/examples/specs/harness.lawspec +45 -43
- package/examples/specs/harness_testing.lawspec +18 -13
- package/examples/specs/indexed_arithmetic.lawspec +401 -126
- package/examples/specs/indexed_families.lawspec +182 -66
- package/examples/specs/keywords.lawspec +22 -21
- package/examples/specs/limits.lawspec +6 -5
- package/examples/specs/list_contracts.lawspec +121 -120
- package/examples/specs/list_refinements.lawspec +43 -42
- package/examples/specs/lists.lawspec +45 -44
- package/examples/specs/matchers.lawspec +79 -78
- package/examples/specs/matching.lawspec +43 -42
- package/examples/specs/mixed_inputs.lawspec +25 -24
- package/examples/specs/models.lawspec +44 -43
- package/examples/specs/parse_port.lawspec +28 -27
- package/examples/specs/payments.lawspec +55 -54
- package/examples/specs/railway.lawspec +59 -58
- package/examples/specs/records.lawspec +149 -148
- package/examples/specs/records_inner.lawspec +5 -4
- package/examples/specs/recursive_refinements.lawspec +30 -29
- package/examples/specs/refined_definitions.lawspec +24 -23
- package/examples/specs/refinements.lawspec +58 -57
- package/examples/specs/resilience.lawspec +159 -158
- package/examples/specs/resources.lawspec +61 -60
- package/examples/specs/scalar_adapters.lawspec +60 -59
- package/examples/specs/scalar_catalog.lawspec +165 -164
- package/examples/specs/scalars.lawspec +78 -77
- package/examples/specs/scheduling_order.lawspec +8 -7
- package/examples/specs/scheduling_overlap.lawspec +5 -4
- package/examples/specs/sequences.lawspec +66 -65
- package/examples/specs/sessions.lawspec +13 -12
- package/examples/specs/slug.lawspec +16 -15
- package/examples/specs/sum_refinements.lawspec +42 -41
- package/examples/specs/tables.lawspec +29 -28
- package/examples/specs/total_functions.lawspec +71 -70
- package/examples/specs/workflows.lawspec +101 -100
- package/examples-command.mjs +8 -4
- package/explain.mjs +114 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +406 -11
- package/launcher.mjs +9 -2
- package/lsp.mjs +235 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/starter-rc1.lawspec +26 -0
- package/starter.lawspec +16 -15
- package/templates.mjs +6 -4
- package/test-command.mjs +107 -35
- package/typed-presentation.mjs +165 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
unit example.rc1.constructiveWitnesses
|
|
2
|
+
|
|
3
|
+
type RequestLabel is a record{
|
|
4
|
+
text of type Text
|
|
5
|
+
}
|
|
6
|
+
end type
|
|
7
|
+
|
|
8
|
+
function keep (value of type a) -> a is
|
|
9
|
+
value
|
|
10
|
+
end function
|
|
11
|
+
|
|
12
|
+
function increment (value of type Integer) -> Integer is
|
|
13
|
+
value + 1
|
|
14
|
+
end function
|
|
15
|
+
|
|
16
|
+
function "|add for approval| (left of type Integer) (right of type Integer) -> Integer is
|
|
17
|
+
left + right
|
|
18
|
+
end function
|
|
19
|
+
|
|
20
|
+
function labelFor (allowed of type Bool) -> RequestLabel is
|
|
21
|
+
RequestLabel record{text = if allowed then "approved" else "declined" end if}
|
|
22
|
+
end function
|
|
23
|
+
|
|
24
|
+
function amountDescription (amount of type Integer) -> Text is
|
|
25
|
+
if amount > 0 then "positive" else "nonpositive" end if
|
|
26
|
+
end function
|
|
27
|
+
|
|
28
|
+
law "|every integer has a successor| is
|
|
29
|
+
description:
|
|
30
|
+
"Every exact integer has a larger integer exactly one step away."
|
|
31
|
+
end description
|
|
32
|
+
definition:
|
|
33
|
+
for all (value of type Integer) =>
|
|
34
|
+
there exists (answer of type Integer where answer > value) such that
|
|
35
|
+
answer must be value + 1
|
|
36
|
+
end exists
|
|
37
|
+
end for all
|
|
38
|
+
end definition
|
|
39
|
+
expect increment value = expected
|
|
40
|
+
in table (value, expected):
|
|
41
|
+
row -1, 0
|
|
42
|
+
row 0, 1
|
|
43
|
+
row 1, 2
|
|
44
|
+
end table
|
|
45
|
+
end law
|
|
46
|
+
|
|
47
|
+
law "|each request has a matching label| is
|
|
48
|
+
description:
|
|
49
|
+
"An allowed request can be labelled approved; another can be labelled declined."
|
|
50
|
+
end description
|
|
51
|
+
definition:
|
|
52
|
+
for all (allowed of type Bool) =>
|
|
53
|
+
there exists (label of type RequestLabel) such that
|
|
54
|
+
label.text must be (if allowed then "approved" else "declined" end if)
|
|
55
|
+
end exists
|
|
56
|
+
end for all
|
|
57
|
+
end definition
|
|
58
|
+
end law
|
|
59
|
+
|
|
60
|
+
law "|positive amounts have a description| is
|
|
61
|
+
definition:
|
|
62
|
+
for all (allowed of type Bool) =>
|
|
63
|
+
there exists (amount of type Integer where amount > 0) such that
|
|
64
|
+
there exists (word of type Text) such that
|
|
65
|
+
word must be "positive"
|
|
66
|
+
end exists
|
|
67
|
+
end exists
|
|
68
|
+
end for all
|
|
69
|
+
end definition
|
|
70
|
+
end law
|
|
71
|
+
|
|
72
|
+
law "|separate requirements can choose separate values| is
|
|
73
|
+
definition:
|
|
74
|
+
(there exists (value of type Integer) such that value = 1 end exists)
|
|
75
|
+
and
|
|
76
|
+
(there exists (value of type Integer) such that value = 2 end exists)
|
|
77
|
+
end definition
|
|
78
|
+
end law
|
|
79
|
+
|
|
80
|
+
law "|a request cannot be both allowed and disallowed| is
|
|
81
|
+
definition:
|
|
82
|
+
there must not exist (allowed of type Bool) such that
|
|
83
|
+
allowed and not allowed
|
|
84
|
+
end exists
|
|
85
|
+
end definition
|
|
86
|
+
end law
|
|
87
|
+
|
|
88
|
+
law "|an empty request domain needs no witness| is
|
|
89
|
+
definition:
|
|
90
|
+
for all (allowed of type Bool where false) =>
|
|
91
|
+
there exists (answer of type Integer) such that
|
|
92
|
+
false
|
|
93
|
+
end exists
|
|
94
|
+
end for all
|
|
95
|
+
end definition
|
|
96
|
+
end law
|
|
97
|
+
|
|
98
|
+
harness example.rc1.constructiveWitnesses.testing for example.rc1.constructiveWitnesses is
|
|
99
|
+
for law "|every integer has a successor|
|
|
100
|
+
witness keep (value `|add for approval| 1) for definition.value.answer
|
|
101
|
+
end for law
|
|
102
|
+
for law "|each request has a matching label|
|
|
103
|
+
witness keep (labelFor allowed) for allowed.label
|
|
104
|
+
end for law
|
|
105
|
+
for law "|positive amounts have a description|
|
|
106
|
+
witness (if allowed then 1 else 2 end if) for allowed.amount
|
|
107
|
+
witness keep (amountDescription amount) for allowed.amount.word
|
|
108
|
+
end for law
|
|
109
|
+
for law "|separate requirements can choose separate values|
|
|
110
|
+
witness 1 for branch1.value
|
|
111
|
+
witness 2 for branch2.value
|
|
112
|
+
end for law
|
|
113
|
+
for law "|a request cannot be both allowed and disallowed|
|
|
114
|
+
witness false for allowed
|
|
115
|
+
end for law
|
|
116
|
+
for law "|an empty request domain needs no witness|
|
|
117
|
+
witness 0 for allowed.answer
|
|
118
|
+
end for law
|
|
119
|
+
end harness
|
|
120
|
+
end unit
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
unit example.rc1.documentaryReview
|
|
2
|
+
|
|
3
|
+
type Review is one of
|
|
4
|
+
| Approved
|
|
5
|
+
| Declined
|
|
6
|
+
end type
|
|
7
|
+
|
|
8
|
+
function review (allowed of type Bool) -> Review is
|
|
9
|
+
if allowed then Approved else Declined end if
|
|
10
|
+
end function
|
|
11
|
+
|
|
12
|
+
law "|allowed requests are approved| is
|
|
13
|
+
id: "REVIEW-001"
|
|
14
|
+
owner: Payments.Review
|
|
15
|
+
description:
|
|
16
|
+
"An allowed request receives approval."
|
|
17
|
+
end description
|
|
18
|
+
definition:
|
|
19
|
+
review true must be Approved
|
|
20
|
+
end definition
|
|
21
|
+
references:
|
|
22
|
+
#S{ref law "|other requests are declined| description,
|
|
23
|
+
ref function review}
|
|
24
|
+
ref law "|other requests are declined| references."|Review policy|
|
|
25
|
+
"|Review policy|: "Allowed requests are approved; all other requests are declined."
|
|
26
|
+
end references
|
|
27
|
+
end law
|
|
28
|
+
|
|
29
|
+
law "|other requests are declined| is
|
|
30
|
+
owner: Payments.Review
|
|
31
|
+
id: "REVIEW-002"
|
|
32
|
+
description:
|
|
33
|
+
"A request without permission receives a decline."
|
|
34
|
+
end description
|
|
35
|
+
definition:
|
|
36
|
+
review false must be Declined
|
|
37
|
+
end definition
|
|
38
|
+
references:
|
|
39
|
+
ref law "|allowed requests are approved| definition
|
|
40
|
+
"|Review policy|: "Allowed requests are approved; all other requests are declined."
|
|
41
|
+
end references
|
|
42
|
+
end law
|
|
43
|
+
end unit
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
unit example.rc1.emptyDomains
|
|
2
|
+
|
|
3
|
+
type UnissuedApproval is one of
|
|
4
|
+
| Unissued of type UnissuedApproval
|
|
5
|
+
| StillUnissued of type UnissuedApproval
|
|
6
|
+
end type
|
|
7
|
+
|
|
8
|
+
law "|no issued approval incurs an obligation| is
|
|
9
|
+
definition:
|
|
10
|
+
for all (approval of type UnissuedApproval) =>
|
|
11
|
+
false
|
|
12
|
+
end for all
|
|
13
|
+
end definition
|
|
14
|
+
description:
|
|
15
|
+
"No approval can be constructed in this domain. Universal verification evaluates zero cases."
|
|
16
|
+
end description
|
|
17
|
+
end law
|
|
18
|
+
|
|
19
|
+
law "|excluded inputs require no witnesses| is
|
|
20
|
+
definition:
|
|
21
|
+
for all (enabled of type Bool where false) =>
|
|
22
|
+
there must exist (witness of type Integer) such that
|
|
23
|
+
false
|
|
24
|
+
end exists
|
|
25
|
+
end for all
|
|
26
|
+
end definition
|
|
27
|
+
description:
|
|
28
|
+
"The restriction excludes every input. This establishes no witness for any actual input."
|
|
29
|
+
end description
|
|
30
|
+
end law
|
|
31
|
+
|
|
32
|
+
law "|absence remains different from existence| is
|
|
33
|
+
definition:
|
|
34
|
+
there must not exist (approval of type UnissuedApproval) such that
|
|
35
|
+
true
|
|
36
|
+
end exists
|
|
37
|
+
end definition
|
|
38
|
+
end law
|
|
39
|
+
|
|
40
|
+
law "|excluded payments incur no obligation| is
|
|
41
|
+
definition:
|
|
42
|
+
for all (eligible of type Bool where false) =>
|
|
43
|
+
false
|
|
44
|
+
end for all
|
|
45
|
+
end definition
|
|
46
|
+
end law
|
|
47
|
+
end unit
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
unit example.rc1.finiteIntegerDomains
|
|
2
|
+
|
|
3
|
+
function credit (amount of type Integer) -> Integer is
|
|
4
|
+
amount + 1
|
|
5
|
+
end function
|
|
6
|
+
|
|
7
|
+
law "|each small credit has its exact settlement amount| is
|
|
8
|
+
description:
|
|
9
|
+
"Every amount from zero through three receives exactly one extra cent."
|
|
10
|
+
end description
|
|
11
|
+
definition:
|
|
12
|
+
for all (amount of type Integer where amount >= 0 and amount <= 3) =>
|
|
13
|
+
there exists (settled of type Integer where
|
|
14
|
+
settled >= amount + 1 and settled <= amount + 1) such that
|
|
15
|
+
settled must be credit amount
|
|
16
|
+
end exists
|
|
17
|
+
end for all
|
|
18
|
+
end definition
|
|
19
|
+
expect credit amount = expected
|
|
20
|
+
in table (amount, expected):
|
|
21
|
+
row 0, 1
|
|
22
|
+
row 1, 2
|
|
23
|
+
row 2, 3
|
|
24
|
+
row 3, 4
|
|
25
|
+
end table
|
|
26
|
+
end law
|
|
27
|
+
|
|
28
|
+
law "|small retry budgets include zero| is
|
|
29
|
+
definition:
|
|
30
|
+
for all (budget of type Whole where budget <= 3) =>
|
|
31
|
+
must budget >= 0
|
|
32
|
+
end for all
|
|
33
|
+
end definition
|
|
34
|
+
end law
|
|
35
|
+
|
|
36
|
+
law "|positive attempt counts exclude zero| is
|
|
37
|
+
definition:
|
|
38
|
+
there must not exist (attempts of type Nat where attempts <= 3) such that
|
|
39
|
+
attempts = 0
|
|
40
|
+
end exists
|
|
41
|
+
end definition
|
|
42
|
+
end law
|
|
43
|
+
|
|
44
|
+
law "|a small credit cannot settle outside the limit| is
|
|
45
|
+
definition:
|
|
46
|
+
there must not exist (settled of type Integer where
|
|
47
|
+
settled >= 0 and settled <= 3) such that
|
|
48
|
+
settled = 4
|
|
49
|
+
end exists
|
|
50
|
+
end definition
|
|
51
|
+
end law
|
|
52
|
+
|
|
53
|
+
law "|consecutive exact cents have no intermediate amount| is
|
|
54
|
+
description:
|
|
55
|
+
"No exact integer amount lies strictly between two consecutive cents."
|
|
56
|
+
end description
|
|
57
|
+
definition:
|
|
58
|
+
for all (amount of type Integer)
|
|
59
|
+
(between of type Integer where between > amount and between < amount + 1)
|
|
60
|
+
=>
|
|
61
|
+
false
|
|
62
|
+
end for all
|
|
63
|
+
end definition
|
|
64
|
+
end law
|
|
65
|
+
|
|
66
|
+
law "|every exact amount has an adjacent settlement amount| is
|
|
67
|
+
definition:
|
|
68
|
+
for all (amount of type Integer) =>
|
|
69
|
+
there exists (settled of type Integer where
|
|
70
|
+
settled > amount and settled <= amount + 2) such that
|
|
71
|
+
settled must be amount + 1
|
|
72
|
+
end exists
|
|
73
|
+
end for all
|
|
74
|
+
end definition
|
|
75
|
+
end law
|
|
76
|
+
end unit
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
unit example.rc1.lawMetadata
|
|
2
|
+
|
|
3
|
+
type Review is one of
|
|
4
|
+
| Approved
|
|
5
|
+
| Declined
|
|
6
|
+
end type
|
|
7
|
+
|
|
8
|
+
function review (allowed of type Bool) -> Review is
|
|
9
|
+
if allowed then Approved else Declined end if
|
|
10
|
+
end function
|
|
11
|
+
|
|
12
|
+
law "|allowed requests are approved| is
|
|
13
|
+
id: "REVIEW-001"
|
|
14
|
+
owner: Payments.Review
|
|
15
|
+
description:
|
|
16
|
+
"An allowed request receives approval."
|
|
17
|
+
end description
|
|
18
|
+
definition:
|
|
19
|
+
review true must be Approved
|
|
20
|
+
end definition
|
|
21
|
+
end law
|
|
22
|
+
|
|
23
|
+
law "|other requests are declined| is
|
|
24
|
+
owner: Payments.Review
|
|
25
|
+
id: "REVIEW-002"
|
|
26
|
+
definition:
|
|
27
|
+
review false must be Declined
|
|
28
|
+
end definition
|
|
29
|
+
end law
|
|
30
|
+
end unit
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
unit example.payments
|
|
2
|
+
|
|
3
|
+
-- Executable acceptance model for canonical native domain bindings.
|
|
4
|
+
-- Applications may call Money "Price", amount "major", and currency "unit";
|
|
5
|
+
-- those representation choices must not alter these laws.
|
|
6
|
+
type Currency is one of
|
|
7
|
+
| USD
|
|
8
|
+
| EUR
|
|
9
|
+
| GBP
|
|
10
|
+
end type
|
|
11
|
+
|
|
12
|
+
type Money is a record{
|
|
13
|
+
amount of type Decimal
|
|
14
|
+
currency of type Currency
|
|
15
|
+
}
|
|
16
|
+
end type
|
|
17
|
+
|
|
18
|
+
type Payment is one of
|
|
19
|
+
| Paid of type Money
|
|
20
|
+
| Declined of type Text
|
|
21
|
+
end type
|
|
22
|
+
|
|
23
|
+
addFee of type Money -> Money
|
|
24
|
+
roundTrip of type Payment -> Payment
|
|
25
|
+
archive of type List (Maybe Payment) -> List (Maybe Payment)
|
|
26
|
+
|
|
27
|
+
function feeModel (money of type Money) -> Money is
|
|
28
|
+
first matching case of money:
|
|
29
|
+
when Money record{amount = amount, currency = currency} then
|
|
30
|
+
Money record{amount = amount + 0.2, currency = currency}
|
|
31
|
+
end case
|
|
32
|
+
end function
|
|
33
|
+
|
|
34
|
+
law "|fees preserve currency and exact decimal value| is
|
|
35
|
+
definition:
|
|
36
|
+
for all (money of type Money) =>
|
|
37
|
+
addFee money must be feeModel money
|
|
38
|
+
end for all
|
|
39
|
+
end definition
|
|
40
|
+
|
|
41
|
+
example "|decimal tenths|:
|
|
42
|
+
money = Money record{amount = 0.1, currency = USD}
|
|
43
|
+
expect addFee money = Money record{amount = 0.3, currency = USD}
|
|
44
|
+
end example
|
|
45
|
+
|
|
46
|
+
example "|small amount is not rounded away|:
|
|
47
|
+
money = Money record{
|
|
48
|
+
amount = 0.000000000000000000000000000001, currency = EUR
|
|
49
|
+
}
|
|
50
|
+
expect addFee money = Money record{
|
|
51
|
+
amount = 0.200000000000000000000000000001, currency = EUR
|
|
52
|
+
}
|
|
53
|
+
end example
|
|
54
|
+
|
|
55
|
+
example "|beyond binary floating precision|:
|
|
56
|
+
money = Money record{amount = 9007199254740993.1, currency = GBP}
|
|
57
|
+
expect addFee money = Money record{
|
|
58
|
+
amount = 9007199254740993.3, currency = GBP
|
|
59
|
+
}
|
|
60
|
+
end example
|
|
61
|
+
end law
|
|
62
|
+
|
|
63
|
+
law "|payment variants and payloads survive native conversion| is
|
|
64
|
+
definition:
|
|
65
|
+
for all (payment of type Payment) =>
|
|
66
|
+
roundTrip payment must be payment
|
|
67
|
+
end for all
|
|
68
|
+
end definition
|
|
69
|
+
|
|
70
|
+
example "|successful payment|:
|
|
71
|
+
payment = Paid (Money record{amount = 12.34, currency = EUR})
|
|
72
|
+
expect roundTrip payment = Paid (Money record{
|
|
73
|
+
amount = 12.34, currency = EUR
|
|
74
|
+
})
|
|
75
|
+
end example
|
|
76
|
+
|
|
77
|
+
example "|declined payment|:
|
|
78
|
+
payment = Declined "card declined"
|
|
79
|
+
expect roundTrip payment = Declined "card declined"
|
|
80
|
+
end example
|
|
81
|
+
end law
|
|
82
|
+
|
|
83
|
+
law "|archives preserve order duplicates and absence| is
|
|
84
|
+
definition:
|
|
85
|
+
for all (payments of type List (Maybe Payment)) =>
|
|
86
|
+
archive payments must be payments
|
|
87
|
+
end for all
|
|
88
|
+
end definition
|
|
89
|
+
|
|
90
|
+
example "|empty archive|:
|
|
91
|
+
payments = []
|
|
92
|
+
expect archive payments = []
|
|
93
|
+
end example
|
|
94
|
+
|
|
95
|
+
example "|missing is different from a declined payment|:
|
|
96
|
+
payments = [
|
|
97
|
+
Nothing, Just (Declined ""),
|
|
98
|
+
Just (Paid (Money record{amount = 0.1, currency = USD})),
|
|
99
|
+
Just (Paid (Money record{amount = 0.1, currency = USD}))
|
|
100
|
+
]
|
|
101
|
+
expect archive payments = [
|
|
102
|
+
Nothing, Just (Declined ""),
|
|
103
|
+
Just (Paid (Money record{amount = 0.1, currency = USD})),
|
|
104
|
+
Just (Paid (Money record{amount = 0.1, currency = USD}))
|
|
105
|
+
]
|
|
106
|
+
end example
|
|
107
|
+
end law
|
|
108
|
+
end unit
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
unit example.delivery.rrr
|
|
2
|
+
|
|
3
|
+
type EmailDelivery is a record{
|
|
4
|
+
recipient of type Text
|
|
5
|
+
document of type record{number of type Text
|
|
6
|
+
file of type record{fileName of type Text
|
|
7
|
+
byteCount of type Whole}}
|
|
8
|
+
}
|
|
9
|
+
end type
|
|
10
|
+
|
|
11
|
+
function "|email invoice PDF file name|
|
|
12
|
+
(delivery of type EmailDelivery) -> Maybe Text is
|
|
13
|
+
first matching case of delivery:
|
|
14
|
+
when record{document = record{file = record{fileName = name}}}
|
|
15
|
+
then Just name
|
|
16
|
+
end case
|
|
17
|
+
end function
|
|
18
|
+
|
|
19
|
+
function emailPdfInvoice (name of type Text) -> EmailDelivery is
|
|
20
|
+
EmailDelivery record{recipient = "accounts@example.com", document =
|
|
21
|
+
record{number = "INV-2026-10", file = record{fileName = name,
|
|
22
|
+
byteCount = 1200}}}
|
|
23
|
+
end function
|
|
24
|
+
|
|
25
|
+
law "|emailPdfInvoice result| is
|
|
26
|
+
description:
|
|
27
|
+
"PDF invoices sent by email retain their file names."
|
|
28
|
+
end description
|
|
29
|
+
definition:
|
|
30
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
31
|
+
"invoice.pdf"
|
|
32
|
+
end definition
|
|
33
|
+
end law
|
|
34
|
+
end unit
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
unit example.delivery.rru
|
|
2
|
+
|
|
3
|
+
type File is one of
|
|
4
|
+
| Pdf of type record{fileName of type Text
|
|
5
|
+
byteCount of type Whole}
|
|
6
|
+
| PlainText of type record{fileName of type Text}
|
|
7
|
+
end type
|
|
8
|
+
|
|
9
|
+
type EmailDelivery is a record{
|
|
10
|
+
recipient of type Text
|
|
11
|
+
document of type record{number of type Text
|
|
12
|
+
file of type File}
|
|
13
|
+
}
|
|
14
|
+
end type
|
|
15
|
+
|
|
16
|
+
function "|email invoice PDF file name|
|
|
17
|
+
(delivery of type EmailDelivery) -> Maybe Text is
|
|
18
|
+
first matching case of delivery:
|
|
19
|
+
when record{document = record{file = Pdf record{fileName = name}}}
|
|
20
|
+
then Just name
|
|
21
|
+
otherwise Nothing
|
|
22
|
+
end case
|
|
23
|
+
end function
|
|
24
|
+
|
|
25
|
+
function emailPdfInvoice (name of type Text) -> EmailDelivery is
|
|
26
|
+
EmailDelivery record{recipient = "accounts@example.com", document =
|
|
27
|
+
record{number = "INV-2026-10", file = (Pdf (record{fileName =
|
|
28
|
+
name,
|
|
29
|
+
byteCount = 1200}))}}
|
|
30
|
+
end function
|
|
31
|
+
|
|
32
|
+
law "|emailPdfInvoice result| is
|
|
33
|
+
description:
|
|
34
|
+
"PDF invoices sent by email retain their file names."
|
|
35
|
+
end description
|
|
36
|
+
definition:
|
|
37
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
38
|
+
"invoice.pdf"
|
|
39
|
+
end definition
|
|
40
|
+
end law
|
|
41
|
+
|
|
42
|
+
function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
|
|
43
|
+
EmailDelivery record{recipient = "accounts@example.com", document =
|
|
44
|
+
record{number = "INV-2026-10", file = (PlainText (record{fileName =
|
|
45
|
+
name}))}}
|
|
46
|
+
end function
|
|
47
|
+
|
|
48
|
+
law "|emailPlainTextInvoice result| is
|
|
49
|
+
description:
|
|
50
|
+
"Plain-text invoices have no PDF file name."
|
|
51
|
+
end description
|
|
52
|
+
definition:
|
|
53
|
+
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
54
|
+
Nothing
|
|
55
|
+
end definition
|
|
56
|
+
end law
|
|
57
|
+
end unit
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
unit example.delivery.rur
|
|
2
|
+
|
|
3
|
+
type Document is one of
|
|
4
|
+
| Invoice of type record{number of type Text
|
|
5
|
+
file of type record{fileName of type Text
|
|
6
|
+
byteCount of type Whole}}
|
|
7
|
+
| Letter of type record{subject of type Text
|
|
8
|
+
file of type record{fileName of type Text
|
|
9
|
+
byteCount of type Whole}}
|
|
10
|
+
end type
|
|
11
|
+
|
|
12
|
+
type EmailDelivery is a record{
|
|
13
|
+
recipient of type Text
|
|
14
|
+
document of type Document
|
|
15
|
+
}
|
|
16
|
+
end type
|
|
17
|
+
|
|
18
|
+
function "|email invoice PDF file name|
|
|
19
|
+
(delivery of type EmailDelivery) -> Maybe Text is
|
|
20
|
+
first matching case of delivery:
|
|
21
|
+
when record{document = Invoice record{file = record{fileName = name}}}
|
|
22
|
+
then Just name
|
|
23
|
+
otherwise Nothing
|
|
24
|
+
end case
|
|
25
|
+
end function
|
|
26
|
+
|
|
27
|
+
function emailPdfInvoice (name of type Text) -> EmailDelivery is
|
|
28
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
|
|
29
|
+
(record{number = "INV-2026-10", file = record{fileName
|
|
30
|
+
= name, byteCount = 1200}}))}
|
|
31
|
+
end function
|
|
32
|
+
|
|
33
|
+
law "|emailPdfInvoice result| is
|
|
34
|
+
description:
|
|
35
|
+
"PDF invoices sent by email retain their file names."
|
|
36
|
+
end description
|
|
37
|
+
definition:
|
|
38
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
39
|
+
"invoice.pdf"
|
|
40
|
+
end definition
|
|
41
|
+
end law
|
|
42
|
+
|
|
43
|
+
function emailPdfLetter (name of type Text) -> EmailDelivery is
|
|
44
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Letter
|
|
45
|
+
(record{subject = "Receipt", file = record{fileName =
|
|
46
|
+
name, byteCount = 1200}}))}
|
|
47
|
+
end function
|
|
48
|
+
|
|
49
|
+
law "|emailPdfLetter result| is
|
|
50
|
+
description:
|
|
51
|
+
"Letters have no invoice PDF file name."
|
|
52
|
+
end description
|
|
53
|
+
definition:
|
|
54
|
+
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
55
|
+
Nothing
|
|
56
|
+
end definition
|
|
57
|
+
end law
|
|
58
|
+
end unit
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
unit example.delivery.ruu
|
|
2
|
+
|
|
3
|
+
type File is one of
|
|
4
|
+
| Pdf of type record{fileName of type Text
|
|
5
|
+
byteCount of type Whole}
|
|
6
|
+
| PlainText of type record{fileName of type Text}
|
|
7
|
+
end type
|
|
8
|
+
|
|
9
|
+
type Document is one of
|
|
10
|
+
| Invoice of type record{number of type Text
|
|
11
|
+
file of type File}
|
|
12
|
+
| Letter of type record{subject of type Text
|
|
13
|
+
file of type File}
|
|
14
|
+
end type
|
|
15
|
+
|
|
16
|
+
type EmailDelivery is a record{
|
|
17
|
+
recipient of type Text
|
|
18
|
+
document of type Document
|
|
19
|
+
}
|
|
20
|
+
end type
|
|
21
|
+
|
|
22
|
+
function "|email invoice PDF file name|
|
|
23
|
+
(delivery of type EmailDelivery) -> Maybe Text is
|
|
24
|
+
first matching case of delivery:
|
|
25
|
+
when record{document = Invoice record{file = Pdf record{fileName = name}}}
|
|
26
|
+
then Just name
|
|
27
|
+
otherwise Nothing
|
|
28
|
+
end case
|
|
29
|
+
end function
|
|
30
|
+
|
|
31
|
+
function emailPdfInvoice (name of type Text) -> EmailDelivery is
|
|
32
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
|
|
33
|
+
(record{number = "INV-2026-10", file = (Pdf (record{fileName = name,
|
|
34
|
+
byteCount = 1200}))}))}
|
|
35
|
+
end function
|
|
36
|
+
|
|
37
|
+
law "|emailPdfInvoice result| is
|
|
38
|
+
description:
|
|
39
|
+
"PDF invoices sent by email retain their file names."
|
|
40
|
+
end description
|
|
41
|
+
definition:
|
|
42
|
+
"|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
|
|
43
|
+
"invoice.pdf"
|
|
44
|
+
end definition
|
|
45
|
+
end law
|
|
46
|
+
|
|
47
|
+
function emailPlainTextInvoice (name of type Text) -> EmailDelivery is
|
|
48
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Invoice
|
|
49
|
+
(record{number = "INV-2026-10", file = (PlainText
|
|
50
|
+
(record{fileName = name}))}))}
|
|
51
|
+
end function
|
|
52
|
+
|
|
53
|
+
law "|emailPlainTextInvoice result| is
|
|
54
|
+
description:
|
|
55
|
+
"Plain-text invoices have no PDF file name."
|
|
56
|
+
end description
|
|
57
|
+
definition:
|
|
58
|
+
"|email invoice PDF file name| (emailPlainTextInvoice "invoice.pdf") must be
|
|
59
|
+
Nothing
|
|
60
|
+
end definition
|
|
61
|
+
end law
|
|
62
|
+
|
|
63
|
+
function emailPdfLetter (name of type Text) -> EmailDelivery is
|
|
64
|
+
EmailDelivery record{recipient = "accounts@example.com", document = (Letter
|
|
65
|
+
(record{subject = "Receipt", file = (Pdf (record{fileName = name, byteCount
|
|
66
|
+
= 1200}))}))}
|
|
67
|
+
end function
|
|
68
|
+
|
|
69
|
+
law "|emailPdfLetter result| is
|
|
70
|
+
description:
|
|
71
|
+
"Letters have no invoice PDF file name."
|
|
72
|
+
end description
|
|
73
|
+
definition:
|
|
74
|
+
"|email invoice PDF file name| (emailPdfLetter "invoice.pdf") must be
|
|
75
|
+
Nothing
|
|
76
|
+
end definition
|
|
77
|
+
end law
|
|
78
|
+
end unit
|