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
|
@@ -1,125 +1,125 @@
|
|
|
1
1
|
unit example.scalars
|
|
2
2
|
|
|
3
|
-
law
|
|
4
|
-
definition
|
|
5
|
-
example
|
|
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
|
|
12
|
-
definition
|
|
13
|
-
example
|
|
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
|
|
20
|
-
definition
|
|
21
|
-
example
|
|
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
|
|
28
|
-
definition
|
|
29
|
-
example
|
|
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
|
|
39
|
-
definition
|
|
40
|
-
example
|
|
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
|
|
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
|
|
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
|
|
57
|
-
definition
|
|
58
|
-
example
|
|
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
|
|
65
|
-
definition
|
|
66
|
-
example
|
|
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
|
|
73
|
-
definition
|
|
74
|
-
example
|
|
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
|
|
81
|
-
definition
|
|
82
|
-
example
|
|
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
|
|
89
|
-
definition
|
|
90
|
-
example
|
|
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
|
|
93
|
+
end example
|
|
94
|
+
example "|present null| :
|
|
95
95
|
x = optional(null)
|
|
96
96
|
expect x = optional(null)
|
|
97
|
-
end
|
|
98
|
-
example
|
|
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
|
|
105
|
-
definition
|
|
106
|
-
example
|
|
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
|
|
113
|
-
definition
|
|
114
|
-
example
|
|
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
|
|
121
|
-
definition
|
|
122
|
-
example
|
|
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
|
|
136
|
-
definition
|
|
137
|
-
example
|
|
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
|
|
10
|
-
law
|
|
11
|
-
law
|
|
12
|
-
law
|
|
13
|
-
law
|
|
14
|
-
law
|
|
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
|
|
9
|
-
law
|
|
10
|
-
law
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
function keyHash (key :: Bytes) -> UInt32 is fnv (prelude.octets key) 2166136261 end function
|
|
27
27
|
|
|
28
|
-
|
|
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
|
|
33
|
-
definition
|
|
34
|
-
|
|
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
|
|
40
|
-
definition
|
|
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
|
-
|
|
44
|
+
function memberId (client :: Text) (n :: Int32) -> Text is client ++ "-" ++ prelude.textOf n end function
|
|
45
45
|
|
|
46
|
-
law
|
|
47
|
-
definition
|
|
48
|
-
|
|
49
|
-
end
|
|
50
|
-
example
|
|
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
|
|
58
|
-
definition
|
|
59
|
-
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
law
|
|
64
|
-
definition
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
law
|
|
68
|
-
definition
|
|
69
|
-
|
|
70
|
-
prelude.take k xs ++ prelude.drop k xs = xs
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
law
|
|
75
|
-
definition
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
law
|
|
81
|
-
definition
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
law
|
|
85
|
-
definition
|
|
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
|
|
29
|
-
definition
|
|
30
|
-
|
|
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
|
|
35
|
-
definition
|
|
36
|
-
|
|
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
|
|
7
|
-
definition
|
|
8
|
-
|
|
9
|
-
end
|
|
10
|
-
description
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
4
|
-
definition
|
|
5
|
-
(
|
|
6
|
-
end
|
|
7
|
-
example
|
|
8
|
-
example
|
|
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
|
|
12
|
-
definition
|
|
13
|
-
(x :: Either (value :: Int8 where value > 0) (value :: Int8 where value < 0))
|
|
14
|
-
(
|
|
15
|
-
end
|
|
16
|
-
example
|
|
17
|
-
example
|
|
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
|
|
21
|
-
definition
|
|
22
|
-
(
|
|
23
|
-
|
|
24
|
-
end) = true
|
|
25
|
-
end
|
|
26
|
-
example
|
|
27
|
-
example
|
|
28
|
-
example
|
|
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
|
|
32
|
-
definition
|
|
33
|
-
(x :: Either (value :: Bool where value) (value :: Bool where !value))
|
|
34
|
-
(
|
|
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
|
|
39
|
-
definition
|
|
40
|
-
(x :: Maybe (value :: Int8 where value > lawspecElement))
|
|
41
|
-
(
|
|
42
|
-
end
|
|
43
|
-
example
|
|
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
|
|
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
|