lawspec 0.23.0 → 0.25.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +167 -1
  2. package/README.md +29 -22
  3. package/UNICODE-LICENSE.txt +39 -0
  4. package/api.mjs +14 -23
  5. package/bin/lawspec.mjs +200 -67
  6. package/build.json +381 -155
  7. package/builtin-data-names.mjs +73 -0
  8. package/compatibility.json +21 -0
  9. package/core.wasm +2 -2
  10. package/doctor.mjs +98 -1
  11. package/examples/native-payments/clojure/lawspec.json +62 -0
  12. package/examples/native-payments/clojure/src/domain/payments.clj +11 -0
  13. package/examples/native-payments/clojure/test/domain/payment_generators.clj +9 -0
  14. package/examples/native-payments/csharp/lawspec.json +13 -2
  15. package/examples/native-payments/elixir/lawspec.json +14 -3
  16. package/examples/native-payments/erlang/lawspec.json +14 -3
  17. package/examples/native-payments/fsharp/lawspec.json +14 -3
  18. package/examples/native-payments/gleam/lawspec.json +14 -3
  19. package/examples/native-payments/go/lawspec.json +14 -3
  20. package/examples/native-payments/groovy/lawspec.json +176 -0
  21. package/examples/native-payments/groovy/src/main/groovy/domain/PaymentsDomain.groovy +49 -0
  22. package/examples/native-payments/groovy/src/test/groovy/domain/PaymentGenerators.groovy +15 -0
  23. package/examples/native-payments/haskell/lawspec.json +14 -3
  24. package/examples/native-payments/java/lawspec.json +14 -3
  25. package/examples/native-payments/javascript/lawspec.json +14 -3
  26. package/examples/native-payments/kotlin/lawspec.json +14 -3
  27. package/examples/native-payments/python/lawspec.json +14 -3
  28. package/examples/native-payments/rust/lawspec.json +14 -3
  29. package/examples/native-payments/scala/lawspec.json +176 -0
  30. package/examples/native-payments/scala/src/main/scala/domain/PaymentsDomain.scala +18 -0
  31. package/examples/native-payments/scala/src/test/scala/domain/PaymentGenerators.scala +8 -0
  32. package/examples/native-payments/swift/lawspec.json +165 -0
  33. package/examples/native-payments/swift/src/Native/PaymentsDomain.swift +35 -0
  34. package/examples/native-payments/swift/tests/Native/PaymentGenerators.swift +12 -0
  35. package/examples/native-payments/typescript/lawspec.json +14 -3
  36. package/examples/packages/orders/lawspec.json +25 -5
  37. package/examples/packages/orders/orders.lawspec +36 -34
  38. package/examples/packages/shop-domain/src/domain.lawspec +23 -21
  39. package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
  40. package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
  41. package/examples/rc1/authorization-snapshots.lawspec +112 -0
  42. package/examples/rc1/banner-filenames.lawspec +63 -0
  43. package/examples/rc1/bit-codec.lawspec +56 -0
  44. package/examples/rc1/bounded-witness-search.lawspec +144 -0
  45. package/examples/rc1/conflicting-requirements.lawspec +30 -0
  46. package/examples/rc1/constructive-witnesses.lawspec +113 -0
  47. package/examples/rc1/documentary-review.lawspec +42 -0
  48. package/examples/rc1/empty-domains.lawspec +46 -0
  49. package/examples/rc1/finite-integer-domains.lawspec +75 -0
  50. package/examples/rc1/law-metadata.lawspec +29 -0
  51. package/examples/rc1/native-payments.lawspec +107 -0
  52. package/examples/rc1/nesting/rrr.lawspec +33 -0
  53. package/examples/rc1/nesting/rru.lawspec +56 -0
  54. package/examples/rc1/nesting/rur.lawspec +57 -0
  55. package/examples/rc1/nesting/ruu.lawspec +77 -0
  56. package/examples/rc1/nesting/urr.lawspec +52 -0
  57. package/examples/rc1/nesting/uru.lawspec +72 -0
  58. package/examples/rc1/nesting/uur.lawspec +73 -0
  59. package/examples/rc1/nesting/uuu.lawspec +95 -0
  60. package/examples/rc1/order-workflow.lawspec +126 -0
  61. package/examples/rc1/parcel-measurements.lawspec +92 -0
  62. package/examples/rc1/picture-records.lawspec +51 -0
  63. package/examples/rc1/picture-tuples.lawspec +47 -0
  64. package/examples/rc1/record-payloads.lawspec +56 -0
  65. package/examples/rc1/recursive-records.lawspec +64 -0
  66. package/examples/rc1/refund-conformance.lawspec +44 -0
  67. package/examples/rc1/refund-policy.lawspec +88 -0
  68. package/examples/rc1/requirement-composition.lawspec +89 -0
  69. package/examples/rc1/structural-records.lawspec +53 -0
  70. package/examples/rc1-authoring.lawspec +56 -0
  71. package/examples-command.mjs +11 -5
  72. package/explain.mjs +112 -0
  73. package/expression-presentation.mjs +333 -0
  74. package/files.mjs +16 -0
  75. package/index.d.ts +934 -12
  76. package/lsp.mjs +231 -0
  77. package/migrate.mjs +135 -0
  78. package/migration-bindings.mjs +86 -0
  79. package/migration-cases.mjs +45 -0
  80. package/migration-collections.mjs +54 -0
  81. package/migration-correspondence.mjs +275 -0
  82. package/migration-generation.mjs +99 -0
  83. package/migration-laws.mjs +102 -0
  84. package/migration-records.mjs +166 -0
  85. package/migration-source.mjs +247 -0
  86. package/migration-write.mjs +156 -0
  87. package/native-evidence.mjs +187 -0
  88. package/native-examples.mjs +8 -1
  89. package/node-events-reporter.mjs +23 -0
  90. package/package.json +8 -1
  91. package/positional-fields.mjs +13 -0
  92. package/proof.d.ts +35 -0
  93. package/proof.mjs +174 -0
  94. package/scala-coverage.mjs +56 -0
  95. package/starter-rc1.lawspec +25 -0
  96. package/templates.mjs +65 -3
  97. package/test-command.mjs +177 -29
  98. package/typed-presentation.mjs +165 -0
