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.
- package/CHANGELOG.md +167 -1
- package/README.md +29 -22
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +14 -23
- package/bin/lawspec.mjs +200 -67
- package/build.json +381 -155
- package/builtin-data-names.mjs +73 -0
- package/compatibility.json +21 -0
- package/core.wasm +2 -2
- package/doctor.mjs +98 -1
- package/examples/native-payments/clojure/lawspec.json +62 -0
- package/examples/native-payments/clojure/src/domain/payments.clj +11 -0
- package/examples/native-payments/clojure/test/domain/payment_generators.clj +9 -0
- 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 +176 -0
- package/examples/native-payments/groovy/src/main/groovy/domain/PaymentsDomain.groovy +49 -0
- package/examples/native-payments/groovy/src/test/groovy/domain/PaymentGenerators.groovy +15 -0
- 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 +176 -0
- package/examples/native-payments/scala/src/main/scala/domain/PaymentsDomain.scala +18 -0
- package/examples/native-payments/scala/src/test/scala/domain/PaymentGenerators.scala +8 -0
- package/examples/native-payments/swift/lawspec.json +165 -0
- package/examples/native-payments/swift/src/Native/PaymentsDomain.swift +35 -0
- package/examples/native-payments/swift/tests/Native/PaymentGenerators.swift +12 -0
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +36 -34
- package/examples/packages/shop-domain/src/domain.lawspec +23 -21
- package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
- package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
- package/examples/rc1/authorization-snapshots.lawspec +112 -0
- package/examples/rc1/banner-filenames.lawspec +63 -0
- package/examples/rc1/bit-codec.lawspec +56 -0
- package/examples/rc1/bounded-witness-search.lawspec +144 -0
- package/examples/rc1/conflicting-requirements.lawspec +30 -0
- package/examples/rc1/constructive-witnesses.lawspec +113 -0
- package/examples/rc1/documentary-review.lawspec +42 -0
- package/examples/rc1/empty-domains.lawspec +46 -0
- package/examples/rc1/finite-integer-domains.lawspec +75 -0
- package/examples/rc1/law-metadata.lawspec +29 -0
- package/examples/rc1/native-payments.lawspec +107 -0
- package/examples/rc1/nesting/rrr.lawspec +33 -0
- package/examples/rc1/nesting/rru.lawspec +56 -0
- package/examples/rc1/nesting/rur.lawspec +57 -0
- package/examples/rc1/nesting/ruu.lawspec +77 -0
- package/examples/rc1/nesting/urr.lawspec +52 -0
- package/examples/rc1/nesting/uru.lawspec +72 -0
- package/examples/rc1/nesting/uur.lawspec +73 -0
- package/examples/rc1/nesting/uuu.lawspec +95 -0
- package/examples/rc1/order-workflow.lawspec +126 -0
- package/examples/rc1/parcel-measurements.lawspec +92 -0
- package/examples/rc1/picture-records.lawspec +51 -0
- package/examples/rc1/picture-tuples.lawspec +47 -0
- package/examples/rc1/record-payloads.lawspec +56 -0
- package/examples/rc1/recursive-records.lawspec +64 -0
- package/examples/rc1/refund-conformance.lawspec +44 -0
- package/examples/rc1/refund-policy.lawspec +88 -0
- package/examples/rc1/requirement-composition.lawspec +89 -0
- package/examples/rc1/structural-records.lawspec +53 -0
- package/examples/rc1-authoring.lawspec +56 -0
- package/examples-command.mjs +11 -5
- package/explain.mjs +112 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +934 -12
- package/lsp.mjs +231 -0
- package/migrate.mjs +135 -0
- package/migration-bindings.mjs +86 -0
- package/migration-cases.mjs +45 -0
- package/migration-collections.mjs +54 -0
- package/migration-correspondence.mjs +275 -0
- package/migration-generation.mjs +99 -0
- package/migration-laws.mjs +102 -0
- package/migration-records.mjs +166 -0
- package/migration-source.mjs +247 -0
- package/migration-write.mjs +156 -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/scala-coverage.mjs +56 -0
- package/starter-rc1.lawspec +25 -0
- package/templates.mjs +65 -3
- package/test-command.mjs +177 -29
- package/typed-presentation.mjs +165 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"sources": [
|
|
4
|
+
"laws"
|
|
5
|
+
],
|
|
6
|
+
"machineBits": 64,
|
|
7
|
+
"targets": [
|
|
8
|
+
{
|
|
9
|
+
"language": "swift",
|
|
10
|
+
"root": ".",
|
|
11
|
+
"nativeBindings": {
|
|
12
|
+
"types": [
|
|
13
|
+
{
|
|
14
|
+
"type": "example.payments::type::Currency",
|
|
15
|
+
"native": [
|
|
16
|
+
"PaymentsDomain",
|
|
17
|
+
"CurrencyCode"
|
|
18
|
+
],
|
|
19
|
+
"constructors": [
|
|
20
|
+
{
|
|
21
|
+
"constructor": "USD",
|
|
22
|
+
"native": [
|
|
23
|
+
"PaymentsDomain",
|
|
24
|
+
"CurrencyCode",
|
|
25
|
+
"dollars"
|
|
26
|
+
],
|
|
27
|
+
"style": "unit",
|
|
28
|
+
"fields": []
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"constructor": "EUR",
|
|
32
|
+
"native": [
|
|
33
|
+
"PaymentsDomain",
|
|
34
|
+
"CurrencyCode",
|
|
35
|
+
"euros"
|
|
36
|
+
],
|
|
37
|
+
"style": "unit",
|
|
38
|
+
"fields": []
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"constructor": "GBP",
|
|
42
|
+
"native": [
|
|
43
|
+
"PaymentsDomain",
|
|
44
|
+
"CurrencyCode",
|
|
45
|
+
"pounds"
|
|
46
|
+
],
|
|
47
|
+
"style": "unit",
|
|
48
|
+
"fields": []
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"type": "example.payments::type::Money",
|
|
54
|
+
"native": [
|
|
55
|
+
"PaymentsDomain",
|
|
56
|
+
"Price"
|
|
57
|
+
],
|
|
58
|
+
"constructors": [
|
|
59
|
+
{
|
|
60
|
+
"constructor": "Money",
|
|
61
|
+
"native": [
|
|
62
|
+
"PaymentsDomain",
|
|
63
|
+
"Price"
|
|
64
|
+
],
|
|
65
|
+
"style": "record",
|
|
66
|
+
"fields": [
|
|
67
|
+
{
|
|
68
|
+
"field": "amount",
|
|
69
|
+
"native": "major"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"field": "currency",
|
|
73
|
+
"native": "unit"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"type": "example.payments::type::Payment",
|
|
81
|
+
"native": [
|
|
82
|
+
"PaymentsDomain",
|
|
83
|
+
"PaymentStatus"
|
|
84
|
+
],
|
|
85
|
+
"constructors": [
|
|
86
|
+
{
|
|
87
|
+
"constructor": "Paid",
|
|
88
|
+
"native": [
|
|
89
|
+
"PaymentsDomain",
|
|
90
|
+
"PaymentStatus",
|
|
91
|
+
"settled"
|
|
92
|
+
],
|
|
93
|
+
"style": "variant",
|
|
94
|
+
"fields": [
|
|
95
|
+
{
|
|
96
|
+
"field": "value",
|
|
97
|
+
"native": "price"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"constructor": "Declined",
|
|
103
|
+
"native": [
|
|
104
|
+
"PaymentsDomain",
|
|
105
|
+
"PaymentStatus",
|
|
106
|
+
"rejected"
|
|
107
|
+
],
|
|
108
|
+
"style": "variant",
|
|
109
|
+
"fields": [
|
|
110
|
+
{
|
|
111
|
+
"field": "value",
|
|
112
|
+
"native": "explanation"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
"functions": [
|
|
120
|
+
{
|
|
121
|
+
"declaration": "example.payments::addFee",
|
|
122
|
+
"native": [
|
|
123
|
+
"PaymentsDomain",
|
|
124
|
+
"applyFee"
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"declaration": "example.payments::roundTrip",
|
|
129
|
+
"native": [
|
|
130
|
+
"PaymentsDomain",
|
|
131
|
+
"restore"
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"declaration": "example.payments::archive",
|
|
136
|
+
"native": [
|
|
137
|
+
"PaymentsDomain",
|
|
138
|
+
"store"
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"generators": [
|
|
143
|
+
{
|
|
144
|
+
"type": "example.payments::type::Money",
|
|
145
|
+
"factory": [
|
|
146
|
+
"PaymentGenerators",
|
|
147
|
+
"prices"
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
"languageProfile": "1.0-rc.1",
|
|
155
|
+
"verification": {
|
|
156
|
+
"layers": [
|
|
157
|
+
"proof",
|
|
158
|
+
"exhaustive",
|
|
159
|
+
"property",
|
|
160
|
+
"examples",
|
|
161
|
+
"runtime",
|
|
162
|
+
"model"
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Application types, independent of generated LawSpec domain declarations.
|
|
2
|
+
import LawSpecRuntime
|
|
3
|
+
|
|
4
|
+
public enum PaymentsDomain {
|
|
5
|
+
public enum CurrencyCode: Sendable {
|
|
6
|
+
case dollars
|
|
7
|
+
case euros
|
|
8
|
+
case pounds
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public struct Price: Sendable {
|
|
12
|
+
public var major: ExactDecimal
|
|
13
|
+
public var unit: CurrencyCode
|
|
14
|
+
|
|
15
|
+
public init(major: ExactDecimal, unit: CurrencyCode) {
|
|
16
|
+
self.major = major
|
|
17
|
+
self.unit = unit
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public enum PaymentStatus: Sendable {
|
|
22
|
+
case settled(price: Price)
|
|
23
|
+
case rejected(explanation: String)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private static let fee = ExactDecimal(coefficient: 2, exponent: -1)
|
|
27
|
+
|
|
28
|
+
public static func applyFee(_ price: Price) -> Price {
|
|
29
|
+
Price(major: price.major + fee, unit: price.unit)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static func restore(_ payment: PaymentStatus) -> PaymentStatus { payment }
|
|
33
|
+
|
|
34
|
+
public static func store(_ payments: PersistentList<PaymentStatus?>) -> PersistentList<PaymentStatus?> { payments }
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Prices the application considers representative: 1.00 to 2.00 euros.
|
|
2
|
+
import App
|
|
3
|
+
import LawSpecRuntime
|
|
4
|
+
import LawSpecTesting
|
|
5
|
+
|
|
6
|
+
enum PaymentGenerators {
|
|
7
|
+
static func prices() -> Gen<PaymentsDomain.Price> {
|
|
8
|
+
Gens.range(100, 200).map { cents in
|
|
9
|
+
PaymentsDomain.Price(major: ExactDecimal(coefficient: BigInt(cents), exponent: -2), unit: .euros)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version":
|
|
2
|
+
"version": 2,
|
|
3
3
|
"sources": [
|
|
4
4
|
"laws"
|
|
5
5
|
],
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"style": "variant",
|
|
104
104
|
"fields": [
|
|
105
105
|
{
|
|
106
|
-
"field": "
|
|
106
|
+
"field": "value",
|
|
107
107
|
"native": "explanation"
|
|
108
108
|
}
|
|
109
109
|
]
|
|
@@ -145,5 +145,16 @@
|
|
|
145
145
|
]
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
]
|
|
148
|
+
],
|
|
149
|
+
"languageProfile": "1.0-rc.1",
|
|
150
|
+
"verification": {
|
|
151
|
+
"layers": [
|
|
152
|
+
"proof",
|
|
153
|
+
"exhaustive",
|
|
154
|
+
"property",
|
|
155
|
+
"examples",
|
|
156
|
+
"runtime",
|
|
157
|
+
"model"
|
|
158
|
+
]
|
|
159
|
+
}
|
|
149
160
|
}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version":
|
|
3
|
-
"sources": [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
2
|
+
"version": 2,
|
|
3
|
+
"sources": [
|
|
4
|
+
"orders.lawspec"
|
|
5
|
+
],
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"shop.domain": "^1.0.0",
|
|
8
|
+
"shop.tax": "^2.0.0"
|
|
9
|
+
},
|
|
10
|
+
"packages": [
|
|
11
|
+
"../shop-domain",
|
|
12
|
+
"../shop-tax-1",
|
|
13
|
+
"../shop-tax-2"
|
|
14
|
+
],
|
|
15
|
+
"targets": [],
|
|
16
|
+
"languageProfile": "1.0-rc.1",
|
|
17
|
+
"verification": {
|
|
18
|
+
"layers": [
|
|
19
|
+
"proof",
|
|
20
|
+
"exhaustive",
|
|
21
|
+
"property",
|
|
22
|
+
"examples",
|
|
23
|
+
"runtime",
|
|
24
|
+
"model"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
7
27
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
unit shop.orders
|
|
2
|
-
import shop.domain as domain (Money, Cents,
|
|
2
|
+
import shop.domain as domain (Money, Cents, law "|commutative|, law
|
|
3
|
+
"|idempotent|)
|
|
3
4
|
-- shop.domain uses version 1 of shop.tax; this project's range selects
|
|
4
5
|
-- version 2. Both are in the build, and their Bands are different types.
|
|
5
6
|
import shop.tax.api as tax (Band)
|
|
6
7
|
|
|
7
8
|
-- Constructor names are scoped to their unit: this Usd is not domain.Usd.
|
|
8
|
-
type Currency is | Usd | Gbp end
|
|
9
|
+
type Currency is one of | Usd | Gbp end type
|
|
9
10
|
|
|
10
|
-
type Line is
|
|
11
|
+
type Line is a record{ price :: Money quantity :: domain.Quantity} end type
|
|
11
12
|
|
|
12
13
|
settlement :: Currency -> domain.Currency
|
|
13
14
|
lineTotal :: Line -> Money
|
|
@@ -17,66 +18,67 @@ cheaper :: Int64 -> Int64 -> Int64
|
|
|
17
18
|
roundDown :: Int64 -> Int64
|
|
18
19
|
classify :: Int64 -> Band
|
|
19
20
|
|
|
20
|
-
law
|
|
21
|
-
definition
|
|
21
|
+
law "|dollars settle in dollars| is
|
|
22
|
+
definition :
|
|
22
23
|
settlement Usd = domain.Usd
|
|
23
24
|
end
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
law
|
|
27
|
-
definition
|
|
27
|
+
law "|pounds settle in euros| is
|
|
28
|
+
definition :
|
|
28
29
|
settlement Gbp = domain.Eur
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
law
|
|
33
|
-
definition
|
|
34
|
-
|
|
35
|
-
domain.currencyOf (lineTotal l) = (
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
law "|a line total keeps the price currency| is
|
|
34
|
+
definition :
|
|
35
|
+
for all (l :: Line) =>
|
|
36
|
+
domain.currencyOf (lineTotal l) = (first matching case of l :
|
|
37
|
+
when Line record{ price = p , quantity = q} then domain.currencyOf p
|
|
38
|
+
end case) end
|
|
38
39
|
end
|
|
39
|
-
example
|
|
40
|
-
l = Line (Money domain.Usd
|
|
40
|
+
example "|two items| :
|
|
41
|
+
l = Line record{ price = (Money record{ currency = domain.Usd , cents =
|
|
42
|
+
250}) , quantity = (domain.Quantity 2)}
|
|
41
43
|
expect domain.centsOf (lineTotal l) = 500
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
law
|
|
46
|
-
definition
|
|
47
|
-
|
|
47
|
+
law "|the cheaper price does not depend on order| is
|
|
48
|
+
definition :
|
|
49
|
+
apply law "|commutative| cheaper
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
law
|
|
52
|
-
definition
|
|
53
|
-
|
|
53
|
+
law "|rounding down to whole dollars is stable| is
|
|
54
|
+
definition :
|
|
55
|
+
apply law "|idempotent| roundDown
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
law
|
|
58
|
-
definition
|
|
59
|
-
|
|
59
|
+
law "|rounding down never raises a price| is
|
|
60
|
+
definition :
|
|
61
|
+
for all (c :: Cents) => roundDown c <= c end
|
|
60
62
|
end
|
|
61
63
|
end
|
|
62
64
|
|
|
63
|
-
law
|
|
64
|
-
definition
|
|
65
|
-
|
|
65
|
+
law "|prices are classified into version 2 bands| is
|
|
66
|
+
definition :
|
|
67
|
+
for all (c :: Cents) => tax.rateOf (classify c) <= 25 end
|
|
66
68
|
end
|
|
67
|
-
example
|
|
68
|
-
example
|
|
69
|
-
example
|
|
69
|
+
example "|nothing| : c = 0 expect classify c = Zero end
|
|
70
|
+
example "|small| : c = 9999 expect classify c = Low end
|
|
71
|
+
example "|large| : c = 10000 expect classify c = High end
|
|
70
72
|
end
|
|
71
73
|
|
|
72
|
-
law
|
|
73
|
-
definition
|
|
74
|
+
law "|shop.domain keeps version 1 of the bands| is
|
|
75
|
+
definition :
|
|
74
76
|
domain.dutyOf domain.High = 20
|
|
75
77
|
end
|
|
76
78
|
end
|
|
77
79
|
|
|
78
|
-
law
|
|
79
|
-
definition
|
|
80
|
+
law "|this project sees version 2 of the bands| is
|
|
81
|
+
definition :
|
|
80
82
|
tax.rateOf High = 25
|
|
81
83
|
end
|
|
82
84
|
end
|
|
@@ -8,35 +8,37 @@ export Band
|
|
|
8
8
|
-- A package of reusable types, refinements, definitions and laws. Other units
|
|
9
9
|
-- import it by name; its declarations keep their own names, so an importer may
|
|
10
10
|
-- declare a Currency or a Usd of its own.
|
|
11
|
-
type Currency is | Usd | Eur end
|
|
11
|
+
type Currency is one of | Usd | Eur end type
|
|
12
12
|
|
|
13
13
|
refinement Cents is (c :: Int64 where c >= 0 && c <= 100000000) end
|
|
14
14
|
|
|
15
|
-
type Money is
|
|
15
|
+
type Money is a record{ currency :: Currency cents :: Cents} end type
|
|
16
16
|
|
|
17
17
|
wrapper Quantity is Int32 where value >= 1 && value <= 1000 end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
19
|
+
function currencyOf (m :: Money) -> Currency is
|
|
20
|
+
first matching case of m : when Money record{ currency = c , cents = n} then c
|
|
21
|
+
end case
|
|
22
|
+
end function
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
end
|
|
24
|
+
function centsOf (m :: Money) -> Int64 is
|
|
25
|
+
first matching case of m : when Money record{ currency = c , cents = n} then n
|
|
26
|
+
end case
|
|
27
|
+
end function
|
|
26
28
|
|
|
27
29
|
-- The duty on a band, at version 1's rates.
|
|
28
|
-
|
|
30
|
+
function dutyOf (b :: Band) -> Int64 is tax.rateOf b end function
|
|
29
31
|
|
|
30
32
|
-- Generic laws are templates: an importer applies them to its own adapters.
|
|
31
|
-
law
|
|
32
|
-
definition
|
|
33
|
-
|
|
33
|
+
law "|commutative| (f :: a -> a -> a) requires Eq a is
|
|
34
|
+
definition :
|
|
35
|
+
for all (x :: a) (y :: a) => f x y = f y x end
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
|
|
37
|
-
law
|
|
38
|
-
definition
|
|
39
|
-
|
|
39
|
+
law "|idempotent| (f :: a -> a) requires Eq a is
|
|
40
|
+
definition :
|
|
41
|
+
for all (x :: a) => f (f x) = f x end
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
@@ -44,14 +46,14 @@ end
|
|
|
44
46
|
-- convert and is tested against these laws.
|
|
45
47
|
convert :: Currency -> Money -> Money
|
|
46
48
|
|
|
47
|
-
law
|
|
48
|
-
definition
|
|
49
|
-
|
|
49
|
+
law "|conversion targets the requested currency| is
|
|
50
|
+
definition :
|
|
51
|
+
for all (c :: Currency) (m :: Money) => currencyOf (convert c m) = c end
|
|
50
52
|
end
|
|
51
53
|
end
|
|
52
54
|
|
|
53
|
-
law
|
|
54
|
-
definition
|
|
55
|
-
|
|
55
|
+
law "|converting to the same currency changes nothing| is
|
|
56
|
+
definition :
|
|
57
|
+
for all (m :: Money) => convert (currencyOf m) m = m end
|
|
56
58
|
end
|
|
57
59
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
unit shop.tax.rates
|
|
2
2
|
|
|
3
3
|
-- Version 1 of the tax bands.
|
|
4
|
-
type Band is | Low | High end
|
|
4
|
+
type Band is one of | Low | High end type
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
6
|
+
function rateOf (b :: Band) -> Int64 is
|
|
7
|
+
first matching case of b : when Low then 5 when High then 20 end case
|
|
8
|
+
end function
|
|
@@ -2,8 +2,9 @@ unit shop.tax.rates
|
|
|
2
2
|
|
|
3
3
|
-- Version 2 adds a zero band and changes the rates. A build may hold both
|
|
4
4
|
-- versions: each dependent sees the one its version range selects.
|
|
5
|
-
type Band is | Zero | Low | High end
|
|
5
|
+
type Band is one of | Zero | Low | High end type
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
end
|
|
7
|
+
function rateOf (b :: Band) -> Int64 is
|
|
8
|
+
first matching case of b : when Zero then 0 when Low then 10 when High then 25
|
|
9
|
+
end case
|
|
10
|
+
end function
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
unit example.rc1.authorizationSnapshots
|
|
2
|
+
|
|
3
|
+
type Payment is one of
|
|
4
|
+
| FirstPayment
|
|
5
|
+
| SecondPayment
|
|
6
|
+
end type
|
|
7
|
+
|
|
8
|
+
type Authorization is one of
|
|
9
|
+
| FirstApproval
|
|
10
|
+
| SecondApproval
|
|
11
|
+
end type
|
|
12
|
+
|
|
13
|
+
type AuthorizationState is one of
|
|
14
|
+
| Ready
|
|
15
|
+
| FirstRevoked
|
|
16
|
+
| AllRevoked
|
|
17
|
+
end type
|
|
18
|
+
|
|
19
|
+
function active (state of type AuthorizationState)
|
|
20
|
+
(authorization of type Authorization) -> Bool is
|
|
21
|
+
first matching case of state:
|
|
22
|
+
when Ready then true
|
|
23
|
+
when FirstRevoked then authorization = SecondApproval
|
|
24
|
+
when AllRevoked then false
|
|
25
|
+
end case
|
|
26
|
+
end function
|
|
27
|
+
|
|
28
|
+
function authorizes (authorization of type Authorization)
|
|
29
|
+
(payment of type Payment) -> Bool is
|
|
30
|
+
first matching case of authorization:
|
|
31
|
+
when FirstApproval then payment = FirstPayment
|
|
32
|
+
when SecondApproval then payment = SecondPayment
|
|
33
|
+
end case
|
|
34
|
+
end function
|
|
35
|
+
|
|
36
|
+
law "|ready payments have authorization| is
|
|
37
|
+
definition:
|
|
38
|
+
for all (payment of type Payment) =>
|
|
39
|
+
there must exist an (authorization of type Authorization
|
|
40
|
+
where active Ready the authorization) such that
|
|
41
|
+
authorization `authorizes payment
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
description:
|
|
47
|
+
"The Ready snapshot contains an active approval for each payment."
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
law "|the revoked first approval is absent| is
|
|
52
|
+
definition:
|
|
53
|
+
there does not exist (authorization of type Authorization
|
|
54
|
+
where active FirstRevoked the authorization) such that
|
|
55
|
+
authorization `authorizes FirstPayment
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
description:
|
|
60
|
+
"The FirstRevoked snapshot has no active approval for the first payment."
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
law "|all revoked approvals are absent| is
|
|
65
|
+
definition:
|
|
66
|
+
for all (payment of type Payment) =>
|
|
67
|
+
there must not exist (authorization of type Authorization
|
|
68
|
+
where active AllRevoked the authorization) such that
|
|
69
|
+
authorization `authorizes payment
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
law "|one approval cannot cover every payment| is
|
|
76
|
+
definition:
|
|
77
|
+
must not there exists (authorization of type Authorization) such that
|
|
78
|
+
for all (payment of type Payment) =>
|
|
79
|
+
authorization `authorizes payment
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
rationale:
|
|
85
|
+
"Each approval belongs to one payment. Quantifier order changes the claim."
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
law "|activation matches the complete snapshot| is
|
|
90
|
+
definition:
|
|
91
|
+
for all (state of type AuthorizationState)
|
|
92
|
+
(authorization of type Authorization) =>
|
|
93
|
+
active state authorization must be
|
|
94
|
+
(state = Ready or
|
|
95
|
+
(state = FirstRevoked and authorization = SecondApproval))
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
expect active state authorization = expected
|
|
100
|
+
in table (state, authorization, expected):
|
|
101
|
+
row Ready, FirstApproval, true
|
|
102
|
+
row Ready, SecondApproval, true
|
|
103
|
+
row FirstRevoked, FirstApproval, false
|
|
104
|
+
row FirstRevoked, SecondApproval, true
|
|
105
|
+
row AllRevoked, FirstApproval, false
|
|
106
|
+
row AllRevoked, SecondApproval, false
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
description:
|
|
110
|
+
"The search domain is exactly two approval identities in one snapshot."
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
unit pictures.banners
|
|
2
|
+
|
|
3
|
+
type Picture is a record{
|
|
4
|
+
fileName of type Text
|
|
5
|
+
dimensions of type record{
|
|
6
|
+
width of type Nat
|
|
7
|
+
height of type Nat
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
end type
|
|
11
|
+
|
|
12
|
+
type BannerDecision is one of
|
|
13
|
+
| Rejected of type Text
|
|
14
|
+
| Eligible
|
|
15
|
+
| TooSmall
|
|
16
|
+
end type
|
|
17
|
+
|
|
18
|
+
function containsProfanity (input of type Text) -> Bool is
|
|
19
|
+
let folded = prelude.caseFold input in
|
|
20
|
+
prelude.any (prelude.textContains folded) ["shit", "piss", "fuck"]
|
|
21
|
+
end function
|
|
22
|
+
|
|
23
|
+
function bannerDecision (picture of type Picture) -> BannerDecision is
|
|
24
|
+
first matching case of picture.fileName:
|
|
25
|
+
when containsProfanity it then Rejected it
|
|
26
|
+
otherwise
|
|
27
|
+
if picture.dimensions.width >= 1200 and picture.dimensions.height >= 300
|
|
28
|
+
then
|
|
29
|
+
Eligible
|
|
30
|
+
else
|
|
31
|
+
TooSmall
|
|
32
|
+
end if
|
|
33
|
+
end case
|
|
34
|
+
end function
|
|
35
|
+
|
|
36
|
+
law "|prohibited filenames are rejected before checking dimensions| is
|
|
37
|
+
description:
|
|
38
|
+
"A prohibited fragment rejects the filename at every size. Clean banners need at least 1200 pixels of width and 300 pixels of height."
|
|
39
|
+
end
|
|
40
|
+
definition:
|
|
41
|
+
for all (picture of type Picture) =>
|
|
42
|
+
containsProfanity picture.fileName implies
|
|
43
|
+
bannerDecision picture must be Rejected picture.fileName
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
expect bannerDecision picture = expected
|
|
47
|
+
in table (picture, expected):
|
|
48
|
+
row Picture record{fileName = "banner.png", dimensions = record{width =
|
|
49
|
+
1200, height = 300}}, Eligible
|
|
50
|
+
row Picture record{fileName = "portrait.png", dimensions = record{width =
|
|
51
|
+
100, height = 100}}, TooSmall
|
|
52
|
+
row Picture record{fileName = "SHIT.png", dimensions = record{width = 1200,
|
|
53
|
+
height = 300}}, Rejected "SHIT.png"
|
|
54
|
+
row Picture record{fileName = "xxpIssxx.jpg", dimensions = record{width = 1,
|
|
55
|
+
height = 1}}, Rejected "xxpIssxx.jpg"
|
|
56
|
+
row Picture record{fileName = "PIẞ.png", dimensions = record{width = 1,
|
|
57
|
+
height = 1}}, Rejected "PIẞ.png"
|
|
58
|
+
row Picture record{fileName = "ſhit.png", dimensions = record{width = 1,
|
|
59
|
+
height = 1}}, Rejected "ſhit.png"
|
|
60
|
+
row Picture record{fileName = "fucK.png", dimensions = record{width = 1,
|
|
61
|
+
height = 1}}, Rejected "fucK.png"
|
|
62
|
+
end
|
|
63
|
+
end
|