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.
Files changed (149) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +5 -4
  3. package/api.mjs +0 -8
  4. package/bin/lawspec.mjs +14 -52
  5. package/build.json +77 -105
  6. package/core.wasm +2 -2
  7. package/core_jsffi.js +5 -0
  8. package/examples/native-payments/clojure/lawspec.json +1 -1
  9. package/examples/native-payments/csharp/lawspec.json +1 -1
  10. package/examples/native-payments/elixir/lawspec.json +1 -1
  11. package/examples/native-payments/erlang/lawspec.json +1 -1
  12. package/examples/native-payments/fsharp/lawspec.json +1 -1
  13. package/examples/native-payments/gleam/lawspec.json +1 -1
  14. package/examples/native-payments/go/lawspec.json +1 -1
  15. package/examples/native-payments/groovy/lawspec.json +1 -1
  16. package/examples/native-payments/haskell/lawspec.json +1 -1
  17. package/examples/native-payments/java/lawspec.json +1 -1
  18. package/examples/native-payments/javascript/lawspec.json +1 -1
  19. package/examples/native-payments/kotlin/lawspec.json +1 -1
  20. package/examples/native-payments/python/lawspec.json +1 -1
  21. package/examples/native-payments/rust/lawspec.json +1 -1
  22. package/examples/native-payments/scala/lawspec.json +1 -1
  23. package/examples/native-payments/swift/lawspec.json +1 -1
  24. package/examples/native-payments/typescript/lawspec.json +1 -1
  25. package/examples/packages/orders/lawspec.json +1 -1
  26. package/examples/packages/orders/orders.lawspec +27 -25
  27. package/examples/packages/shop-domain/src/domain.lawspec +15 -14
  28. package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
  29. package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
  30. package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
  31. package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
  32. package/examples/rc1/authorization-snapshots.lawspec +24 -23
  33. package/examples/rc1/banner-filenames.lawspec +7 -6
  34. package/examples/rc1/bit-codec.lawspec +12 -11
  35. package/examples/rc1/bounded-witness-search.lawspec +52 -45
  36. package/examples/rc1/conflicting-requirements.lawspec +8 -7
  37. package/examples/rc1/constructive-witnesses.lawspec +40 -33
  38. package/examples/rc1/documentary-review.lawspec +9 -8
  39. package/examples/rc1/empty-domains.lawspec +16 -15
  40. package/examples/rc1/finite-integer-domains.lawspec +24 -23
  41. package/examples/rc1/law-metadata.lawspec +6 -5
  42. package/examples/rc1/native-payments.lawspec +17 -16
  43. package/examples/rc1/nesting/rrr.lawspec +4 -3
  44. package/examples/rc1/nesting/rru.lawspec +7 -6
  45. package/examples/rc1/nesting/rur.lawspec +7 -6
  46. package/examples/rc1/nesting/ruu.lawspec +10 -9
  47. package/examples/rc1/nesting/urr.lawspec +7 -6
  48. package/examples/rc1/nesting/uru.lawspec +10 -9
  49. package/examples/rc1/nesting/uur.lawspec +10 -9
  50. package/examples/rc1/nesting/uuu.lawspec +13 -12
  51. package/examples/rc1/order-workflow.lawspec +18 -17
  52. package/examples/rc1/parcel-measurements.lawspec +14 -13
  53. package/examples/rc1/picture-records.lawspec +6 -5
  54. package/examples/rc1/picture-tuples.lawspec +6 -5
  55. package/examples/rc1/record-payloads.lawspec +12 -11
  56. package/examples/rc1/recursive-records.lawspec +11 -10
  57. package/examples/rc1/refund-conformance.lawspec +7 -6
  58. package/examples/rc1/refund-policy.lawspec +15 -14
  59. package/examples/rc1/requirement-composition.lawspec +26 -25
  60. package/examples/rc1/structural-records.lawspec +13 -12
  61. package/examples/rc1-authoring.lawspec +6 -5
  62. package/examples/specs/abilities.lawspec +67 -65
  63. package/examples/specs/ability_imports.lawspec +58 -57
  64. package/examples/specs/actors.lawspec +23 -22
  65. package/examples/specs/algebra.lawspec +142 -141
  66. package/examples/specs/approvals.lawspec +16 -15
  67. package/examples/specs/async_bindings.lawspec +10 -9
  68. package/examples/specs/async_fetch.lawspec +12 -11
  69. package/examples/specs/atoi_codec.lawspec +16 -15
  70. package/examples/specs/boolean_flags.lawspec +10 -9
  71. package/examples/specs/builtins.lawspec +73 -72
  72. package/examples/specs/canonical_url.lawspec +14 -13
  73. package/examples/specs/collections.lawspec +153 -154
  74. package/examples/specs/composition.lawspec +70 -66
  75. package/examples/specs/concurrent_collections.lawspec +8 -7
  76. package/examples/specs/consistency.lawspec +4 -3
  77. package/examples/specs/contracts.lawspec +80 -79
  78. package/examples/specs/crypto.lawspec +26 -25
  79. package/examples/specs/ctc.lawspec +148 -0
  80. package/examples/specs/currying.lawspec +32 -31
  81. package/examples/specs/data_types.lawspec +50 -49
  82. package/examples/specs/distribution.lawspec +57 -56
  83. package/examples/specs/domain_modeling.lawspec +48 -47
  84. package/examples/specs/durations.lawspec +39 -38
  85. package/examples/specs/equivalent.lawspec +25 -24
  86. package/examples/specs/failures.lawspec +64 -63
  87. package/examples/specs/finite_data.lawspec +32 -31
  88. package/examples/specs/flow_stack.lawspec +64 -63
  89. package/examples/specs/gadt_expressions.lawspec +50 -49
  90. package/examples/specs/generation.lawspec +115 -114
  91. package/examples/specs/handler_bindings.lawspec +42 -40
  92. package/examples/specs/handles.lawspec +2 -1
  93. package/examples/specs/harness.lawspec +45 -43
  94. package/examples/specs/harness_testing.lawspec +18 -13
  95. package/examples/specs/indexed_arithmetic.lawspec +401 -126
  96. package/examples/specs/indexed_families.lawspec +182 -66
  97. package/examples/specs/keywords.lawspec +22 -21
  98. package/examples/specs/limits.lawspec +6 -5
  99. package/examples/specs/list_contracts.lawspec +121 -120
  100. package/examples/specs/list_refinements.lawspec +43 -42
  101. package/examples/specs/lists.lawspec +45 -44
  102. package/examples/specs/matchers.lawspec +79 -78
  103. package/examples/specs/matching.lawspec +43 -42
  104. package/examples/specs/mixed_inputs.lawspec +25 -24
  105. package/examples/specs/models.lawspec +44 -43
  106. package/examples/specs/parse_port.lawspec +28 -27
  107. package/examples/specs/payments.lawspec +55 -54
  108. package/examples/specs/railway.lawspec +59 -58
  109. package/examples/specs/records.lawspec +149 -148
  110. package/examples/specs/records_inner.lawspec +5 -4
  111. package/examples/specs/recursive_refinements.lawspec +30 -29
  112. package/examples/specs/refined_definitions.lawspec +24 -23
  113. package/examples/specs/refinements.lawspec +58 -57
  114. package/examples/specs/resilience.lawspec +159 -158
  115. package/examples/specs/resources.lawspec +61 -60
  116. package/examples/specs/scalar_adapters.lawspec +60 -59
  117. package/examples/specs/scalar_catalog.lawspec +165 -164
  118. package/examples/specs/scalars.lawspec +78 -77
  119. package/examples/specs/scheduling_order.lawspec +8 -7
  120. package/examples/specs/scheduling_overlap.lawspec +5 -4
  121. package/examples/specs/sequences.lawspec +66 -65
  122. package/examples/specs/sessions.lawspec +13 -12
  123. package/examples/specs/slug.lawspec +16 -15
  124. package/examples/specs/sum_refinements.lawspec +42 -41
  125. package/examples/specs/tables.lawspec +29 -28
  126. package/examples/specs/total_functions.lawspec +71 -70
  127. package/examples/specs/workflows.lawspec +101 -100
  128. package/examples-command.mjs +4 -6
  129. package/explain.mjs +6 -4
  130. package/expression-presentation.mjs +8 -8
  131. package/files.mjs +1 -1
  132. package/index.d.ts +4 -527
  133. package/launcher.mjs +9 -2
  134. package/lsp.mjs +10 -6
  135. package/native-examples.mjs +2 -2
  136. package/package.json +1 -1
  137. package/starter-rc1.lawspec +6 -5
  138. package/starter.lawspec +16 -15
  139. package/templates.mjs +4 -2
  140. package/migrate.mjs +0 -135
  141. package/migration-bindings.mjs +0 -86
  142. package/migration-cases.mjs +0 -45
  143. package/migration-collections.mjs +0 -54
  144. package/migration-correspondence.mjs +0 -275
  145. package/migration-generation.mjs +0 -99
  146. package/migration-laws.mjs +0 -102
  147. package/migration-records.mjs +0 -166
  148. package/migration-source.mjs +0 -247
  149. 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 Money cents :: Int64 end
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 `a till gives back what it takes` is
16
- definition is
17
- `for all` (cents :: Int64 where cents >= 0 && cents <= 1000) . take (Money cents) = Money cents
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 `small payments go through` is
32
- definition is
33
- `for all` (cents :: Int64 where cents >= 0 && cents <= 1000) .
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 `large payments are declined` is
39
- definition is
40
- `for all` (cents :: Int64 where cents > 1000 && cents <= 100000) .
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 `negative payments are rejected` is
46
- definition is
47
- `for all` (cents :: Int64 where cents >= -1000 && cents < 0) .
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 `large payments fail as declined` is
55
- definition is
56
- `for all` (cents :: Int64 where cents > 1000 && cents <= 100000) . pay cents fails with Declined
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 `negative payments say why they are rejected` is
61
- definition is
62
- `for all` (cents :: Int64 where cents >= -1000 && cents < 0) .
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
@@ -17,4 +17,5 @@ model jobs :: shared Jobs behaves like Queue Int32 is
17
17
  submit as offer