@@ -0,0 +1,56 @@
1
+ unit example.rc1.bitCodec
2
+
3
+ mapping bitText of type Bool -> Text is
4
+ row false, "0"
5
+ row true, "1"
6
+ end mapping
7
+
8
+ function decodeBit (text of type Text) -> Maybe Bool is
9
+ bitTextInverse text
10
+ end function
11
+
12
+ function "|decode with zero default| (text of type Text) -> Bool is
13
+ first matching case of decodeBit text:
14
+ when Just bit then bit
15
+ when Nothing then false
16
+ end case
17
+ end function
18
+
19
+ law "|each bit is recovered| is
20
+ definition:
21
+ for all (bit of type Bool) =>
22
+ decodeBit (bitText bit) must be Just bit
23
+ end
24
+ end
25
+
26
+ description:
27
+ "Each bit has a one-character encoding that decodes to the original bit."
28
+ end
29
+
30
+ expect bitText bit = encoded
31
+ expect decodeBit encoded = decoded
32
+ in table (bit, encoded, decoded):
33
+ row false, "0", Just false
34
+ row true, "1", Just true
35
+ end
36
+ end
37
+
38
+ law "|decoding is a left inverse| is
39
+ definition:
40
+ apply law "|left inverse| "|decode with zero default| bitText
41
+ end
42
+
43
+ description:
44
+ "Decoding an encoded bit recovers it. The inverse is the first argument."
45
+ end
46
+ end
47
+
48
+ law "|other text has no bit| is
49
+ definition:
50
+ decodeBit "01" must be Nothing
51
+ end
52
+
53
+ description:
54
+ "Two characters are not one encoded bit. Invalid input has no decoded value."
55
+ end
56
+ end
@@ -0,0 +1,144 @@
1
+ unit example.rc1.boundedWitnessSearch
2
+
3
+ type RequestLabel is a record{
4
+ text of type Text
5
+ }
6
+ end type
7
+
8
+ function keepValue (value of type a) -> a is
9
+ value
10
+ end function
11
+
12
+ function reply (allowed of type Bool) -> Integer is
13
+ if allowed then 1 else 2 end if
14
+ end function
15
+
16
+ function labelFor (allowed of type Bool) -> RequestLabel is
17
+ RequestLabel record{
18
+ text = if allowed then "approved" else "declined" end if
19
+ }
20
+ end function
21
+
22
+ law "|each request can receive its matching reply| is
23
+ description:
24
+ "Allowed requests receive reply one; other requests receive reply two."
25
+ end
26
+ definition:
27
+ for all (allowed of type Bool) =>
28
+ there exists (answer of type Integer) such that
29
+ answer must be reply allowed
30
+ end
31
+ end
32
+ end
33
+ expect reply allowed = expected
34
+ in table (allowed, expected):
35
+ row true, 1
36
+ row false, 2
37
+ end
38
+ end
39
+
40
+ law "|each request can receive its matching label| is
41
+ definition:
42
+ for all (allowed of type Bool) =>
43
+ there exists (label of type RequestLabel) such that
44
+ label.text must be (if allowed then "approved" else "declined" end if)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ law "|an adjusted amount can exceed any exact amount| is
51
+ definition:
52
+ for all (amount of type Integer) =>
53
+ there exists (adjusted of type Integer where adjusted > amount) such that
54
+ adjusted > amount
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ law "|a small amount cannot be both positive and nonpositive| is
61
+ definition:
62
+ there must not exist (amount of type Integer where
63
+ amount >= 0 and amount <= 3) such that
64
+ amount > 0 and amount <= 0
65
+ end
66
+ end
67
+ end
68
+
69
+ law "|independent requirements can choose distinct amounts| is
70
+ definition:
71
+ (there exists (amount of type Integer) such that amount = 1 end)
72
+ and
73
+ (there exists (amount of type Integer) such that amount = 2 end)
74
+ end
75
+ end
76
+
77
+ law "|a dependent strategy can propose the adjusted count| is
78
+ definition:
79
+ there exists (count of type Integer) such that
80
+ count must be 4
81
+ end
82
+ end
83
+ end
84
+
85
+ law "|an exceptional request can receive a manual category| is
86
+ definition:
87
+ there exists (category of type Text) such that
88
+ category must be "manual"
89
+ end
90
+ end
91
+ end
92
+
93
+ law "|consecutive exact cents have no intermediate amount| is
94
+ definition:
95
+ for all (amount of type Integer)
96
+ (between of type Integer where between > amount and between < amount + 1)
97
+ =>
98
+ false
99
+ end
100
+ end
101
+ end
102
+
103
+ law "|exact amounts are not all zero| is
104
+ definition:
105
+ must not for all (amount of type Integer) =>
106
+ amount = 0
107
+ end
108
+ end
109
+ end
110
+
111
+ harness example.rc1.boundedWitnessSearch.testing for example.rc1.boundedWitnessSearch is
112
+ strategy replies of type Integer is one of 1, 2 end
113
+ strategy labels of type RequestLabel is
114
+ one of keepValue (labelFor true), keepValue (labelFor false)
115
+ end
116
+ strategy firstAmount of type Integer is one of 1 end
117
+ strategy secondAmount of type Integer is one of 2 end
118
+ strategy bases of type Integer is one of 0, 3 end
119
+ strategy counts of type Integer is
120
+ (bind base of type Integer from bases in one of base + 1)
121
+ such that it > 0
122
+ end
123
+ strategy ordinaryCategory of type Text is one of "automatic" end
124
+ strategy manualCategory of type Text is one of "manual" end
125
+ strategy categories of type Text is
126
+ frequency 3 ordinaryCategory, 1 manualCategory
127
+ end
128
+ strategy nonzeroAmount of type Integer is one of 1 end
129
+
130
+ for law "|each request can receive its matching reply|
131
+ witness 0 for allowed.answer
132
+ use replies for definition.allowed.answer
133
+ for law "|each request can receive its matching label|
134
+ use labels for allowed.label
135
+ for law "|independent requirements can choose distinct amounts|
136
+ use firstAmount for branch1.amount
137
+ use secondAmount for definition.branch2.amount
138
+ for law "|a dependent strategy can propose the adjusted count|
139
+ use counts for count
140
+ for law "|an exceptional request can receive a manual category|
141
+ use categories for category
142
+ for law "|exact amounts are not all zero|
143
+ use nonzeroAmount for amount
144
+ end
@@ -0,0 +1,30 @@
1
+ unit example.conflictingRefunds
2
+
3
+ type RefundDecision is one of
4
+ | Approved
5
+ | ReviewRequired
6
+ end type
7
+
8
+ function proposedDecision (flagged of type Bool) -> RefundDecision is
9
+ if flagged then ReviewRequired else Approved end if
10
+ end function
11
+
12
+ law "|every request is approved| is
13
+ description:
14
+ "The first requirement demands approval even when a request is flagged."
15
+ end
16
+ definition:
17
+ for all (flagged of type Bool) =>
18
+ proposedDecision flagged must be Approved
19
+ end
20
+ end
21
+ end
22
+
23
+ law "|a flagged request requires review| is
24
+ description:
25
+ "The second requirement demands a different result for the same request."
26
+ end
27
+ definition:
28
+ proposedDecision true must be ReviewRequired
29
+ end
30
+ end
@@ -0,0 +1,113 @@
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
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
37
+ end
38
+ end
39
+ expect increment value = expected
40
+ in table (value, expected):
41
+ row -1, 0
42
+ row 0, 1
43
+ row 1, 2
44
+ end
45
+ end
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
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
56
+ end
57
+ end
58
+ end
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
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ law "|separate requirements can choose separate values| is
73
+ definition:
74
+ (there exists (value of type Integer) such that value = 1 end)
75
+ and
76
+ (there exists (value of type Integer) such that value = 2 end)
77
+ end
78
+ end
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
85
+ end
86
+ end
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
94
+ end
95
+ end
96
+ end
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
+ for law "|each request has a matching label|
102
+ witness keep (labelFor allowed) for allowed.label
103
+ for law "|positive amounts have a description|
104
+ witness (if allowed then 1 else 2 end if) for allowed.amount
105
+ witness keep (amountDescription amount) for allowed.amount.word
106
+ for law "|separate requirements can choose separate values|
107
+ witness 1 for branch1.value
108
+ witness 2 for branch2.value
109
+ for law "|a request cannot be both allowed and disallowed|
110
+ witness false for allowed
111
+ for law "|an empty request domain needs no witness|
112
+ witness 0 for allowed.answer
113
+ end
@@ -0,0 +1,42 @@
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
18
+ definition:
19
+ review true must be Approved
20
+ end
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
27
+ end
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
35
+ definition:
36
+ review false must be Declined
37
+ end
38
+ references:
39
+ ref law "|allowed requests are approved| definition
40
+ "|Review policy|: "Allowed requests are approved; all other requests are declined."
41
+ end
42
+ end
@@ -0,0 +1,46 @@
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
13
+ end
14
+ description:
15
+ "No approval can be constructed in this domain. Universal verification evaluates zero cases."
16
+ end
17
+ end
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
25
+ end
26
+ end
27
+ description:
28
+ "The restriction excludes every input. This establishes no witness for any actual input."
29
+ end
30
+ end
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
37
+ end
38
+ end
39
+
40
+ law "|excluded payments incur no obligation| is
41
+ definition:
42
+ for all (eligible of type Bool where false) =>
43
+ false
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,75 @@
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
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
17
+ end
18
+ end
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
26
+ end
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
33
+ end
34
+ end
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
41
+ end
42
+ end
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
50
+ end
51
+ end
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
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
63
+ end
64
+ end
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
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,29 @@
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
18
+ definition:
19
+ review true must be Approved
20
+ end
21
+ end
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
29
+ end
@@ -0,0 +1,107 @@
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
39
+ end
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
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
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
61
+ end
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
68
+ end
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
76
+
77
+ example "|declined payment|:
78
+ payment = Declined "card declined"
79
+ expect roundTrip payment = Declined "card declined"
80
+ end
81
+ end
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
88
+ end
89
+
90
+ example "|empty archive|:
91
+ payments = []
92
+ expect archive payments = []
93
+ end
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
107
+ end
@@ -0,0 +1,33 @@
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
29
+ definition:
30
+ "|email invoice PDF file name| (emailPdfInvoice "invoice.pdf") must be Just
31
+ "invoice.pdf"
32
+ end
33
+ end