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
@@ -1,51 +1,52 @@
1
1
  unit example.list_refinements
2
2
 
3
- definition above (floor :: Int8) (xs :: List Int8) :: Bool is
4
- match xs with
5
- | Nil -> true
6
- | Cons first rest -> first > floor && above floor rest
7
- end
8
- end
3
+ function above (floor :: Int8) (xs :: List Int8) -> Bool is
4
+ first matching case of xs :
5
+ when Nil then true
6
+ when Cons first rest then first > floor && above floor rest
7
+ end case
8
+ end function
9
9
 
10
- definition positiveRows (rows :: List (List Int8)) :: Bool is
11
- match rows with
12
- | Nil -> true
13
- | Cons first rest -> above 0 first && positiveRows rest
14
- end
15
- end
10
+ function positiveRows (rows :: List (List Int8)) -> Bool is
11
+ first matching case of rows :
12
+ when Nil then true
13
+ when Cons first rest then above 0 first && positiveRows rest
14
+ end case
15
+ end function
16
16
 
17
- law `each element is positive` is
18
- definition is `for all` (xs :: List (value :: Int8 where value > 0)) .
19
- above 0 xs = true
20
- end
21
- example `empty` is xs = [] expect above 0 xs = true end
22
- example `positive values` is xs = [1, 127] expect above 0 xs = true end
23
- end
17
+ law "|each element is positive| is
18
+ definition : for all (xs :: List (value :: Int8 where value > 0)) =>
19
+ above 0 xs = true end for all
20
+ end definition
21
+ example "|empty| : xs = [] expect above 0 xs = true end example
22
+ example "|positive values| : xs = [1, 127] expect above 0 xs = true end example
23
+ end law
24
24
 
25
- law `nested element domains` is
26
- definition is `for all` (rows :: List (List (value :: Int8 where value > 0))) .
27
- positiveRows rows = true
28
- end
29
- example `empty rows` is rows = [[], [1, 2]] expect positiveRows rows = true end
30
- end
25
+ law "|nested element domains| is
26
+ definition : for all (rows :: List (List (value :: Int8 where value > 0))) =>
27
+ positiveRows rows = true end for all
28
+ end definition
29
+ example "|empty rows| : rows = [[], [1, 2]] expect positiveRows rows = true end example
30
+ end law
31
31
 
32
- law `dependent elements` is
33
- definition is `for all` (lawspecElement :: Int8)
34
- (xs :: List (value :: Int8 where value > lawspecElement)) .
35
- above lawspecElement xs = true
36
- end
37
- example `maximum prefix still permits empty` is
32
+ law "|dependent elements| is
33
+ definition : for all (lawspecElement :: Int8)
34
+ (xs :: List (value :: Int8 where value > lawspecElement)) =>
35
+ above lawspecElement xs = true end for all
36
+ end definition
37
+ example "|maximum prefix still permits empty| :
38
38
  lawspecElement = 127 xs = [] expect above lawspecElement xs = true
39
- end
40
- example `nonempty continuation` is
39
+ end example
40
+ example "|nonempty continuation| :
41
41
  lawspecElement = 0 xs = [1, 2] expect above lawspecElement xs = true
42
- end
43
- end
42
+ end example
43
+ end law
44
44
 
45
- law `division stays behind its guard` is
46
- definition is `for all`
47
- (xs :: List (value :: Int8 where value != 0 && 1 / value > 0)) .
48
- above 0 xs = true
49
- end
50
- example `positive denominator` is xs = [1] expect above 0 xs = true end
51
- end
45
+ law "|division stays behind its guard| is
46
+ definition : for all
47
+ (xs :: List (value :: Int8 where value != 0 && 1 / value > 0)) =>
48
+ above 0 xs = true end for all
49
+ end definition
50
+ example "|positive denominator| : xs = [1] expect above 0 xs = true end example
51
+ end law
52
+ end unit
@@ -8,60 +8,61 @@ echoMaybe :: Maybe (Maybe Bool) -> Maybe (Maybe Bool)
8
8
  echoEither :: Either (List Int32) (Maybe Bool) -> Either (List Int32) (Maybe Bool)
9
9
  echoNested :: List (Maybe (Either CodeUnit16 Bytes)) -> List (Maybe (Either CodeUnit16 Bytes))
10
10
 
