lawspec 0.25.0 → 0.27.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 +109 -1
- package/NORMALIZATION-LICENSES.txt +296 -0
- package/README.md +13 -4
- package/api.mjs +0 -8
- package/bin/lawspec.mjs +114 -79
- package/build.json +99 -117
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/doctor.mjs +14 -4
- 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/prolog/lawspec.json +20 -0
- package/examples/native-payments/prolog/src/domain/payments.pl +23 -0
- package/examples/native-payments/prolog/tests/domain/payment_generators.pl +17 -0
- 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 +19 -18
- 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 +68 -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 +7 -6
- 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 +161 -160
- 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 +7 -7
- package/explain.mjs +6 -4
- package/expression-presentation.mjs +8 -8
- package/files.mjs +1 -1
- package/index.d.ts +10 -528
- package/launcher.mjs +9 -2
- package/lsp.mjs +10 -6
- package/native-evidence.mjs +25 -12
- package/native-examples.mjs +3 -3
- package/package.json +2 -1
- package/starter-rc1.lawspec +6 -5
- package/starter.lawspec +16 -15
- package/templates.mjs +88 -5
- package/test-command.mjs +40 -4
- 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
|
@@ -7,169 +7,170 @@ unit example.generation
|
|
|
7
7
|
generated :: Text -> UInt64 -> Int32 -> Int32 -> List Text
|
|
8
8
|
shrunk :: Text -> UInt64 -> Int32 -> List Text
|
|
9
9
|
|
|
10
|
-
law
|
|
11
|
-
definition
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
example
|
|
10
|
+
law "|int8| is
|
|
11
|
+
definition :
|
|
12
|
+
for all (seed :: UInt64) => prelude.length (generated "(int Int8 -128 127)" seed 4 5) = 5 end for all
|
|
13
|
+
end definition
|
|
14
|
+
example "|seed 42| :
|
|
15
15
|
seed = 42
|
|
16
16
|
expect generated "(int Int8 -128 127)" seed 4 5 = ["-125", "20", "0", "36", "46"]
|
|
17
17
|
expect shrunk "(int Int8 -128 127)" seed 4 = ["0", "-63", "-124"]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
law
|
|
22
|
-
definition
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
example
|
|
18
|
+
end example
|
|
19
|
+
end law
|
|
20
|
+
|
|
21
|
+
law "|unbounded integers| is
|
|
22
|
+
definition :
|
|
23
|
+
for all (seed :: UInt64) => prelude.length (generated "(int Integer _ _)" seed 4 4) = 4 end for all
|
|
24
|
+
end definition
|
|
25
|
+
example "|seed 7| :
|
|
26
26
|
seed = 7
|
|
27
27
|
expect generated "(int Integer _ _)" seed 4 4 = ["-653071", "196343", "-29128", "80327"]
|
|
28
28
|
expect shrunk "(int Integer _ _)" seed 4 = ["0", "-326536", "-653070"]
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
law
|
|
33
|
-
definition
|
|
34
|
-
|
|
35
|
-
end
|
|
36
|
-
example
|
|
29
|
+
end example
|
|
30
|
+
end law
|
|
31
|
+
|
|
32
|
+
law "|a lower bound| is
|
|
33
|
+
definition :
|
|
34
|
+
for all (seed :: UInt64) => prelude.length (generated "(int Int32 5 _)" seed 4 4) = 4 end for all
|
|
35
|
+
end definition
|
|
36
|
+
example "|seed 7| :
|
|
37
37
|
seed = 7
|
|
38
38
|
expect generated "(int Int32 5 _)" seed 4 4 = ["346934", "1196348", "970877", "1080332"]
|
|
39
39
|
expect shrunk "(int Int32 5 _)" seed 4 = ["5", "173470", "346933"]
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
law
|
|
44
|
-
definition
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
example
|
|
40
|
+
end example
|
|
41
|
+
end law
|
|
42
|
+
|
|
43
|
+
law "|the full UInt64 range| is
|
|
44
|
+
definition :
|
|
45
|
+
for all (seed :: UInt64) => prelude.length (generated "(int UInt64 0 18446744073709551615)" seed 4 3) = 3 end for all
|
|
46
|
+
end definition
|
|
47
|
+
example "|seed 1| :
|
|
48
48
|
seed = 1
|
|
49
49
|
expect generated "(int UInt64 0 18446744073709551615)" seed 4 3 = ["13757245211066428519", "1", "0"]
|
|
50
50
|
expect shrunk "(int UInt64 0 18446744073709551615)" seed 4 = ["0", "6878622605533214260", "13757245211066428518"]
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
law
|
|
55
|
-
definition
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
example
|
|
51
|
+
end example
|
|
52
|
+
end law
|
|
53
|
+
|
|
54
|
+
law "|booleans| is
|
|
55
|
+
definition :
|
|
56
|
+
for all (seed :: UInt64) => prelude.length (generated "(bool)" seed 4 6) = 6 end for all
|
|
57
|
+
end definition
|
|
58
|
+
example "|seed 3| :
|
|
59
59
|
seed = 3
|
|
60
60
|
expect generated "(bool)" seed 4 6 = ["true", "true", "true", "true", "false", "true"]
|
|
61
61
|
expect shrunk "(bool)" seed 4 = ["false"]
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
law
|
|
66
|
-
definition
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
example
|
|
62
|
+
end example
|
|
63
|
+
end law
|
|
64
|
+
|
|
65
|
+
law "|text| is
|
|
66
|
+
definition :
|
|
67
|
+
for all (seed :: UInt64) => prelude.length (generated "(text)" seed 6 3) = 3 end for all
|
|
68
|
+
end definition
|
|
69
|
+
example "|seed 9| :
|
|
70
70
|
seed = 9
|
|
71
71
|
expect generated "(text)" seed 6 3 = ["\"I(\"", "\"\"", "\"4<*6F\""]
|
|
72
72
|
expect shrunk "(text)" seed 6 = ["\"\"", "\"I\"", "\"(\""]
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
law
|
|
77
|
-
definition
|
|
78
|
-
|
|
79
|
-
end
|
|
80
|
-
example
|
|
73
|
+
end example
|
|
74
|
+
end law
|
|
75
|
+
|
|
76
|
+
law "|unit| is
|
|
77
|
+
definition :
|
|
78
|
+
for all (seed :: UInt64) => prelude.length (generated "(unit)" seed 1 2) = 2 end for all
|
|
79
|
+
end definition
|
|
80
|
+
example "|seed 1| :
|
|
81
81
|
seed = 1
|
|
82
82
|
expect generated "(unit)" seed 1 2 = ["()", "()"]
|
|
83
83
|
expect shrunk "(unit)" seed 1 = []
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
law
|
|
88
|
-
definition
|
|
89
|
-
|
|
90
|
-
end
|
|
91
|
-
example
|
|
84
|
+
end example
|
|
85
|
+
end law
|
|
86
|
+
|
|
87
|
+
law "|lists| is
|
|
88
|
+
definition :
|
|
89
|
+
for all (seed :: UInt64) => prelude.length (generated "(list (int Int32 0 _))" seed 4 3) = 3 end for all
|
|
90
|
+
end definition
|
|
91
|
+
example "|seed 42| :
|
|
92
92
|
seed = 42
|
|
93
93
|
expect generated "(list (int Int32 0 _))" seed 4 3 = ["[0, 1745563, 275752]", "[1325093, 742426, 493279]", "[2000000]"]
|
|
94
94
|
expect shrunk "(list (int Int32 0 _))" seed 4 = ["[]", "[0]", "[1745563, 275752]", "[0, 275752]", "[0, 1745563]", "[0, 0, 275752]", "[0, 872782, 275752]", "[0, 1745562, 275752]", "[0, 1745563, 0]", "[0, 1745563, 137876]", "[0, 1745563, 275751]"]
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
law
|
|
99
|
-
definition
|
|
100
|
-
|
|
101
|
-
end
|
|
102
|
-
example
|
|
95
|
+
end example
|
|
96
|
+
end law
|
|
97
|
+
|
|
98
|
+
law "|maybe| is
|
|
99
|
+
definition :
|
|
100
|
+
for all (seed :: UInt64) => prelude.length (generated "(maybe (bool))" seed 4 4) = 4 end for all
|
|
101
|
+
end definition
|
|
102
|
+
example "|seed 5| :
|
|
103
103
|
seed = 5
|
|
104
104
|
expect generated "(maybe (bool))" seed 4 4 = ["Just(false)", "Just(true)", "Just(false)", "Just(true)"]
|
|
105
105
|
expect shrunk "(maybe (bool))" seed 4 = ["Nothing"]
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
law
|
|
110
|
-
definition
|
|
111
|
-
|
|
112
|
-
end
|
|
113
|
-
example
|
|
106
|
+
end example
|
|
107
|
+
end law
|
|
108
|
+
|
|
109
|
+
law "|either| is
|
|
110
|
+
definition :
|
|
111
|
+
for all (seed :: UInt64) => prelude.length (generated "(either (text) (int Int8 -128 127))" seed 4 4) = 4 end for all
|
|
112
|
+
end definition
|
|
113
|
+
example "|seed 11| :
|
|
114
114
|
seed = 11
|
|
115
115
|
expect generated "(either (text) (int Int8 -128 127))" seed 4 4 = ["Right(-19)", "Left(\"\\\"{U\")", "Left(\"j\")", "Right(1)"]
|
|
116
116
|
expect shrunk "(either (text) (int Int8 -128 127))" seed 4 = ["Right(0)", "Right(-10)", "Right(-18)"]
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
law
|
|
121
|
-
definition
|
|
122
|
-
|
|
123
|
-
end
|
|
124
|
-
example
|
|
117
|
+
end example
|
|
118
|
+
end law
|
|
119
|
+
|
|
120
|
+
law "|a recursive tree| is
|
|
121
|
+
definition :
|
|
122
|
+
for all (seed :: UInt64) => prelude.length (generated "(data Tree (ctor t::type::Tree::Leaf) (ctor t::type::Tree::Node (ref Tree) (int Int8 -128 127) (ref Tree))) (ref Tree)" seed 3 2) = 2 end for all
|
|
123
|
+
end definition
|
|
124
|
+
example "|seed 13| :
|
|
125
125
|
seed = 13
|
|
126
126
|
expect generated "(data Tree (ctor t::type::Tree::Leaf) (ctor t::type::Tree::Node (ref Tree) (int Int8 -128 127) (ref Tree))) (ref Tree)" seed 3 2 = ["Node(Node(Leaf, -29, Leaf), -44, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Leaf"]
|
|
127
127
|
expect shrunk "(data Tree (ctor t::type::Tree::Leaf) (ctor t::type::Tree::Node (ref Tree) (int Int8 -128 127) (ref Tree))) (ref Tree)" seed 3 = ["Leaf", "Node(Leaf, -29, Leaf)", "Node(Node(Leaf, -110, Leaf), 58, Leaf)", "Node(Leaf, -44, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Node(Node(Leaf, 0, Leaf), -44, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Node(Node(Leaf, -15, Leaf), -44, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Node(Node(Leaf, -28, Leaf), -44, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Node(Node(Leaf, -29, Leaf), 0, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Node(Node(Leaf, -29, Leaf), -22, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Node(Node(Leaf, -29, Leaf), -43, Node(Node(Leaf, -110, Leaf), 58, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Leaf)", "Node(Node(Leaf, -29, Leaf), -44, Node(Leaf, -110, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Node(Leaf, 58, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Node(Node(Leaf, 0, Leaf), 58, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Node(Node(Leaf, -55, Leaf), 58, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Node(Node(Leaf, -109, Leaf), 58, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Node(Node(Leaf, -110, Leaf), 0, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Node(Node(Leaf, -110, Leaf), 29, Leaf))", "Node(Node(Leaf, -29, Leaf), -44, Node(Node(Leaf, -110, Leaf), 57, Leaf))"]
|
|
128
|
-
end
|
|
129
|
-
end
|
|
128
|
+
end example
|
|
129
|
+
end law
|
|
130
130
|
|
|
131
131
|
-- A refinement's bounds narrow generation: an amount from 1 to 1000 is
|
|
132
132
|
-- drawn from that range, not filtered out of every Int32, alongside a value
|
|
133
133
|
-- of a data type.
|
|
134
|
-
type Purse is
|
|
134
|
+
type Purse is a record{ coins :: Int64} end type
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
function spend (p :: Purse) (amount :: Int32 where amount >= 1 && amount <= 1000) -> Int32 is amount end function
|
|
137
137
|
|
|
138
|
-
law
|
|
139
|
-
definition
|
|
140
|
-
|
|
141
|
-
end
|
|
142
|
-
end
|
|
138
|
+
law "|refined amounts are drawn from their range| is
|
|
139
|
+
definition :
|
|
140
|
+
for all (p :: Purse) (amount :: Int32 where amount >= 1 && amount <= 1000) => spend p amount >= 1 end for all
|
|
141
|
+
end definition
|
|
142
|
+
end law
|
|
143
143
|
|
|
144
144
|
-- if c then a else b evaluates only the branch c selects, and each branch is
|
|
145
145
|
-- checked knowing which way c went: the division is safe because n > 0.
|
|
146
|
-
|
|
147
|
-
if n > 0 then prelude.quot total n else 0
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
law
|
|
151
|
-
definition
|
|
152
|
-
|
|
153
|
-
end
|
|
154
|
-
example
|
|
146
|
+
function share (total :: Int32 where total >= 0 && total <= 1000) (n :: Int32 where n >= 0 && n <= 10) -> Int32 is
|
|
147
|
+
if n > 0 then prelude.quot total n else 0 end if
|
|
148
|
+
end function
|
|
149
|
+
|
|
150
|
+
law "|a share is at most the total| is
|
|
151
|
+
definition :
|
|
152
|
+
for all (t :: Int32 where t >= 0 && t <= 1000) (n :: Int32 where n >= 0 && n <= 10) => share t n <= t end for all
|
|
153
|
+
end definition
|
|
154
|
+
example "|nobody to share with| :
|
|
155
155
|
t = 7
|
|
156
156
|
n = 0
|
|
157
157
|
expect share t n = 0
|
|
158
|
-
end
|
|
159
|
-
example
|
|
158
|
+
end example
|
|
159
|
+
example "|three people| :
|
|
160
160
|
t = 7
|
|
161
161
|
n = 3
|
|
162
162
|
expect share t n = 2
|
|
163
|
-
end
|
|
164
|
-
end
|
|
163
|
+
end example
|
|
164
|
+
end law
|
|
165
165
|
|
|
166
166
|
-- A text refined to be non-empty is drawn from its refinement, at every
|
|
167
167
|
-- size: four of them, one also unlike another, are met at the first case,
|
|
168
168
|
-- not filtered out of draws that are mostly empty while the size is small.
|
|
169
|
-
law
|
|
170
|
-
definition
|
|
171
|
-
|
|
172
|
-
(d :: Text where d != "" && d != c)
|
|
173
|
-
prelude.length a + prelude.length b + prelude.length c + prelude.length d >= 4
|
|
174
|
-
end
|
|
175
|
-
end
|
|
169
|
+
law "|several non-empty texts are drawn| is
|
|
170
|
+
definition :
|
|
171
|
+
for all (a :: Text where a != "") (b :: Text where b != "") (c :: Text where c != "")
|
|
172
|
+
(d :: Text where d != "" && d != c) =>
|
|
173
|
+
prelude.length a + prelude.length b + prelude.length c + prelude.length d >= 4 end for all
|
|
174
|
+
end definition
|
|
175
|
+
end law
|
|
176
|
+
end unit
|
|
@@ -4,62 +4,64 @@ unit example.till
|
|
|
4
4
|
-- lawspec.json under handlers. Money is bound to a native type there too, so
|
|
5
5
|
-- the handler's operations take and give that type.
|
|
6
6
|
|
|
7
|
-
type Money is
|
|
8
|
-
type PayError is | Declined | Rejected message :: Text end
|
|
7
|
+
type Money is a record{ cents :: Int64} end type
|
|
8
|
+
type PayError is one of | Declined | Rejected of type record{ message :: Text} end type
|
|
9
9
|
|
|
10
10
|
-- A till's drawer. Every handler of it gives back what it takes.
|
|
11
11
|
ability Drawer is
|
|
12
12
|
take :: Money -> Money
|
|
13
13
|
opening :: Money
|
|
14
14
|
laws
|
|
15
|
-
law
|
|
16
|
-
definition
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
15
|
+
law "|a till gives back what it takes| is
|
|
16
|
+
definition :
|
|
17
|
+
for all (cents :: Int64 where cents >= 0 && cents <= 1000) => take (Money record{ cents = cents}) = Money record{ cents = cents} end for all
|
|
18
|
+
end definition
|
|
19
|
+
end law
|
|
20
|
+
end laws
|
|
21
|
+
end ability
|
|
21
22
|
|
|
22
23
|
handler fakeDrawer for Drawer is
|
|
23
|
-
take money is money end
|
|
24
|
-
opening is Money 0 end
|
|
25
|
-
end
|
|
24
|
+
operation take money is money end operation
|
|
25
|
+
operation opening is Money record{ cents = 0} end operation
|
|
26
|
+
end handler
|
|
26
27
|
|
|
27
28
|
-- A native adapter that fails. Its native code raises the application's own
|
|
28
29
|
-- exceptions; lawspec.json maps them to PayError's constructors.
|
|
29
30
|
pay :: Int64 -> Money uses Drawer fails with PayError
|
|
30
31
|
|
|
31
|
-
law
|
|
32
|
-
definition
|
|
33
|
-
|
|
34
|
-
prelude.attempt (pay cents) = Right (Money cents)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
32
|
+
law "|small payments go through| is
|
|
33
|
+
definition :
|
|
34
|
+
for all (cents :: Int64 where cents >= 0 && cents <= 1000) =>
|
|
35
|
+
prelude.attempt (pay cents) = Right (Money record{ cents = cents}) end for all
|
|
36
|
+
end definition
|
|
37
|
+
end law
|
|
37
38
|
|
|
38
|
-
law
|
|
39
|
-
definition
|
|
40
|
-
|
|
41
|
-
prelude.attempt (pay cents) = Left Declined
|
|
42
|
-
end
|
|
43
|
-
end
|
|
39
|
+
law "|large payments are declined| is
|
|
40
|
+
definition :
|
|
41
|
+
for all (cents :: Int64 where cents > 1000 && cents <= 100000) =>
|
|
42
|
+
prelude.attempt (pay cents) = Left Declined end for all
|
|
43
|
+
end definition
|
|
44
|
+
end law
|
|
44
45
|
|
|
45
|
-
law
|
|
46
|
-
definition
|
|
47
|
-
|
|
48
|
-
prelude.attempt (pay cents) = Left (Rejected "negative")
|
|
49
|
-
end
|
|
50
|
-
end
|
|
46
|
+
law "|negative payments are rejected| is
|
|
47
|
+
definition :
|
|
48
|
+
for all (cents :: Int64 where cents >= -1000 && cents < 0) =>
|
|
49
|
+
prelude.attempt (pay cents) = Left (Rejected record{ message = "negative"}) end for all
|
|
50
|
+
end definition
|
|
51
|
+
end law
|
|
51
52
|
|
|
52
53
|
-- The same failures, as a law expects them: `fails with` matches the
|
|
53
54
|
-- constructor a mapped exception became, and its message.
|
|
54
|
-
law
|
|
55
|
-
definition
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
end
|
|
55
|
+
law "|large payments fail as declined| is
|
|
56
|
+
definition :
|
|
57
|
+
for all (cents :: Int64 where cents > 1000 && cents <= 100000) => pay cents fails with Declined end for all
|
|
58
|
+
end definition
|
|
59
|
+
end law
|
|
59
60
|
|
|
60
|
-
law
|
|
61
|
-
definition
|
|
62
|
-
|
|
63
|
-
pay cents fails with Rejected _ message contains "negative"
|
|
64
|
-
end
|
|
65
|
-
end
|
|
61
|
+
law "|negative payments say why they are rejected| is
|
|
62
|
+
definition :
|
|
63
|
+
for all (cents :: Int64 where cents >= -1000 && cents < 0) =>
|
|
64
|
+
pay cents fails with Rejected record{ message = _} message contains "negative" end for all
|
|
65
|
+
end definition
|
|
66
|
+
end law
|
|
67
|
+
end unit
|
|
@@ -5,71 +5,73 @@ unit example.harness
|
|
|
5
5
|
-- harness's business, in harness_testing.lawspec.
|
|
6
6
|
|
|
7
7
|
-- An order: how many items it has, and its total in cents.
|
|
8
|
-
type Order is
|
|
8
|
+
type Order is a record{ items :: Int32 total :: Int32} end type
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function itemsOf (order :: Order) -> Int32 is first matching case of order : when Order record{ items = items , total = total} then items end case end function
|
|
11
|
+
function totalOf (order :: Order) -> Int32 is first matching case of order : when Order record{ items = items , total = total} then total end case end function
|
|
12
|
+
function isEmpty (order :: Order) -> Bool is itemsOf order = 0 end function
|
|
13
13
|
|
|
14
14
|
-- The discount an order gets, and a price rounded to tens of cents.
|
|
15
15
|
discount :: Order -> Int32
|
|
16
16
|
roundCents :: Int32 -> Int32
|
|
17
17
|
|
|
18
|
-
law
|
|
19
|
-
definition
|
|
20
|
-
|
|
21
|
-
(discount order <= totalOf order) = true
|
|
22
|
-
end
|
|
23
|
-
end
|
|
18
|
+
law "|a discount is never more than the total| is
|
|
19
|
+
definition :
|
|
20
|
+
for all (order :: Order where itemsOf order >= 0 && totalOf order >= 0) =>
|
|
21
|
+
(discount order <= totalOf order) = true end for all
|
|
22
|
+
end definition
|
|
23
|
+
end law
|
|
24
24
|
|
|
25
|
-
law
|
|
26
|
-
definition
|
|
27
|
-
|
|
28
|
-
roundCents (roundCents cents) = roundCents cents
|
|
29
|
-
end
|
|
30
|
-
end
|
|
25
|
+
law "|rounding is idempotent| is
|
|
26
|
+
definition :
|
|
27
|
+
for all (cents :: Int32 where cents >= 0 && cents <= 1000000) =>
|
|
28
|
+
roundCents (roundCents cents) = roundCents cents end for all
|
|
29
|
+
end definition
|
|
30
|
+
end law
|
|
31
31
|
|
|
32
|
-
law
|
|
33
|
-
definition
|
|
34
|
-
|
|
35
|
-
(roundCents cents >= cents) = true
|
|
36
|
-
end
|
|
37
|
-
end
|
|
32
|
+
law "|rounding never lowers a price| is
|
|
33
|
+
definition :
|
|
34
|
+
for all (cents :: Int32 where cents >= 0 && cents <= 1000000) =>
|
|
35
|
+
(roundCents cents >= cents) = true end for all
|
|
36
|
+
end definition
|
|
37
|
+
end law
|
|
38
38
|
|
|
39
39
|
-- A ledger records payments. Every law about booking holds for every
|
|
40
40
|
-- lawful ledger; the harness chooses which ones the tests use.
|
|
41
41
|
ability Ledger is
|
|
42
42
|
accept :: Int32 -> Bool
|
|
43
43
|
laws
|
|
44
|
-
law
|
|
45
|
-
definition
|
|
46
|
-
end
|
|
47
|
-
end
|
|
44
|
+
law "|positive amounts are accepted| is
|
|
45
|
+
definition : for all (cents :: Int32 where cents > 0) => accept cents = true end for all end definition
|
|
46
|
+
end law
|
|
47
|
+
end laws
|
|
48
|
+
end ability
|
|
48
49
|
|
|
49
50
|
handler fakeLedger for Ledger is
|
|
50
|
-
accept cents is cents > 0 end
|
|
51
|
-
end
|
|
51
|
+
operation accept cents is cents > 0 end operation
|
|
52
|
+
end handler
|
|
52
53
|
|
|
53
54
|
book :: Int32 -> Bool uses Ledger
|
|
54
55
|
|
|
55
|
-
law
|
|
56
|
-
definition
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
56
|
+
law "|booking a positive amount succeeds| is
|
|
57
|
+
definition :
|
|
58
|
+
for all (cents :: Int32 where cents > 0) => book cents = true end for all
|
|
59
|
+
end definition
|
|
60
|
+
end law
|
|
60
61
|
|
|
61
|
-
law
|
|
62
|
-
definition
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
end
|
|
62
|
+
law "|a refund is never booked twice| is
|
|
63
|
+
definition :
|
|
64
|
+
for all (cents :: Int32 where cents > 0) => book cents = book cents end for all
|
|
65
|
+
end definition
|
|
66
|
+
end law
|
|
66
67
|
|
|
67
68
|
-- A scratch area the laws may use; it can be emptied between laws, and
|
|
68
69
|
-- laws running at the same time cannot interfere through it.
|
|
69
|
-
type Scratch is
|
|
70
|
+
type Scratch is a record{ used :: Int32} end type
|
|
70
71
|
|
|
71
72
|
resource Scratch is concurrent
|
|
72
|
-
acquire is Scratch 0 end
|
|
73
|
-
release scratch is unitValue end
|
|
74
|
-
reset scratch is unitValue end
|
|
75
|
-
end
|
|
73
|
+
acquire is Scratch record{ used = 0} end acquire
|
|
74
|
+
release scratch is unitValue end release
|
|
75
|
+
reset scratch is unitValue end reset
|
|
76
|
+
end resource
|
|
77
|
+
end unit
|
|
@@ -4,42 +4,47 @@
|
|
|
4
4
|
harness example.harness.testing for example.harness is
|
|
5
5
|
-- Small orders: up to three items at a dollar each.
|
|
6
6
|
strategy smallOrder :: Order is
|
|
7
|
-
bind items :: Int32 from (one of 0, 1, 2, 3) in one of Order items (items * 100)
|
|
8
|
-
end
|
|
7
|
+
bind items :: Int32 from (one of 0, 1, 2, 3) in one of Order record{ items = items , total = (items * 100)} end bind
|
|
8
|
+
end strategy
|
|
9
9
|
-- Bulk orders: the default generator, kept to large ones.
|
|
10
10
|
strategy bulkOrder :: Order is
|
|
11
11
|
any such that itemsOf it > 10 && totalOf it >= 0 at most 1000 discards
|
|
12
|
-
end
|
|
13
|
-
strategy orders :: Order is frequency 9 smallOrder, 1 bulkOrder end
|
|
12
|
+
end strategy
|
|
13
|
+
strategy orders :: Order is frequency 9 smallOrder, 1 bulkOrder end strategy
|
|
14
14
|
|
|
15
15
|
tags pricing
|
|
16
16
|
test with fakeLedger
|
|
17
17
|
order random
|
|
18
18
|
parallel
|
|
19
19
|
|
|
20
|
-
for law
|
|
20
|
+
for law "|a discount is never more than the total|
|
|
21
21
|
use orders for order
|
|
22
22
|
cover 5% "empty order" when isEmpty order
|
|
23
23
|
classify totalOf order > 1000 as "large"
|
|
24
|
-
label if isEmpty order then "empty" else "some items"
|
|
24
|
+
label if isEmpty order then "empty" else "some items" end if
|
|
25
25
|
timeout 10 s
|
|
26
|
+
end for law
|
|
26
27
|
|
|
27
|
-
for law
|
|
28
|
+
for law "|rounding is idempotent|
|
|
28
29
|
target maximize cents
|
|
29
30
|
repeat 2
|
|
30
31
|
retry flaky 1
|
|
31
32
|
|
|
32
|
-
for law
|
|
33
|
+
end for law
|
|
34
|
+
for law "|rounding never lowers a price|
|
|
33
35
|
known failing "rounds half down; see PRICE-12"
|
|
34
36
|
|
|
35
|
-
for law
|
|
37
|
+
end for law
|
|
38
|
+
for law "|a refund is never booked twice|
|
|
36
39
|
skip "refunds are not booked yet"
|
|
37
40
|
|
|
38
|
-
for
|
|
41
|
+
end for law
|
|
42
|
+
for laws "|booking a positive amount succeeds|, "|positive amounts are accepted|
|
|
39
43
|
tags ledger
|
|
40
44
|
|
|
45
|
+
end for laws
|
|
41
46
|
share Scratch per unit
|
|
42
|
-
benchmark `discount of a bulk order` is discount (Order 30 50000) end
|
|
47
|
+
benchmark `discount of a bulk order` is discount (Order record{ items = 30 , total = 50000}) end benchmark
|
|
43
48
|
-- book uses Ledger: the benchmark runs under its production handler.
|
|
44
|
-
benchmark `booking a payment` is book 500 end
|
|
45
|
-
end
|
|
49
|
+
benchmark `booking a payment` is book 500 end benchmark
|
|
50
|
+
end harness
|