lawspec 0.24.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 (148) hide show
  1. package/CHANGELOG.md +109 -1
  2. package/README.md +34 -26
  3. package/UNICODE-LICENSE.txt +39 -0
  4. package/api.mjs +6 -23
  5. package/bin/lawspec.mjs +148 -65
  6. package/build.json +245 -177
  7. package/builtin-data-names.mjs +73 -0
  8. package/core.wasm +2 -2
  9. package/core_jsffi.js +5 -0
  10. package/examples/native-payments/clojure/lawspec.json +13 -2
  11. package/examples/native-payments/csharp/lawspec.json +13 -2
  12. package/examples/native-payments/elixir/lawspec.json +14 -3
  13. package/examples/native-payments/erlang/lawspec.json +14 -3
  14. package/examples/native-payments/fsharp/lawspec.json +14 -3
  15. package/examples/native-payments/gleam/lawspec.json +14 -3
  16. package/examples/native-payments/go/lawspec.json +14 -3
  17. package/examples/native-payments/groovy/lawspec.json +14 -3
  18. package/examples/native-payments/haskell/lawspec.json +14 -3
  19. package/examples/native-payments/java/lawspec.json +14 -3
  20. package/examples/native-payments/javascript/lawspec.json +14 -3
  21. package/examples/native-payments/kotlin/lawspec.json +14 -3
  22. package/examples/native-payments/python/lawspec.json +14 -3
  23. package/examples/native-payments/rust/lawspec.json +14 -3
  24. package/examples/native-payments/scala/lawspec.json +14 -3
  25. package/examples/native-payments/swift/lawspec.json +14 -3
  26. package/examples/native-payments/typescript/lawspec.json +14 -3
  27. package/examples/packages/orders/lawspec.json +25 -5
  28. package/examples/packages/orders/orders.lawspec +57 -53
  29. package/examples/packages/shop-domain/src/domain.lawspec +36 -33
  30. package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
  31. package/examples/packages/shop-tax-1/src/rates.lawspec +5 -4
  32. package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
  33. package/examples/packages/shop-tax-2/src/rates.lawspec +6 -4
  34. package/examples/rc1/authorization-snapshots.lawspec +113 -0
  35. package/examples/rc1/banner-filenames.lawspec +64 -0
  36. package/examples/rc1/bit-codec.lawspec +57 -0
  37. package/examples/rc1/bounded-witness-search.lawspec +151 -0
  38. package/examples/rc1/conflicting-requirements.lawspec +31 -0
  39. package/examples/rc1/constructive-witnesses.lawspec +120 -0
  40. package/examples/rc1/documentary-review.lawspec +43 -0
  41. package/examples/rc1/empty-domains.lawspec +47 -0
  42. package/examples/rc1/finite-integer-domains.lawspec +76 -0
  43. package/examples/rc1/law-metadata.lawspec +30 -0
  44. package/examples/rc1/native-payments.lawspec +108 -0
  45. package/examples/rc1/nesting/rrr.lawspec +34 -0
  46. package/examples/rc1/nesting/rru.lawspec +57 -0
  47. package/examples/rc1/nesting/rur.lawspec +58 -0
  48. package/examples/rc1/nesting/ruu.lawspec +78 -0
  49. package/examples/rc1/nesting/urr.lawspec +53 -0
  50. package/examples/rc1/nesting/uru.lawspec +73 -0
  51. package/examples/rc1/nesting/uur.lawspec +74 -0
  52. package/examples/rc1/nesting/uuu.lawspec +96 -0
  53. package/examples/rc1/order-workflow.lawspec +127 -0
  54. package/examples/rc1/parcel-measurements.lawspec +93 -0
  55. package/examples/rc1/picture-records.lawspec +52 -0
  56. package/examples/rc1/picture-tuples.lawspec +48 -0
  57. package/examples/rc1/record-payloads.lawspec +57 -0
  58. package/examples/rc1/recursive-records.lawspec +65 -0
  59. package/examples/rc1/refund-conformance.lawspec +45 -0
  60. package/examples/rc1/refund-policy.lawspec +89 -0
  61. package/examples/rc1/requirement-composition.lawspec +90 -0
  62. package/examples/rc1/structural-records.lawspec +54 -0
  63. package/examples/rc1-authoring.lawspec +57 -0
  64. package/examples/specs/abilities.lawspec +67 -65
  65. package/examples/specs/ability_imports.lawspec +58 -57
  66. package/examples/specs/actors.lawspec +23 -22
  67. package/examples/specs/algebra.lawspec +142 -141
  68. package/examples/specs/approvals.lawspec +16 -15
  69. package/examples/specs/async_bindings.lawspec +10 -9
  70. package/examples/specs/async_fetch.lawspec +12 -11
  71. package/examples/specs/atoi_codec.lawspec +16 -15
  72. package/examples/specs/boolean_flags.lawspec +10 -9
  73. package/examples/specs/builtins.lawspec +73 -72
  74. package/examples/specs/canonical_url.lawspec +14 -13
  75. package/examples/specs/collections.lawspec +153 -154
  76. package/examples/specs/composition.lawspec +70 -66
  77. package/examples/specs/concurrent_collections.lawspec +8 -7
  78. package/examples/specs/consistency.lawspec +4 -3
  79. package/examples/specs/contracts.lawspec +80 -79
  80. package/examples/specs/crypto.lawspec +26 -25
  81. package/examples/specs/ctc.lawspec +148 -0
  82. package/examples/specs/currying.lawspec +32 -31
  83. package/examples/specs/data_types.lawspec +50 -49
  84. package/examples/specs/distribution.lawspec +57 -56
  85. package/examples/specs/domain_modeling.lawspec +48 -47
  86. package/examples/specs/durations.lawspec +39 -38
  87. package/examples/specs/equivalent.lawspec +25 -24
  88. package/examples/specs/failures.lawspec +64 -63
  89. package/examples/specs/finite_data.lawspec +32 -31
  90. package/examples/specs/flow_stack.lawspec +64 -63
  91. package/examples/specs/gadt_expressions.lawspec +50 -49
  92. package/examples/specs/generation.lawspec +115 -114
  93. package/examples/specs/handler_bindings.lawspec +42 -40
  94. package/examples/specs/handles.lawspec +2 -1
  95. package/examples/specs/harness.lawspec +45 -43
  96. package/examples/specs/harness_testing.lawspec +18 -13
  97. package/examples/specs/indexed_arithmetic.lawspec +401 -126
  98. package/examples/specs/indexed_families.lawspec +182 -66
  99. package/examples/specs/keywords.lawspec +22 -21
  100. package/examples/specs/limits.lawspec +6 -5
  101. package/examples/specs/list_contracts.lawspec +121 -120
  102. package/examples/specs/list_refinements.lawspec +43 -42
  103. package/examples/specs/lists.lawspec +45 -44
  104. package/examples/specs/matchers.lawspec +79 -78
  105. package/examples/specs/matching.lawspec +43 -42
  106. package/examples/specs/mixed_inputs.lawspec +25 -24
  107. package/examples/specs/models.lawspec +44 -43
  108. package/examples/specs/parse_port.lawspec +28 -27
  109. package/examples/specs/payments.lawspec +55 -54
  110. package/examples/specs/railway.lawspec +59 -58
  111. package/examples/specs/records.lawspec +149 -148
  112. package/examples/specs/records_inner.lawspec +5 -4
  113. package/examples/specs/recursive_refinements.lawspec +30 -29
  114. package/examples/specs/refined_definitions.lawspec +24 -23
  115. package/examples/specs/refinements.lawspec +58 -57
  116. package/examples/specs/resilience.lawspec +159 -158
  117. package/examples/specs/resources.lawspec +61 -60
  118. package/examples/specs/scalar_adapters.lawspec +60 -59
  119. package/examples/specs/scalar_catalog.lawspec +165 -164
  120. package/examples/specs/scalars.lawspec +78 -77
  121. package/examples/specs/scheduling_order.lawspec +8 -7
  122. package/examples/specs/scheduling_overlap.lawspec +5 -4
  123. package/examples/specs/sequences.lawspec +66 -65
  124. package/examples/specs/sessions.lawspec +13 -12
  125. package/examples/specs/slug.lawspec +16 -15
  126. package/examples/specs/sum_refinements.lawspec +42 -41
  127. package/examples/specs/tables.lawspec +29 -28
  128. package/examples/specs/total_functions.lawspec +71 -70
  129. package/examples/specs/workflows.lawspec +101 -100
  130. package/examples-command.mjs +8 -4
  131. package/explain.mjs +114 -0
  132. package/expression-presentation.mjs +333 -0
  133. package/files.mjs +16 -0
  134. package/index.d.ts +406 -11
  135. package/launcher.mjs +9 -2
  136. package/lsp.mjs +235 -0
  137. package/native-evidence.mjs +187 -0
  138. package/native-examples.mjs +8 -1
  139. package/node-events-reporter.mjs +23 -0
  140. package/package.json +8 -1
  141. package/positional-fields.mjs +13 -0
  142. package/proof.d.ts +35 -0
  143. package/proof.mjs +174 -0
  144. package/starter-rc1.lawspec +26 -0
  145. package/starter.lawspec +16 -15
  146. package/templates.mjs +6 -4
  147. package/test-command.mjs +107 -35
  148. package/typed-presentation.mjs +165 -0