11
- law `list involution` (f :: List a -> List a) requires Eq a is
12
- definition is `involution` f end
13
- end
11
+ law "|list involution| (f :: List a -> List a) requires Eq a is
12
+ definition : apply law "|involution| f end definition
13
+ end law
14
14
 
15
- law `reverse twice restores the list` is
16
- definition is `list involution` reverse end
17
- example `ordered input` is
15
+ law "|reverse twice restores the list| is
16
+ definition : apply law "|list involution| reverse end definition
17
+ example "|ordered input| :
18
18
  x = [3, 1, 2]
19
19
  expect reverse x = [2, 1, 3]
20
- end
21
- example `empty input` is x = [] expect reverse x = [] end
22
- end
20
+ end example
21
+ example "|empty input| : x = [] expect reverse x = [] end example
22
+ end law
23
23
 
24
- law `sorting is idempotent` is
25
- definition is `idempotent` sort end
26
- example `duplicates` is x = [3, 1, 3] expect sort x = [1, 3, 3] end
27
- end
24
+ law "|sorting is idempotent| is
25
+ definition : apply law "|idempotent| sort end definition
26
+ example "|duplicates| : x = [3, 1, 3] expect sort x = [1, 3, 3] end example
27
+ end law
28
28
 
29
- law `sort produces sorted output` is
30
- definition is `for all` (xs :: List Int32) . sorted (sort xs) end
31
- end
29
+ law "|sort produces sorted output| is
30
+ definition : for all (xs :: List Int32) => sorted (sort xs) end for all end definition
31
+ end law
32
32
 
33
- law `sort preserves length` is
34
- definition is `for all` (xs :: List Int32) . prelude.length (sort xs) = prelude.length xs end
35
- end
33
+ law "|sort preserves length| is
34
+ definition : for all (xs :: List Int32) => prelude.length (sort xs) = prelude.length xs end for all end definition
35
+ end law
36
36
 
37
- law `sort preserves elements` is
38
- definition is `for all` (xs :: List Int32) . permutation (sort xs) xs end
39
- end
37
+ law "|sort preserves elements| is
38
+ definition : for all (xs :: List Int32) => permutation (sort xs) xs end for all end definition
39
+ end law
40
40
 
41
- law `nonempty reversal preserves length` is
42
- definition is
43
- `for all` (xs :: List Int32 where prelude.length xs > 0) .
44
- prelude.length (reverse xs) = prelude.length xs
45
- end
46
- end
41
+ law "|nonempty reversal preserves length| is
42
+ definition :
43
+ for all (xs :: List Int32 where prelude.length xs > 0) =>
44
+ prelude.length (reverse xs) = prelude.length xs end for all
45
+ end definition
46
+ end law
47
47
 
48
- law `Maybe preserves nested absence` is
49
- definition is `for all` (x :: Maybe (Maybe Bool)) . echoMaybe x = x end
50
- example `outer absence` is x = Nothing expect echoMaybe x = Nothing end
51
- example `inner absence` is x = Just Nothing expect echoMaybe x = Just Nothing end
52
- example `present` is x = Just (Just true) expect echoMaybe x = Just (Just true) end
53
- end
48
+ law "|Maybe preserves nested absence| is
49
+ definition : for all (x :: Maybe (Maybe Bool)) => echoMaybe x = x end for all end definition
50
+ example "|outer absence| : x = Nothing expect echoMaybe x = Nothing end example
51
+ example "|inner absence| : x = Just Nothing expect echoMaybe x = Just Nothing end example
52
+ example "|present| : x = Just (Just true) expect echoMaybe x = Just (Just true) end example
53
+ end law
54
54
 
55
- law `Either preserves branches` is
56
- definition is `for all` (x :: Either (List Int32) (Maybe Bool)) . echoEither x = x end
57
- example `left list` is x = Left [3, 1, 3] expect echoEither x = Left [3, 1, 3] end
58
- example `right absence` is x = Right Nothing expect echoEither x = Right Nothing end
59
- end
55
+ law "|Either preserves branches| is
56
+ definition : for all (x :: Either (List Int32) (Maybe Bool)) => echoEither x = x end for all end definition
57
+ example "|left list| : x = Left [3, 1, 3] expect echoEither x = Left [3, 1, 3] end example
58
+ example "|right absence| : x = Right Nothing expect echoEither x = Right Nothing end example
59
+ end law
60
60
 