18
18
  take as poll
19
19
  pending as size
20
- end
20
+ end model
21
+ 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 Order items :: Int32 total :: Int32 end
8
+ type Order is a record{ items :: Int32 total :: Int32} end type
9
9
 
10
- definition itemsOf (order :: Order) :: Int32 is match order with | Order items total -> items end end
11
- definition totalOf (order :: Order) :: Int32 is match order with | Order items total -> total end end
12
- definition isEmpty (order :: Order) :: Bool is itemsOf order == 0 end
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 `a discount is never more than the total` is
19
- definition is
20
- `for all` (order :: Order where itemsOf order >= 0 && totalOf order >= 0) .
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 `rounding is idempotent` is
26
- definition is
27
- `for all` (cents :: Int32 where cents >= 0 && cents <= 1000000) .
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 `rounding never lowers a price` is
33
- definition is
34
- `for all` (cents :: Int32 where cents >= 0 && cents <= 1000000) .
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 `positive amounts are accepted` is
45
- definition is `for all` (cents :: Int32 where cents > 0) . accept cents = true end
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 `booking a positive amount succeeds` is
56
- definition is
57
- `for all` (cents :: Int32 where cents > 0) . book cents = true
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 `a refund is never booked twice` is
62
- definition is
63
- `for all` (cents :: Int32 where cents > 0) . book cents = book cents
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 Scratch used :: Int32 end
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 `a discount is never more than the total`
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 `rounding is idempotent`
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 `rounding never lowers a price`
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 `a refund is never booked twice`
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 laws `booking a positive amount succeeds`, `positive amounts are accepted`
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