@@ -1,125 +1,125 @@
1
1
  unit example.scalars
2
2
 
3
- law `integer promotion` is
4
- definition is `for all` (x :: Int8) . x + 1 = 1 + x end
5
- example `overflow is preserved` is
3
+ law "|integer promotion| is
4
+ definition : for all (x :: Int8) => x + 1 = 1 + x end for all end definition
5
+ example "|overflow is preserved| :
6
6
  x = 127
7
7
  expect x + 1 = 128
8
- end
9
- end
8
+ end example
9
+ end law
10
10
 
11
- law `unsigned precision` is
12
- definition is `for all` (x :: UInt64) . x + 0 = x end
13
- example `maximum` is
11
+ law "|unsigned precision| is
12
+ definition : for all (x :: UInt64) => x + 0 = x end for all end definition
13
+ example "|maximum| :
14
14
  x = 18446744073709551615
15
15
  expect x + 1 = 18446744073709551616
16
- end
17
- end
16
+ end example
17
+ end law
18
18
 
19
- law `decimal exactness` is
20
- definition is `for all` (x :: Decimal) . x + 0.1 = 0.1 + x end
21
- example `tenths` is
19
+ law "|decimal exactness| is
20
+ definition : for all (x :: Decimal) => x + 0.1 = 0.1 + x end for all end definition
21
+ example "|tenths| :
22
22
  x = 0.1