61
- law `nested raw values survive` is
62
- definition is `for all` (xs :: List (Maybe (Either CodeUnit16 Bytes))) . echoNested xs = xs end
63
- example `surrogate and octets` is
61
+ law "|nested raw values survive| is
62
+ definition : for all (xs :: List (Maybe (Either CodeUnit16 Bytes))) => echoNested xs = xs end for all end definition
63
+ example "|surrogate and octets| :
64
64
  xs = [Nothing, Just (Left codeUnit16(55296)), Just (Right bytes([0, 255]))]
65
65
  expect echoNested xs = [Nothing, Just (Left codeUnit16(55296)), Just (Right bytes([0, 255]))]
66
- end
67
- end
66
+ end example
67
+ end law
68
+ end unit
@@ -4,11 +4,11 @@ unit example.matchers
4
4
  -- Bool, so a law may combine them with && and ||, and an example may expect
5
5
  -- one to hold.
6
6
 
7
- type Order is
8
- | Pending id :: Int32
9
- | Shipped id :: Int32 carrier :: Text
10
- | Cancelled id :: Int32 reason :: Maybe Text
11
- end
7
+ type Order is one of
8
+ | Pending of type Int32
9
+ | Shipped of type record{ id :: Int32 carrier :: Text}
10
+ | Cancelled of type record{ id :: Int32 reason :: Maybe Text}
11
+ end type
12
12
 
13
13
  -- Native adapters, written on each target.
14
14
  sortItems :: List Int32 -> List Int32
@@ -17,96 +17,97 @@ average :: Int32 -> Int32 -> Float64
17
17
  slug :: Text -> Text
18
18
  ship :: Int32 -> Order
19
19
 
20
- law `sorting keeps every item` is
21
- definition is
22
- `for all` (xs :: List Int32) . sortItems xs has same items as xs
23
- end
24
- example `duplicates stay` is
20
+ law "|sorting keeps every item| is
21
+ definition :
22
+ for all (xs :: List Int32) => sortItems xs has same items as xs end for all
23
+ end definition
24
+ example "|duplicates stay| :
25
25
  xs = [3, 1, 3]
26
26
  expect sortItems xs = [1, 3, 3]
27
- end
28
- end
27
+ end example
28
+ end law
29
29
 
30
- law `unique tags come from the input` is
31
- definition is
32
- `for all` (tags :: List Text) .
33
- uniqueTags tags is subset of tags && tags contains all of uniqueTags tags
34
- end
35
- end
30
+ law "|unique tags come from the input| is
31
+ definition :
32
+ for all (tags :: List Text) =>
33
+ uniqueTags tags is subset of tags && tags contains all of uniqueTags tags end for all
34
+ end definition
35
+ end law
36
36
 
37
- law `unique tags keep each tag` is
38
- definition is
39
- `for all` (tags :: List Text) (tag :: Text) .
40
- tags contains tag implies uniqueTags tags contains tag
41
- end
42
- end
37
+ law "|unique tags keep each tag| is
38
+ definition :
39
+ for all (tags :: List Text) (tag :: Text) =>
40
+ tags contains tag implies uniqueTags tags contains tag end for all
41
+ end definition
42
+ end law
43
43
 
44
- law `the average lies between the two` is
45
- definition is
46
- `for all` (a :: Int32) (b :: Int32) .
47
- average a b is within 0.5 of prelude.Float64 (prelude.quot (a + b) 2)
48
- end
49
- end
44
+ law "|the average lies between the two| is
45
+ definition :
46
+ for all (a :: Int32) (b :: Int32) =>
47
+ average a b is within 0.5 of prelude.Float64 (prelude.quot (a + b) 2) end for all
48
+ end definition
49
+ end law
50
50
 
51
- law `a slug is lowercase words joined by dashes` is
52
- definition is
53
- `for all` (title :: Text) .
54
- slug title matches regex "([a-z0-9]+(-[a-z0-9]+)*)?"
55
- end
56
- example `a title` is
51
+ law "|a slug is lowercase words joined by dashes| is
52
+ definition :
53
+ for all (title :: Text) =>
54
+ slug title matches regex "([a-z0-9]+(-[a-z0-9]+)*)?" end for all
55
+ end definition
56
+ example "|a title| :
57
57
  title = "Hello World"
58
58
  expect slug title = "hello-world"
59
59
  expect slug title starts with "hello"
60
60
  expect slug title ends with "world"
61
61
  expect slug title contains "o-w"
