lawspec 0.25.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 +43 -1
- package/README.md +5 -4
- package/api.mjs +0 -8
- package/bin/lawspec.mjs +14 -52
- package/build.json +77 -105
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/examples/native-payments/clojure/lawspec.json +1 -1
- package/examples/native-payments/csharp/lawspec.json +1 -1
- package/examples/native-payments/elixir/lawspec.json +1 -1
- package/examples/native-payments/erlang/lawspec.json +1 -1
- package/examples/native-payments/fsharp/lawspec.json +1 -1
- package/examples/native-payments/gleam/lawspec.json +1 -1
- package/examples/native-payments/go/lawspec.json +1 -1
- package/examples/native-payments/groovy/lawspec.json +1 -1
- package/examples/native-payments/haskell/lawspec.json +1 -1
- package/examples/native-payments/java/lawspec.json +1 -1
- package/examples/native-payments/javascript/lawspec.json +1 -1
- package/examples/native-payments/kotlin/lawspec.json +1 -1
- package/examples/native-payments/python/lawspec.json +1 -1
- package/examples/native-payments/rust/lawspec.json +1 -1
- package/examples/native-payments/scala/lawspec.json +1 -1
- package/examples/native-payments/swift/lawspec.json +1 -1
- package/examples/native-payments/typescript/lawspec.json +1 -1
- package/examples/packages/orders/lawspec.json +1 -1
- package/examples/packages/orders/orders.lawspec +27 -25
- package/examples/packages/shop-domain/src/domain.lawspec +15 -14
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
- package/examples/rc1/authorization-snapshots.lawspec +24 -23
- package/examples/rc1/banner-filenames.lawspec +7 -6
- package/examples/rc1/bit-codec.lawspec +12 -11
- package/examples/rc1/bounded-witness-search.lawspec +52 -45
- package/examples/rc1/conflicting-requirements.lawspec +8 -7
- package/examples/rc1/constructive-witnesses.lawspec +40 -33
- package/examples/rc1/documentary-review.lawspec +9 -8
- package/examples/rc1/empty-domains.lawspec +16 -15
- package/examples/rc1/finite-integer-domains.lawspec +24 -23
- package/examples/rc1/law-metadata.lawspec +6 -5
- package/examples/rc1/native-payments.lawspec +17 -16
- package/examples/rc1/nesting/rrr.lawspec +4 -3
- package/examples/rc1/nesting/rru.lawspec +7 -6
- package/examples/rc1/nesting/rur.lawspec +7 -6
- package/examples/rc1/nesting/ruu.lawspec +10 -9
- package/examples/rc1/nesting/urr.lawspec +7 -6
- package/examples/rc1/nesting/uru.lawspec +10 -9
- package/examples/rc1/nesting/uur.lawspec +10 -9
- package/examples/rc1/nesting/uuu.lawspec +13 -12
- package/examples/rc1/order-workflow.lawspec +18 -17
- package/examples/rc1/parcel-measurements.lawspec +14 -13
- package/examples/rc1/picture-records.lawspec +6 -5
- package/examples/rc1/picture-tuples.lawspec +6 -5
- package/examples/rc1/record-payloads.lawspec +12 -11
- package/examples/rc1/recursive-records.lawspec +11 -10
- package/examples/rc1/refund-conformance.lawspec +7 -6
- package/examples/rc1/refund-policy.lawspec +15 -14
- package/examples/rc1/requirement-composition.lawspec +26 -25
- package/examples/rc1/structural-records.lawspec +13 -12
- package/examples/rc1-authoring.lawspec +6 -5
- 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 +4 -6
- package/explain.mjs +6 -4
- package/expression-presentation.mjs +8 -8
- package/files.mjs +1 -1
- package/index.d.ts +4 -527
- package/launcher.mjs +9 -2
- package/lsp.mjs +10 -6
- package/native-examples.mjs +2 -2
- package/package.json +1 -1
- package/starter-rc1.lawspec +6 -5
- package/starter.lawspec +16 -15
- package/templates.mjs +4 -2
- package/migrate.mjs +0 -135
- package/migration-bindings.mjs +0 -86
- package/migration-cases.mjs +0 -45
- package/migration-collections.mjs +0 -54
- package/migration-correspondence.mjs +0 -275
- package/migration-generation.mjs +0 -99
- package/migration-laws.mjs +0 -102
- package/migration-records.mjs +0 -166
- package/migration-source.mjs +0 -247
- package/migration-write.mjs +0 -156
|
@@ -4,62 +4,64 @@ unit example.till
|
|
|
4
4
|
-- lawspec.json under handlers. Money is bound to a native type there too, so
|
|
5
5
|
-- the handler's operations take and give that type.
|
|
6
6
|
|
|
7
|
-
type Money is
|
|
8
|
-
type PayError is | Declined | Rejected message :: Text end
|
|
7
|
+
type Money is a record{ cents :: Int64} end type
|
|
8
|
+
type PayError is one of | Declined | Rejected of type record{ message :: Text} end type
|
|
9
9
|
|
|
10
10
|
-- A till's drawer. Every handler of it gives back what it takes.
|
|
11
11
|
ability Drawer is
|
|
12
12
|
take :: Money -> Money
|
|
13
13
|
opening :: Money
|
|
14
14
|
laws
|
|
15
|
-
law
|
|
16
|
-
definition
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
15
|
+
law "|a till gives back what it takes| is
|
|
16
|
+
definition :
|
|
17
|
+
for all (cents :: Int64 where cents >= 0 && cents <= 1000) => take (Money record{ cents = cents}) = Money record{ cents = cents} end for all
|
|
18
|
+
end definition
|
|
19
|
+
end law
|
|
20
|
+
end laws
|
|
21
|
+
end ability
|
|
21
22
|
|
|
22
23
|
handler fakeDrawer for Drawer is
|
|
23
|
-
take money is money end
|
|
24
|
-
opening is Money 0 end
|
|
25
|
-
end
|
|
24
|
+
operation take money is money end operation
|
|
25
|
+
operation opening is Money record{ cents = 0} end operation
|
|
26
|
+
end handler
|
|
26
27
|
|
|
27
28
|
-- A native adapter that fails. Its native code raises the application's own
|
|
28
29
|
-- exceptions; lawspec.json maps them to PayError's constructors.
|
|
29
30
|
pay :: Int64 -> Money uses Drawer fails with PayError
|
|
30
31
|
|
|
31
|
-
law
|
|
32
|
-
definition
|
|
33
|
-
|
|
34
|
-
prelude.attempt (pay cents) = Right (Money cents)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
32
|
+
law "|small payments go through| is
|
|
33
|
+
definition :
|
|
34
|
+
for all (cents :: Int64 where cents >= 0 && cents <= 1000) =>
|
|
35
|
+
prelude.attempt (pay cents) = Right (Money record{ cents = cents}) end for all
|
|
36
|
+
end definition
|
|
37
|
+
end law
|
|
37
38
|
|
|
38
|
-
law
|
|
39
|
-
definition
|
|
40
|
-
|
|
41
|
-
prelude.attempt (pay cents) = Left Declined
|
|
42
|
-
end
|
|
43
|
-
end
|
|
39
|
+
law "|large payments are declined| is
|
|
40
|
+
definition :
|
|
41
|
+
for all (cents :: Int64 where cents > 1000 && cents <= 100000) =>
|
|
42
|
+
prelude.attempt (pay cents) = Left Declined end for all
|
|
43
|
+
end definition
|
|
44
|
+
end law
|
|
44
45
|
|
|
45
|
-
law
|
|
46
|
-
definition
|
|
47
|
-
|
|
48
|
-
prelude.attempt (pay cents) = Left (Rejected "negative")
|
|
49
|
-
end
|
|
50
|
-
end
|
|
46
|
+
law "|negative payments are rejected| is
|
|
47
|
+
definition :
|
|
48
|
+
for all (cents :: Int64 where cents >= -1000 && cents < 0) =>
|
|
49
|
+
prelude.attempt (pay cents) = Left (Rejected record{ message = "negative"}) end for all
|
|
50
|
+
end definition
|
|
51
|
+
end law
|
|
51
52
|
|
|
52
53
|
-- The same failures, as a law expects them: `fails with` matches the
|
|
53
54
|
-- constructor a mapped exception became, and its message.
|
|
54
|
-
law
|
|
55
|
-
definition
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
end
|
|
55
|
+
law "|large payments fail as declined| is
|
|
56
|
+
definition :
|
|
57
|
+
for all (cents :: Int64 where cents > 1000 && cents <= 100000) => pay cents fails with Declined end for all
|
|
58
|
+
end definition
|
|
59
|
+
end law
|
|
59
60
|
|
|
60
|
-
law
|
|
61
|
-
definition
|
|
62
|
-
|
|
63
|
-
pay cents fails with Rejected _ message contains "negative"
|
|
64
|
-
end
|
|
65
|
-
end
|
|
61
|
+
law "|negative payments say why they are rejected| is
|
|
62
|
+
definition :
|
|
63
|
+
for all (cents :: Int64 where cents >= -1000 && cents < 0) =>
|
|
64
|
+
pay cents fails with Rejected record{ message = _} message contains "negative" end for all
|
|
65
|
+
end definition
|
|
66
|
+
end law
|
|
67
|
+
end unit
|
|
@@ -5,71 +5,73 @@ unit example.harness
|
|
|
5
5
|
-- harness's business, in harness_testing.lawspec.
|
|
6
6
|
|
|
7
7
|
-- An order: how many items it has, and its total in cents.
|
|
8
|
-
type Order is
|
|
8
|
+
type Order is a record{ items :: Int32 total :: Int32} end type
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function itemsOf (order :: Order) -> Int32 is first matching case of order : when Order record{ items = items , total = total} then items end case end function
|
|
11
|
+
function totalOf (order :: Order) -> Int32 is first matching case of order : when Order record{ items = items , total = total} then total end case end function
|
|
12
|
+
function isEmpty (order :: Order) -> Bool is itemsOf order = 0 end function
|
|
13
13
|
|
|
14
14
|
-- The discount an order gets, and a price rounded to tens of cents.
|
|
15
15
|
discount :: Order -> Int32
|
|
16
16
|
roundCents :: Int32 -> Int32
|
|
17
17
|
|
|
18
|
-
law
|
|
19
|
-
definition
|
|
20
|
-
|
|
21
|
-
(discount order <= totalOf order) = true
|
|
22
|
-
end
|
|
23
|
-
end
|
|
18
|
+
law "|a discount is never more than the total| is
|
|
19
|
+
definition :
|
|
20
|
+
for all (order :: Order where itemsOf order >= 0 && totalOf order >= 0) =>
|
|
21
|
+
(discount order <= totalOf order) = true end for all
|
|
22
|
+
end definition
|
|
23
|
+
end law
|
|
24
24
|
|
|
25
|
-
law
|
|
26
|
-
definition
|
|
27
|
-
|
|
28
|
-
roundCents (roundCents cents) = roundCents cents
|
|
29
|
-
end
|
|
30
|
-
end
|
|
25
|
+
law "|rounding is idempotent| is
|
|
26
|
+
definition :
|
|
27
|
+
for all (cents :: Int32 where cents >= 0 && cents <= 1000000) =>
|
|
28
|
+
roundCents (roundCents cents) = roundCents cents end for all
|
|
29
|
+
end definition
|
|
30
|
+
end law
|
|
31
31
|
|
|
32
|
-
law
|
|
33
|
-
definition
|
|
34
|
-
|
|
35
|
-
(roundCents cents >= cents) = true
|
|
36
|
-
end
|
|
37
|
-
end
|
|
32
|
+
law "|rounding never lowers a price| is
|
|
33
|
+
definition :
|
|
34
|
+
for all (cents :: Int32 where cents >= 0 && cents <= 1000000) =>
|
|
35
|
+
(roundCents cents >= cents) = true end for all
|
|
36
|
+
end definition
|
|
37
|
+
end law
|
|
38
38
|
|
|
39
39
|
-- A ledger records payments. Every law about booking holds for every
|
|
40
40
|
-- lawful ledger; the harness chooses which ones the tests use.
|
|
41
41
|
ability Ledger is
|
|
42
42
|
accept :: Int32 -> Bool
|
|
43
43
|
laws
|
|
44
|
-
law
|
|
45
|
-
definition
|
|
46
|
-
end
|
|
47
|
-
end
|
|
44
|
+
law "|positive amounts are accepted| is
|
|
45
|
+
definition : for all (cents :: Int32 where cents > 0) => accept cents = true end for all end definition
|
|
46
|
+
end law
|
|
47
|
+
end laws
|
|
48
|
+
end ability
|
|
48
49
|
|
|
49
50
|
handler fakeLedger for Ledger is
|
|
50
|
-
accept cents is cents > 0 end
|
|
51
|
-
end
|
|
51
|
+
operation accept cents is cents > 0 end operation
|
|
52
|
+
end handler
|
|
52
53
|
|
|
53
54
|
book :: Int32 -> Bool uses Ledger
|
|
54
55
|
|
|
55
|
-
law
|
|
56
|
-
definition
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
56
|
+
law "|booking a positive amount succeeds| is
|
|
57
|
+
definition :
|
|
58
|
+
for all (cents :: Int32 where cents > 0) => book cents = true end for all
|
|
59
|
+
end definition
|
|
60
|
+
end law
|
|
60
61
|
|
|
61
|
-
law
|
|
62
|
-
definition
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
end
|
|
62
|
+
law "|a refund is never booked twice| is
|
|
63
|
+
definition :
|
|
64
|
+
for all (cents :: Int32 where cents > 0) => book cents = book cents end for all
|
|
65
|
+
end definition
|
|
66
|
+
end law
|
|
66
67
|
|
|
67
68
|
-- A scratch area the laws may use; it can be emptied between laws, and
|
|
68
69
|
-- laws running at the same time cannot interfere through it.
|
|
69
|
-
type Scratch is
|
|
70
|
+
type Scratch is a record{ used :: Int32} end type
|
|
70
71
|
|
|
71
72
|
resource Scratch is concurrent
|
|
72
|
-
acquire is Scratch 0 end
|
|
73
|
-
release scratch is unitValue end
|
|
74
|
-
reset scratch is unitValue end
|
|
75
|
-
end
|
|
73
|
+
acquire is Scratch record{ used = 0} end acquire
|
|
74
|
+
release scratch is unitValue end release
|
|
75
|
+
reset scratch is unitValue end reset
|
|
76
|
+
end resource
|
|
77
|
+
end unit
|
|
@@ -4,42 +4,47 @@
|
|
|
4
4
|
harness example.harness.testing for example.harness is
|
|
5
5
|
-- Small orders: up to three items at a dollar each.
|
|
6
6
|
strategy smallOrder :: Order is
|
|
7
|
-
bind items :: Int32 from (one of 0, 1, 2, 3) in one of Order items (items * 100)
|
|
8
|
-
end
|
|
7
|
+
bind items :: Int32 from (one of 0, 1, 2, 3) in one of Order record{ items = items , total = (items * 100)} end bind
|
|
8
|
+
end strategy
|
|
9
9
|
-- Bulk orders: the default generator, kept to large ones.
|
|
10
10
|
strategy bulkOrder :: Order is
|
|
11
11
|
any such that itemsOf it > 10 && totalOf it >= 0 at most 1000 discards
|
|
12
|
-
end
|
|
13
|
-
strategy orders :: Order is frequency 9 smallOrder, 1 bulkOrder end
|
|
12
|
+
end strategy
|
|
13
|
+
strategy orders :: Order is frequency 9 smallOrder, 1 bulkOrder end strategy
|
|
14
14
|
|
|
15
15
|
tags pricing
|
|
16
16
|
test with fakeLedger
|
|
17
17
|
order random
|
|
18
18
|
parallel
|
|
19
19
|
|
|
20
|
-
for law
|
|
20
|
+
for law "|a discount is never more than the total|
|
|
21
21
|
use orders for order
|
|
22
22
|
cover 5% "empty order" when isEmpty order
|
|
23
23
|
classify totalOf order > 1000 as "large"
|
|
24
|
-
label if isEmpty order then "empty" else "some items"
|
|
24
|
+
label if isEmpty order then "empty" else "some items" end if
|
|
25
25
|
timeout 10 s
|
|
26
|
+
end for law
|
|
26
27
|
|
|
27
|
-
for law
|
|
28
|
+
for law "|rounding is idempotent|
|
|
28
29
|
target maximize cents
|
|
29
30
|
repeat 2
|
|
30
31
|
retry flaky 1
|
|
31
32
|
|
|
32
|
-
for law
|
|
33
|
+
end for law
|
|
34
|
+
for law "|rounding never lowers a price|
|
|
33
35
|
known failing "rounds half down; see PRICE-12"
|
|
34
36
|
|
|
35
|
-
for law
|
|
37
|
+
end for law
|
|
38
|
+
for law "|a refund is never booked twice|
|
|
36
39
|
skip "refunds are not booked yet"
|
|
37
40
|
|
|
38
|
-
for
|
|
41
|
+
end for law
|
|
42
|
+
for laws "|booking a positive amount succeeds|, "|positive amounts are accepted|
|
|
39
43
|
tags ledger
|
|
40
44
|
|
|
45
|
+
end for laws
|
|
41
46
|
share Scratch per unit
|
|
42
|
-
benchmark `discount of a bulk order` is discount (Order 30 50000) end
|
|
47
|
+
benchmark `discount of a bulk order` is discount (Order record{ items = 30 , total = 50000}) end benchmark
|
|
43
48
|
-- book uses Ledger: the benchmark runs under its production handler.
|
|
44
|
-
benchmark `booking a payment` is book 500 end
|
|
45
|
-
end
|
|
49
|
+
benchmark `booking a payment` is book 500 end benchmark
|
|
50
|
+
end harness
|