23
23
  expect x + 0.2 = 0.3
24
- end
25
- end
24
+ end example
25
+ end law
26
26
 
27
- law `exact division` is
28
- definition is `for all` (x :: Int16) . x / 2 = x / 2 end
29
- example `one half` is
27
+ law "|exact division| is
28
+ definition : for all (x :: Int16) => x / 2 = x / 2 end for all end definition
29
+ example "|one half| :
30
30
  x = 1
31
31
  expect x / 2 = rational(1, 2)
32
32
  expect prelude.quot -7 3 = -2
33
33
  expect prelude.rem -7 3 = -1
34
34
  expect prelude.round rational(125, 100) 1 = 1.2
35
- end
36
- end
35
+ end example
36
+ end law
37
37
 
38
- law `IEEE classification` is
39
- definition is `for all` (x :: Float32) . prelude.isNaN x = prelude.isNaN x end
40
- example `NaN` is
38
+ law "|IEEE classification| is
39
+ definition : for all (x :: Float32) => prelude.isNaN x = prelude.isNaN x end for all end definition
40
+ example "|NaN| :
41
41
  x = float32Bits("7fc00000")
42
42
  expect prelude.isNaN x = true
43
- end
44
- example `negative zero` is
43
+ end example
44
+ example "|negative zero| :
45
45
  x = float32Bits("80000000")
46
46
  expect prelude.isNegativeZero x = true
47
47
  expect x = (0 :: Float32)
48
- end
49
- example `infinity` is
48
+ end example
49
+ example "|infinity| :
50
50
  x = float32Bits("7f800000")
51
51
  expect prelude.isInfinite x = true
52
52
  expect prelude.Float32 0.1 = (0.1 :: Float32)
53
- end
54
- end
53
+ end example
54
+ end law
55
55
 
56
- law `complex arithmetic` is
57
- definition is `for all` (x :: Unit) . complex64(1, 2) * complex64(3, 4) = complex64(-5, 10) end
58
- example `product` is
56
+ law "|complex arithmetic| is
57
+ definition : for all (x :: Unit) => complex64(1, 2) * complex64(3, 4) = complex64(-5, 10) end for all end definition
58
+ example "|product| :
59
59
  x = unitValue
60
60
  expect complex64(1, 2) * complex64(3, 4) = complex64(-5, 10)
61
- end
62
- end
61
+ end example
62
+ end law
63
63
 