62
- end
63
- end
62
+ end example
63
+ end law
64
64
 
65
- law `shipping gives a shipped order` is
66
- definition is
67
- `for all` (id :: Int32) . ship id matches Shipped _ _
68
- end
69
- example `the carrier is never empty` is
65
+ law "|shipping gives a shipped order| is
66
+ definition :
67
+ for all (id :: Int32) => ship id matches Shipped record{ id = _ , carrier = _} end for all
68
+ end definition
69
+ example "|the carrier is never empty| :
70
70
  id = 7
71
- expect ship id matches Shipped 7 _
72
- expect !(ship id matches Shipped _ "")
73
- end
74
- end
71
+ expect ship id matches Shipped record{ id = 7 , carrier = _}
72
+ expect !(ship id matches Shipped record{ id = _ , carrier = ""})
73
+ end example
74
+ end law
75
75
 
76
76
  -- Laws of the matchers themselves.
77
- law `having the same items is symmetric` is
78
- definition is
79
- `for all` (xs :: List Int8) (ys :: List Int8) .
80
- (xs has same items as ys) = (ys has same items as xs)
81
- end
82
- end
77
+ law "|having the same items is symmetric| is
78
+ definition :
79
+ for all (xs :: List Int8) (ys :: List Int8) =>
80
+ (xs has same items as ys) = (ys has same items as xs) end for all
81
+ end definition
82
+ end law
83
83
 
84
- law `a list contains each of its items` is
85
- definition is
86
- `for all` (x :: Int8) (xs :: List Int8) . Cons x xs contains x
87
- end
88
- end
84
+ law "|a list contains each of its items| is
85
+ definition :
86
+ for all (x :: Int8) (xs :: List Int8) => Cons x xs contains x end for all
87
+ end definition
88
+ end law
89
89
 
90
- law `a list is a subset of itself` is
91
- definition is
92
- `for all` (xs :: List Int8) . xs is subset of xs && xs contains all of xs
93
- end
94
- end
90
+ law "|a list is a subset of itself| is
91
+ definition :
92
+ for all (xs :: List Int8) => xs is subset of xs && xs contains all of xs end for all
93
+ end definition
94
+ end law
95
95
 
96
- law `a text starts and ends with itself` is
97
- definition is
98
- `for all` (t :: Text) . t starts with t && t ends with t && t contains t && t contains ""
99
- end
100
- end
96
+ law "|a text starts and ends with itself| is
97
+ definition :
98
+ for all (t :: Text) => t starts with t && t ends with t && t contains t && t contains "" end for all
99
+ end definition
100
+ end law
101
101
 
102
- law `a number is within any tolerance of itself` is
103
- definition is
104
- `for all` (x :: Int32) (d :: Int32 where d >= 0) . x is within d of x
105
- end
106
- end
102
+ law "|a number is within any tolerance of itself| is
103
+ definition :
104
+ for all (x :: Int32) (d :: Int32 where d >= 0) => x is within d of x end for all
105
+ end definition
106
+ end law
107
107
 
108
- law `a regex value matches like a literal` is
109
- definition is
110
- `for all` (t :: Text) . (t matches regex "[a-c]*") = (t matches regex "[a-c]*")
111
- end
112
- end
108
+ law "|a regex value matches like a literal| is
109
+ definition :
110
+ for all (t :: Text) => (t matches regex "[a-c]*") = (t matches regex "[a-c]*") end for all
111
+ end definition
112
+ end law
113
+ end unit
@@ -1,49 +1,50 @@
1
1
  unit example.matching
2
2
 
3
3
  -- Rebuilding values checks both constructor identity and every payload field.
4
- law `list patterns preserve the head and tail` is
5
- definition is
6
- `for all` (xs :: List Int8) .
7
- (match xs with
8
- | Nil -> []
9
- | Cons head tail -> Cons head tail
10
- end) = xs
11
- end
12
- end
4
+ law "|list patterns preserve the head and tail| is
5
+ definition :
6
+ for all (xs :: List Int8) =>
7
+ (first matching case of xs :
8
+ when Nil then []
9
+ when Cons head tail then Cons head tail
10
+ end case) = xs end for all
11
+ end definition
12
+ end law
13
13
 
