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,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": 1,
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": "reason",
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": 1,
3
- "sources": ["orders.lawspec"],
4
- "dependencies": { "shop.domain": "^1.0.0", "shop.tax": "^2.0.0" },
5
- "packages": ["../shop-domain", "../shop-tax-1", "../shop-tax-2"],
6
- "targets": []
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, `commutative`, `idempotent`)
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 Line price :: Money quantity :: domain.Quantity end
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 `dollars settle in dollars` is
21
- definition is
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 `pounds settle in euros` is
27
- definition is
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 `a line total keeps the price currency` is
33
- definition is
34
- `for all` (l :: Line) .
35
- domain.currencyOf (lineTotal l) = (match l with
36
- | Line p q -> domain.currencyOf p
37
- end)
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 `two items` is
40
- l = Line (Money domain.Usd 250) (domain.Quantity 2)
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 `the cheaper price does not depend on order` is
46
- definition is
47
- `commutative` cheaper
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 `rounding down to whole dollars is stable` is
52
- definition is
53
- `idempotent` roundDown
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 `rounding down never raises a price` is
58
- definition is
59
- `for all` (c :: Cents) . roundDown c <= c
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 `prices are classified into version 2 bands` is
64
- definition is
65
- `for all` (c :: Cents) . tax.rateOf (classify c) <= 25
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 `nothing` is c = 0 expect classify c = Zero end
68
- example `small` is c = 9999 expect classify c = Low end
69
- example `large` is c = 10000 expect classify c = High end
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 `shop.domain keeps version 1 of the bands` is
73
- definition is
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 `this project sees version 2 of the bands` is
79
- definition is
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 Money currency :: Currency cents :: Cents end
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
- definition currencyOf (m :: Money) :: Currency is
20
- match m with | Money c n -> c end
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
- definition centsOf (m :: Money) :: Int64 is
24
- match m with | Money c n -> n end
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
- definition dutyOf (b :: Band) :: Int64 is tax.rateOf b end
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 `commutative` (f :: a -> a -> a) requires Eq a is
32
- definition is
33
- `for all` (x :: a) (y :: a) . f x y = f y x
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 `idempotent` (f :: a -> a) requires Eq a is
38
- definition is
39
- `for all` (x :: a) . f (f x) = f x
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 `conversion targets the requested currency` is
48
- definition is
49
- `for all` (c :: Currency) (m :: Money) . currencyOf (convert c m) = c
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 `converting to the same currency changes nothing` is
54
- definition is
55
- `for all` (m :: Money) . convert (currencyOf m) m = m
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
- definition rateOf (b :: Band) :: Int64 is
7
- match b with | Low -> 5 | High -> 20 end
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
- definition rateOf (b :: Band) :: Int64 is
8
- match b with | Zero -> 0 | Low -> 10 | High -> 25 end
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