64
- law `raw units survive` is
65
- definition is `for all` (x :: Utf16Text) . x = x end
66
- example `unpaired surrogate` is
64
+ law "|raw units survive| is
65
+ definition : for all (x :: Utf16Text) => x = x end for all end definition
66
+ example "|unpaired surrogate| :
67
67
  x = utf16([55296, 0, 56320])
68
68
  expect x = utf16([55296, 0, 56320])
69
- end
70
- end
69
+ end example
70
+ end law
71
71
 
72
- law `arbitrary bytes` is
73
- definition is `for all` (x :: Bytes) . x = x end
74
- example `octets` is
72
+ law "|arbitrary bytes| is
73
+ definition : for all (x :: Bytes) => x = x end for all end definition
74
+ example "|octets| :
75
75
  x = bytes([0, 128, 255])
76
76
  expect x = bytes([0, 128, 255])
77
- end
78
- end
77
+ end example
78
+ end law
79
79
 
80
- law `symbol fixture identity` is
81
- definition is `for all` (x :: Symbol) . x = x end
82
- example `same reference` is
80
+ law "|symbol fixture identity| is
81
+ definition : for all (x :: Symbol) => x = x end for all end definition
82
+ example "|same reference| :
83
83
  x = symbol("first", "description")
84
84
  expect x = symbol("first", "description")
85
- end
86
- end
85
+ end example
86
+ end law
87
87
 
88
- law `nested absence` is
89
- definition is `for all` (x :: Optional (Nullable Int8)) . x = x end
90
- example `undefined` is
88
+ law "|nested absence| is
89
+ definition : for all (x :: Optional (Nullable Int8)) => x = x end for all end definition
90
+ example "|undefined| :
91
91
  x = undefined
92
92
  expect x = undefined
93
- end
94
- example `present null` is
93
+ end example
94
+ example "|present null| :
95
95
  x = optional(null)
96
96
  expect x = optional(null)
97
- end
98
- example `present integer` is
97
+ end example
98
+ example "|present integer| :
99
99
  x = optional(nullable(7))
100
100
  expect x = optional(nullable(7))
101
- end
102
- end
101
+ end example
102
+ end law
103
103
 
104
- law `supplementary scalar` is
105
- definition is `for all` (x :: Char) . x = x end
106
- example `emoji` is
104
+ law "|supplementary scalar| is
105
+ definition : for all (x :: Char) => x = x end for all end definition
106
+ example "|emoji| :
107
107
  x = char(128512)
108
108
  expect x = char(128512)
109
- end
110
- end
109
+ end example
110
+ end law
111
111
 
112
- law `surrogate code point` is
113
- definition is `for all` (x :: CodePointText) . x = x end
114
- example `surrogate` is
112
+ law "|surrogate code point| is
113
+ definition : for all (x :: CodePointText) => x = x end for all end definition
114
+ example "|surrogate| :
115
115
  x = codePoints([55296, 128512])
116
116
  expect x = codePoints([55296, 128512])
117
- end
118
- end
117
+ end example
118
+ end law
119
119
 
120
- law `explicit float rounding` is
121
- definition is `for all` (x :: Unit) . x = x end
122
- example `IEEE halfway cases` is
120
+ law "|explicit float rounding| is
121
+ definition : for all (x :: Unit) => x = x end for all end definition
122
+ example "|IEEE halfway cases| :
123
123
  x = unitValue
124
124
  expect prelude.Complex128 complex64(1, 2) = complex128(1, 2)
125
125
  expect prelude.Complex64 complex128(1.25, -2.5) = complex64(1.25, -2.5)
@@ -129,10 +129,11 @@ law `explicit float rounding` is
129
129
  expect prelude.Float64 rational(1606938044258990453947923680586147734807949174969684883144705, 1606938044258990275541962092341162602522202993782792835301376) = float64Bits("3ff0000000000001")
130
130
  expect prelude.Float32 rational(1, 1427247692705959881058285969449495136382746624) = float32Bits("00000000")
131
131
  expect prelude.Float32 rational(1125899906842625, 1606938044258990275541962092341162602522202993782792835301376) = float32Bits("00000001")
132
- end
133
- end
132
+ end example
133
+ end law
134
134
 
135
- law `short circuit exact failures` is
136
- definition is `for all` (x :: Unit) . false implies 1 / 0 = rational(1, 2) end
137
- example `guard prevents division` is x = unitValue expect x = unitValue end
138
- end
135
+ law "|short circuit exact failures| is
136
+ definition : for all (x :: Unit) => false implies 1 / 0 = rational(1, 2) end for all end definition
137
+ example "|guard prevents division| : x = unitValue expect x = unitValue end example
138
+ end law
139
+ end unit
@@ -6,13 +6,14 @@ unit example.sequencing
6
6
  -- pause notes when it is called (when the suite asks it to) and gives true.