14
- law `nested Maybe patterns preserve each absence state` is
15
- definition is
16
- `for all` (value :: Maybe (Maybe Bool)) .
17
- (match value with
18
- | Nothing -> Nothing
19
- | Just inner -> Just (match inner with
20
- | Nothing -> Nothing
21
- | Just payload -> Just payload
22
- end)
23
- end) = value
24
- end
25
- end
14
+ law "|nested Maybe patterns preserve each absence state| is
15
+ definition :
16
+ for all (value :: Maybe (Maybe Bool)) =>
17
+ (first matching case of value :
18
+ when Nothing then Nothing
19
+ when Just inner then Just (first matching case of inner :
20
+ when Nothing then Nothing
21
+ when Just payload then Just payload
22
+ end case)
23
+ end case) = value end for all
24
+ end definition
25
+ end law
26
26
 
27
- law `Either patterns preserve their constructor` is
28
- definition is
29
- `for all` (value :: Either (List Int8) (Maybe Bool)) .
30
- (match value with
31
- | Left items -> Left items
32
- | Right optional -> Right optional
33
- end) = value
34
- end
35
- end
27
+ law "|Either patterns preserve their constructor| is
28
+ definition :
29
+ for all (value :: Either (List Int8) (Maybe Bool)) =>
30
+ (first matching case of value :
31
+ when Left items then Left items
32
+ when Right optional then Right optional
33
+ end case) = value end for all
34
+ end definition
35
+ end law
36
36
 
37
37
  -- The annotation gives the empty-case literal the same primitive type as head.
38
- law `matching can provide a default value` is
39
- definition is
40
- `for all` (value :: Maybe Int8) .
41
- ((match value with
42
- | Nothing -> 0
43
- | Just payload -> payload
44
- end) :: Int8) = ((match value with
45
- | Just payload -> payload
46
- | Nothing -> 0
47
- end) :: Int8)
48
- end
49
- end
38
+ law "|matching can provide a default value| is
39
+ definition :
40
+ for all (value :: Maybe Int8) =>
41
+ ((first matching case of value :
42
+ when Nothing then 0
43
+ when Just payload then payload
44
+ end case) :: Int8) = ((first matching case of value :
45
+ when Just payload then payload
46
+ when Nothing then 0
47
+ end case) :: Int8) end for all
48
+ end definition
49
+ end law
50
+ end unit
@@ -3,39 +3,40 @@ unit example.mixed.inputs
3
3
  normalize :: Text -> Text
4
4
  identity :: Int32 -> Int32
5
5
 
6
- law `text normalization reaches a fixed point with an unused integer input` is
7
- definition is
8
- `for all` (text :: Text) (number :: Int32) .
9
- normalize text = normalize (normalize text)
10
- end
11
- example `text normalization and integer identity have explicit results` is
6
+ law "|text normalization reaches a fixed point with an unused integer input| is
7
+ definition :
8
+ for all (text :: Text) (number :: Int32) =>
9
+ normalize text = normalize (normalize text) end for all
10
+ end definition
11
+ example "|text normalization and integer identity have explicit results| :
12
12
  text = "Hello, World!"
13
13
  number = -42
14
14
  expect normalize text = "Hello,-World!"
15
15
  expect identity number = -42
16
- end
17
- end
16
+ end example
17
+ end law
18
18
 
19
- law `integer identity with an unused text input` is
20
- definition is
21
- `for all` (text :: Text) (number :: Int32) .
22
- identity number = number
23
- end
24
- example `text normalization and integer identity have explicit results` is
19
+ law "|integer identity with an unused text input| is
20
+ definition :
21
+ for all (text :: Text) (number :: Int32) =>
22
+ identity number = number end for all
23
+ end definition
24
+ example "|text normalization and integer identity have explicit results| :
25
25
  text = "λ 😀"
26
26
  number = 2147483647
27
27
  expect normalize text = "λ-😀"
28
28
  expect identity number = 2147483647
29
- end
30
- end
29
+ end example
30
+ end law
31
31
 
32
- law `normalizing an empty literal` is
33
- definition is
34
- `for all` (text :: Text) .
35
- normalize "" = ""
36
- end
37
- example `empty literal stays empty; quantified text is unused` is
32
+ law "|normalizing an empty literal| is
33
+ definition :
34
+ for all (text :: Text) =>
35
+ normalize "" = "" end for all
36
+ end definition
37
+ example "|empty literal stays empty; quantified text is unused| :
38
38
  text = "unused context"
39
39
  expect normalize "" = ""
40
- end
41
- end
40
+ end example
41
+ end law
42
+ end unit