7
7
  pause :: Int32 -> Bool
8
8
 
9
- law `the first pause ends` is definition is pause 1 = true end end
10
- law `the second pause ends` is definition is pause 2 = true end end
11
- law `the third pause ends` is definition is pause 3 = true end end
12
- law `the fourth pause ends` is definition is pause 4 = true end end
13
- law `the fifth pause ends` is definition is pause 5 = true end end
14
- law `the sixth pause ends` is definition is pause 6 = true end end
9
+ law "|the first pause ends| is definition : pause 1 = true end definition end law
10
+ law "|the second pause ends| is definition : pause 2 = true end definition end law
11
+ law "|the third pause ends| is definition : pause 3 = true end definition end law
12
+ law "|the fourth pause ends| is definition : pause 4 = true end definition end law
13
+ law "|the fifth pause ends| is definition : pause 5 = true end definition end law
14
+ law "|the sixth pause ends| is definition : pause 6 = true end definition end law
15
15
 
16
16
  harness example.sequencing.testing for example.sequencing is
17
17
  order random
18
- end
18
+ end harness
19
+ end unit
@@ -5,10 +5,11 @@ unit example.overlap
5
5
  -- time: each nap sleeps, and their sleeps overlap.
6
6
  async nap :: Int32 -> Bool
7
7
 
8
- law `the first nap ends` is definition is nap 101 = true end end
9
- law `the second nap ends` is definition is nap 102 = true end end
10
- law `the third nap ends` is definition is nap 103 = true end end
8
+ law "|the first nap ends| is definition : nap 101 = true end definition end law
9
+ law "|the second nap ends| is definition : nap 102 = true end definition end law
10
+ law "|the third nap ends| is definition : nap 103 = true end definition end law
11
11
 
12
12
  harness example.overlap.testing for example.overlap is
13
13
  parallel
14
- end
14
+ end harness
15
+ end unit
@@ -4,83 +4,84 @@ unit example.sequences
4
4
  -- index. Bytes give their octets, and Text its UTF-8 encoding.
5
5
 
6
6
  -- A record key's hash: FNV-1a over the key's octets, in 32 bits.
7
- definition fnv (octets :: List UInt8) (hash :: UInt32) :: UInt32 is
8
- match octets with
9
- | Nil -> hash
10
- | Cons o rest -> fnv rest (prelude.wrapping ((xorByte hash o) * 16777619))
11
- end
12
- end
7
+ function fnv (octets :: List UInt8) (hash :: UInt32) -> UInt32 is
8
+ first matching case of octets :
9
+ when Nil then hash
10
+ when Cons o rest then fnv rest (prelude.wrapping ((xorByte hash o) * 16777619))
11
+ end case
12
+ end function
13
13
 
14
14
  -- hash xor o, for an octet o, by its low eight bits.
15
- definition xorByte (hash :: UInt32) (o :: UInt8) :: Integer is
15
+ function xorByte (hash :: UInt32) (o :: UInt8) -> Integer is
16
16
  let low = prelude.rem hash 256 in
17
- hash - low + xorBits low o 128
18
- end
17
+ hash - low + xorBits low o 128 end let
18
+ end function
19
19
 
20
- definition xorBits (a :: Integer) (b :: Integer) (bit :: Integer) :: Integer is
20
+ function xorBits (a :: Integer) (b :: Integer) (bit :: Integer) -> Integer is
21
21
  if bit <= 0 || a < 0 || b < 0 then 0 else
22
- (if prelude.quot a bit != prelude.quot b bit then bit else 0)
23
- + xorBits (prelude.rem a bit) (prelude.rem b bit) (prelude.quot bit 2)
24
- end
22
+ (if prelude.quot a bit != prelude.quot b bit then bit else 0 end if)
23
+ + xorBits (prelude.rem a bit) (prelude.rem b bit) (prelude.quot bit 2) end if
24
+ end function
25
25
 
26
- definition keyHash (key :: Bytes) :: UInt32 is fnv (prelude.octets key) 2166136261 end
26
+ function keyHash (key :: Bytes) -> UInt32 is fnv (prelude.octets key) 2166136261 end function
27
27
 
28
- definition partitionFor (key :: Bytes) (n :: Int32) :: Int32 is
29
- if n >= 1 then prelude.Int32 (prelude.rem (keyHash key) n) else 0
30
- end
28
+ function partitionFor (key :: Bytes) (n :: Int32) -> Int32 is
29
+ if n >= 1 then prelude.Int32 (prelude.rem (keyHash key) n) else 0 end if
30
+ end function
31
31
 
32
- law `a key's partition exists` is
33
- definition is
34
- `for all` (key :: Bytes) (n :: Int32 where n >= 1 && n <= 64) .
35
- (partitionFor key n >= 0 && partitionFor key n < n) = true
36
- end
37
- end
32
+ law "|a key's partition exists| is
33
+ definition :
34
+ for all (key :: Bytes) (n :: Int32 where n >= 1 && n <= 64) =>
35
+ (partitionFor key n >= 0 && partitionFor key n < n) = true end for all
36
+ end definition
37
+ end law
38
38
 
39
- law `the hash follows FNV-1a` is
40
- definition is keyHash (prelude.utf8 "a") = 3826002220 and keyHash (prelude.utf8 "") = 2166136261 end
41
- end
39
+ law "|the hash follows FNV-1a| is
40
+ definition : keyHash (prelude.utf8 "a") = 3826002220 and keyHash (prelude.utf8 "") = 2166136261 end definition
41
+ end law
42
42
 
43
43
  -- Member ids, made by the coordinator from a client id and a counter.
44
- definition memberId (client :: Text) (n :: Int32) :: Text is client ++ "-" ++ prelude.textOf n end
44
+ function memberId (client :: Text) (n :: Int32) -> Text is client ++ "-" ++ prelude.textOf n end function
45
45
 
46
- law `a member id starts with its client` is
47
- definition is
48
- `for all` (client :: Text) (n :: Int32) . memberId client n starts with client
49
- end
50
- example `the third` is
46
+ law "|a member id starts with its client| is
47
+ definition :
48
+ for all (client :: Text) (n :: Int32) => memberId client n starts with client end for all
49
+ end definition
50
+ example "|the third| :
51
51
  client = "consumer"
52
52
  n = 3
53
53
  expect memberId client n = "consumer-3"
54
- end
55
- end
56
-
57
- law `joining text adds lengths` is
58
- definition is
59
- `for all` (a :: Text) (b :: Text) . prelude.length (a ++ b) = prelude.length a + prelude.length b
60
- end
61
- end
62
-
63
- law `octets and bytes round trip` is
64
- definition is `for all` (b :: Bytes) . prelude.bytesOf (prelude.octets b) = b end
65
- end
66
-
67
- law `a slice is a part` is
68
- definition is
69
- `for all` (xs :: List Int32) (k :: Int32 where k >= 0 && k <= 10) .
70
- prelude.take k xs ++ prelude.drop k xs = xs
71
- end
72
- end
73
-
74
- law `at reads the item an index names` is
75
- definition is
76
- `for all` (x :: Int32) (xs :: List Int32) . prelude.at 0 (Cons x xs) = Just x and prelude.at (prelude.length xs + 1) (Cons x xs) = Nothing
77
- end
78
- end
79
-
80
- law `texts join with a separator` is
81
- definition is prelude.join ", " ["a", "b", "c"] = "a, b, c" and prelude.slice 1 3 "kafka" = "af" end
82
- end
83
-
84
- law `utf8 encodes code points` is
85
- definition is prelude.utf8 "é" = prelude.bytesOf [195, 169] and prelude.length (prelude.utf8 "é") = 2 end
86
- end
54
+ end example
55
+ end law
56
+
57
+ law "|joining text adds lengths| is
58
+ definition :
59
+ for all (a :: Text) (b :: Text) => prelude.length (a ++ b) = prelude.length a + prelude.length b end for all
60
+ end definition
61
+ end law
62
+
63
+ law "|octets and bytes round trip| is
64
+ definition : for all (b :: Bytes) => prelude.bytesOf (prelude.octets b) = b end for all end definition
65
+ end law
66
+
67
+ law "|a slice is a part| is
68
+ definition :
69
+ for all (xs :: List Int32) (k :: Int32 where k >= 0 && k <= 10) =>
70
+ prelude.take k xs ++ prelude.drop k xs = xs end for all
71
+ end definition
72
+ end law
73
+
74
+ law "|at reads the item an index names| is
75
+ definition :
76
+ for all (x :: Int32) (xs :: List Int32) => prelude.at 0 (Cons x xs) = Just x and prelude.at (prelude.length xs + 1) (Cons x xs) = Nothing end for all
77
+ end definition
78
+ end law
79
+
80
+ law "|texts join with a separator| is
81
+ definition : prelude.join ", " ["a", "b", "c"] = "a, b, c" and prelude.slice 1 3 "kafka" = "af" end definition
82
+ end law
83
+
84
+ law "|utf8 encodes code points| is
85
+ definition : prelude.utf8 "é" = prelude.bytesOf [195, 169] and prelude.length (prelude.utf8 "é") = 2 end definition
86
+ end law
87
+ end unit
@@ -11,12 +11,12 @@ protocol Serve is
11
11
  receive Int32
12
12
  receive Int32
13
13
  send Int64
14
- end
14
+ end protocol
15
15
 
16
16
  -- Handing a server's end to a worker (delegation).
17
17
  protocol Hire is
18
18
  send Serve
19
- end
19
+ end protocol
20
20
 
21
21
  -- Adds through a server process. Processes that talk over channels wait for
22
22
  -- each other, so these adapters are asynchronous.
@@ -25,14 +25,15 @@ async add :: Int32 -> Int32 -> Integer
25
25
  -- Adds through a worker that is handed the server's end over a Hire channel.
26
26
  async addHired :: Int32 -> Int32 -> Integer
27
27
 
28
- law `a server adds` is
29
- definition is
30
- `for all` (a :: Int32) (b :: Int32) . add a b = prelude.Integer a + prelude.Integer b
31
- end
32
- end
28
+ law "|a server adds| is
29
+ definition :
30
+ for all (a :: Int32) (b :: Int32) => add a b = prelude.Integer a + prelude.Integer b end for all
31
+ end definition
32
+ end law
33
33
 
34
- law `a hired worker adds` is
35
- definition is
36
- `for all` (a :: Int32) (b :: Int32) . addHired a b = prelude.Integer a + prelude.Integer b
37
- end
38
- end
34
+ law "|a hired worker adds| is
35
+ definition :
36
+ for all (a :: Int32) (b :: Int32) => addHired a b = prelude.Integer a + prelude.Integer b end for all
37
+ end definition
38
+ end law
39
+ end unit
@@ -3,31 +3,32 @@ unit example.slug
3
3
  normalize :: Text -> Text
4
4
  referenceNormalize :: Text -> Text
5
5
 
6
- law `normalizers agree` is
7
- definition is
8
- `equivalent` normalize referenceNormalize
9
- end
10
- description is
6
+ law "|normalizers agree| is
7
+ definition :
8
+ apply law "|equivalent| normalize referenceNormalize
9
+ end definition
10
+ description :
11
11
  "{normalize} and {referenceNormalize} replace ASCII spaces with hyphens"
12
- end
13
- example `spaces become hyphens; punctuation is preserved` is
12
+ end description
13
+ example "|spaces become hyphens; punctuation is preserved| :
14
14
  x = "Hello, World!"
15
15
  expect normalize x = "Hello,-World!"
16
16
  expect referenceNormalize x = "Hello,-World!"
17
- end
18
- example `empty text remains empty` is
17
+ end example
18
+ example "|empty text remains empty| :
19
19
  x = ""
20
20
  expect normalize x = ""
21
21
  expect referenceNormalize x = ""
22
- end
23
- example `Unicode is preserved while spaces become hyphens` is
22
+ end example
23
+ example "|Unicode is preserved while spaces become hyphens| :
24
24
  x = "café 日本語 😀"
25
25
  expect normalize x = "café-日本語-😀"
26
26
  expect referenceNormalize x = "café-日本語-😀"
27
- end
28
- example `quotes, backslashes and controls survive space replacement` is
27
+ end example
28
+ example "|quotes, backslashes and controls survive space replacement| :
29
29
  x = "quote: \" slash: \\ newline: \n tab: \t dollar: $"
30
30
  expect normalize x = "quote:-\"-slash:-\\-newline:-\n-tab:-\t-dollar:-$"
31
31
  expect referenceNormalize x = "quote:-\"-slash:-\\-newline:-\n-tab:-\t-dollar:-$"
32
- end
33
- end
32
+ end example
33
+ end law
34
+ end unit
@@ -1,49 +1,50 @@
1
1
  unit example.sum_refinements
2
2
 
3
- law `positive Maybe payloads` is
4
- definition is `for all` (x :: Maybe (value :: Int8 where value > 0)) .
5
- (match x with | Nothing -> true | Just payload -> payload >= 1 end) = true
6
- end
7
- example `absent` is x = Nothing expect x = Nothing end
8
- example `present` is x = Just 1 expect x = Just 1 end
9
- end
3
+ law "|positive Maybe payloads| is
4
+ definition : for all (x :: Maybe (value :: Int8 where value > 0)) =>
5
+ (first matching case of x : when Nothing then true when Just payload then payload >= 1 end case) = true end for all
6
+ end definition
7
+ example "|absent| : x = Nothing expect x = Nothing end example
8
+ example "|present| : x = Just 1 expect x = Just 1 end example
9
+ end law
10
10
 
11
- law `selected Either payload` is
12
- definition is `for all`
13
- (x :: Either (value :: Int8 where value > 0) (value :: Int8 where value < 0)) .
14
- (match x with | Left payload -> payload >= 1 | Right payload -> payload <= -1 end) = true
15
- end
16
- example `left` is x = Left 1 expect x = Left 1 end
17
- example `right` is x = Right -1 expect x = Right -1 end
18
- end
11
+ law "|selected Either payload| is
12
+ definition : for all
13
+ (x :: Either (value :: Int8 where value > 0) (value :: Int8 where value < 0)) =>
14
+ (first matching case of x : when Left payload then payload >= 1 when Right payload then payload <= -1 end case) = true end for all
15
+ end definition
16
+ example "|left| : x = Left 1 expect x = Left 1 end example
17
+ example "|right| : x = Right -1 expect x = Right -1 end example
18
+ end law
19
19
 
20
- law `nested Maybe states` is
21
- definition is `for all` (x :: Maybe (Maybe (value :: Bool where value))) .
22
- (match x with | Nothing -> true | Just inner ->
23
- match inner with | Nothing -> true | Just payload -> payload end
24
- end) = true
25
- end
26
- example `outer absent` is x = Nothing expect x = Nothing end
27
- example `inner absent` is x = Just Nothing expect x = Just Nothing end
28
- example `present` is x = Just (Just true) expect x = Just (Just true) end
29
- end
20
+ law "|nested Maybe states| is
21
+ definition : for all (x :: Maybe (Maybe (value :: Bool where value))) =>
22
+ (first matching case of x : when Nothing then true when Just inner then
23
+ first matching case of inner : when Nothing then true when Just payload then payload end case
24
+ end case) = true end for all
25
+ end definition
26
+ example "|outer absent| : x = Nothing expect x = Nothing end example
27
+ example "|inner absent| : x = Just Nothing expect x = Just Nothing end example
28
+ example "|present| : x = Just (Just true) expect x = Just (Just true) end example
29
+ end law
30
30
 
31
- law `finite Either variants` is
32
- definition is `for all`
33
- (x :: Either (value :: Bool where value) (value :: Bool where !value)) .
34
- (match x with | Left payload -> payload | Right payload -> !payload end) = true
35
- end
36
- end
31
+ law "|finite Either variants| is
32
+ definition : for all
33
+ (x :: Either (value :: Bool where value) (value :: Bool where !value)) =>
34
+ (first matching case of x : when Left payload then payload when Right payload then !payload end case) = true end for all
35
+ end definition
36
+ end law
37
37
 
38
- law `dependent payload keeps outer binding` is
39
- definition is `for all` (lawspecElement :: Int8)
40
- (x :: Maybe (value :: Int8 where value > lawspecElement)) .
41
- (match x with | Nothing -> true | Just payload -> payload - lawspecElement >= 1 end) = true
42
- end
43
- example `maximum prefix has absent continuation` is
38
+ law "|dependent payload keeps outer binding| is
39
+ definition : for all (lawspecElement :: Int8)
40
+ (x :: Maybe (value :: Int8 where value > lawspecElement)) =>
41
+ (first matching case of x : when Nothing then true when Just payload then payload - lawspecElement >= 1 end case) = true end for all
42
+ end definition
43
+ example "|maximum prefix has absent continuation| :
44
44
  lawspecElement = 127 x = Nothing expect x = Nothing
45
- end
46
- example `present continuation` is
45
+ end example
46
+ example "|present continuation| :
47
47
  lawspecElement = 0 x = Just 1 expect x = Just 1
48
- end
49
- end
48
+ end example
49
+ end law
50
+ end unit