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,37 +1,38 @@
|
|
|
1
1
|
unit example.finite_data
|
|
2
2
|
|
|
3
|
-
type Choice is Yes | No end
|
|
3
|
+
type Choice is one of Yes | No end type
|
|
4
4
|
|
|
5
|
-
type Pair (a :: Type) (b :: Type) is
|
|
6
|
-
|
|
7
|
-
end
|
|
5
|
+
type Pair (a :: Type) (b :: Type) is a record{
|
|
6
|
+
first :: a second :: b}
|
|
7
|
+
end type
|
|
8
8
|
|
|
9
|
-
law
|
|
10
|
-
definition
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end) = choice
|
|
16
|
-
end
|
|
17
|
-
example
|
|
18
|
-
end
|
|
9
|
+
law "|sum constructors remain distinct| is
|
|
10
|
+
definition :
|
|
11
|
+
for all (choice :: Choice) =>
|
|
12
|
+
(first matching case of choice :
|
|
13
|
+
when Yes then Yes
|
|
14
|
+
when No then No
|
|
15
|
+
end case) = choice end for all
|
|
16
|
+
end definition
|
|
17
|
+
example "|yes| : choice = Yes expect choice = Yes end example
|
|
18
|
+
end law
|
|
19
19
|
|
|
20
|
-
law
|
|
21
|
-
definition
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
end) = pair
|
|
26
|
-
end
|
|
27
|
-
example
|
|
28
|
-
pair = Pair true false
|
|
29
|
-
expect pair = Pair true false
|
|
30
|
-
end
|
|
31
|
-
end
|
|
20
|
+
law "|products preserve both fields| is
|
|
21
|
+
definition :
|
|
22
|
+
for all (pair :: Pair Bool Bool) =>
|
|
23
|
+
(first matching case of pair :
|
|
24
|
+
when Pair record{ first = first , second = second} then Pair record{ first = first , second = second}
|
|
25
|
+
end case) = pair end for all
|
|
26
|
+
end definition
|
|
27
|
+
example "|different fields| :
|
|
28
|
+
pair = Pair record{ first = true , second = false}
|
|
29
|
+
expect pair = Pair record{ first = true , second = false}
|
|
30
|
+
end example
|
|
31
|
+
end law
|
|
32
32
|
|
|
33
|
-
law
|
|
34
|
-
definition
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
end
|
|
33
|
+
law "|nested optional products keep presence states| is
|
|
34
|
+
definition :
|
|
35
|
+
for all (value :: Maybe (Pair Choice (Nullable Bool))) => value = value end for all
|
|
36
|
+
end definition
|
|
37
|
+
end law
|
|
38
|
+
end unit
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
unit example.flow
|
|
2
2
|
|
|
3
|
-
type Stack (n ::
|
|
3
|
+
type Stack (n :: Whole) is one of
|
|
4
4
|
| Empty where n = 0
|
|
5
|
-
| Push top :: Int8 rest :: Stack m where n = m + 1
|
|
6
|
-
end
|
|
5
|
+
| Push of type record{ top :: Int8 rest :: Stack m} where n = m + 1
|
|
6
|
+
end type
|
|
7
7
|
|
|
8
8
|
-- A / A' is a flow parameter: the call takes the stack from A to A'. Each
|
|
9
9
|
-- adapter returns its result with the stack it leaves, as a generated
|
|
@@ -13,81 +13,82 @@ pop :: Stack (n + 1) / Stack n -> Int8
|
|
|
13
13
|
peek :: Stack (n + 1) / Stack (n + 1) -> Int8
|
|
14
14
|
|
|
15
15
|
-- A reference definition updates its flow parameter with ~s := e.
|
|
16
|
-
|
|
17
|
-
~s := Push x s
|
|
18
|
-
end
|
|
16
|
+
function pushed (x :: Int8) (s :: Stack n / Stack (n + 1)) -> Unit is
|
|
17
|
+
~s := Push record{ top = x , rest = s}
|
|
18
|
+
end function
|
|
19
19
|
|
|
20
20
|
-- ~s passes s to a flow parameter and rebinds s to the stack the call
|
|
21
21
|
-- leaves; e1; e2 sequences, left to right. pop needs Stack (m + 1): after
|
|
22
22
|
-- push, s is a Stack (n + 1), so the pop below type-checks.
|
|
23
|
-
law
|
|
24
|
-
definition
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
end
|
|
23
|
+
law "|pop returns what push pushed| is
|
|
24
|
+
definition :
|
|
25
|
+
for all (x :: Int8) (s :: Stack n) => (push x ~s; pop ~s) = x end for all
|
|
26
|
+
end definition
|
|
27
|
+
end law
|
|
28
28
|
|
|
29
|
-
law
|
|
30
|
-
definition
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
end
|
|
29
|
+
law "|push grows the stack| is
|
|
30
|
+
definition :
|
|
31
|
+
for all (x :: Int8) (s :: Stack n) => (push x ~s; nOfStack s) = n + 1 end for all
|
|
32
|
+
end definition
|
|
33
|
+
end law
|
|
34
34
|
|
|
35
|
-
law
|
|
36
|
-
definition
|
|
37
|
-
|
|
38
|
-
(push x ~s; push y ~s; pop ~s; pop ~s) = x
|
|
39
|
-
end
|
|
40
|
-
end
|
|
35
|
+
law "|pops come back in reverse| is
|
|
36
|
+
definition :
|
|
37
|
+
for all (x :: Int8) (y :: Int8) (s :: Stack n) =>
|
|
38
|
+
(push x ~s; push y ~s; pop ~s; pop ~s) = x end for all
|
|
39
|
+
end definition
|
|
40
|
+
end law
|
|
41
41
|
|
|
42
42
|
-- The quantifier's index k + 1 lets peek and pop take s.
|
|
43
|
-
law
|
|
44
|
-
definition
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
end
|
|
43
|
+
law "|peek and pop agree| is
|
|
44
|
+
definition :
|
|
45
|
+
for all (s :: Stack (k + 1)) => peek ~s = pop ~s end for all
|
|
46
|
+
end definition
|
|
47
|
+
end law
|
|
48
48
|
|
|
49
|
-
law
|
|
50
|
-
definition
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
end
|
|
49
|
+
law "|pop shrinks the stack| is
|
|
50
|
+
definition :
|
|
51
|
+
for all (s :: Stack (k + 1)) => (pop ~s; nOfStack s) = k end for all
|
|
52
|
+
end definition
|
|
53
|
+
end law
|
|
54
54
|
|
|
55
|
-
law
|
|
56
|
-
definition
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
55
|
+
law "|push agrees with the reference| is
|
|
56
|
+
definition :
|
|
57
|
+
for all (x :: Int8) (s :: Stack n) => (pushed x ~s; pop ~s) = x end for all
|
|
58
|
+
end definition
|
|
59
|
+
end law
|
|
60
60
|
|
|
61
61
|
-- A function may take several flow parameters: pushBoth takes two stacks and
|
|
62
62
|
-- leaves each one higher. A call passes ~a ~b, rebinding each.
|
|
63
|
-
|
|
64
|
-
~a := Push x a; ~b := Push x b
|
|
65
|
-
end
|
|
63
|
+
function pushBoth (x :: Int8) (a :: Stack n / Stack (n + 1)) (b :: Stack m / Stack (m + 1)) -> Unit is
|
|
64
|
+
~a := Push record{ top = x , rest = a}; ~b := Push record{ top = x , rest = b}
|
|
65
|
+
end function
|
|
66
66
|
|
|
67
|
-
law
|
|
68
|
-
definition
|
|
69
|
-
|
|
70
|
-
end
|
|
71
|
-
end
|
|
67
|
+
law "|both stacks get the value| is
|
|
68
|
+
definition :
|
|
69
|
+
for all (x :: Int8) (a :: Stack n) (b :: Stack m) => (pushBoth x ~a ~b; pop ~a; pop ~b) = x end for all
|
|
70
|
+
end definition
|
|
71
|
+
end law
|
|
72
72
|
|
|
73
73
|
-- A flow call may sit in a branch of an if or a match, when every branch
|
|
74
74
|
-- leaves the stack at the same type: here each branch pushes once.
|
|
75
|
-
law
|
|
76
|
-
definition
|
|
77
|
-
|
|
78
|
-
((if x > 0 then push x ~s else push 0 ~s); pop ~s) = (if x > 0 then x else 0)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
75
|
+
law "|a push in each branch| is
|
|
76
|
+
definition :
|
|
77
|
+
for all (x :: Int8) (s :: Stack n) =>
|
|
78
|
+
((if x > 0 then push x ~s else push 0 ~s end if); pop ~s) = (if x > 0 then x else 0 end if) end for all
|
|
79
|
+
end definition
|
|
80
|
+
end law
|
|
81
81
|
|
|
82
|
-
law
|
|
83
|
-
definition
|
|
84
|
-
|
|
85
|
-
((
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
end); pop ~s) = (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
82
|
+
law "|a push chosen by a match| is
|
|
83
|
+
definition :
|
|
84
|
+
for all (m :: Maybe Int8) (s :: Stack n) =>
|
|
85
|
+
((first matching case of m :
|
|
86
|
+
when Just v then push v ~s
|
|
87
|
+
when Nothing then push 0 ~s
|
|
88
|
+
end case); pop ~s) = (first matching case of m :
|
|
89
|
+
when Just v then v
|
|
90
|
+
when Nothing then prelude.Int8 0
|
|
91
|
+
end case) end for all
|
|
92
|
+
end definition
|
|
93
|
+
end law
|
|
94
|
+
end unit
|
|
@@ -1,76 +1,77 @@
|
|
|
1
1
|
unit example.gadt
|
|
2
2
|
|
|
3
|
-
type Pair (a :: Type) (b :: Type) is
|
|
3
|
+
type Pair (a :: Type) (b :: Type) is a record{ first :: a second :: b} end type
|
|
4
4
|
|
|
5
5
|
-- An expression indexed by the type of its value. Each constructor's `where`
|
|
6
6
|
-- fixes that type, so a value of Expr Bool is never a number literal. The
|
|
7
7
|
-- types b and c of Both are existential: Expr (Pair b c) determines them.
|
|
8
|
-
type Expr (a :: Type) is
|
|
9
|
-
| Number
|
|
10
|
-
| Truth
|
|
11
|
-
| Plus left :: Expr
|
|
12
|
-
| Same left :: Expr
|
|
13
|
-
| Negate
|
|
14
|
-
| Both first :: Expr b second :: Expr c where a = Pair b c
|
|
15
|
-
end
|
|
8
|
+
type Expr (a :: Type) is one of
|
|
9
|
+
| Number of type Integer where a = Integer
|
|
10
|
+
| Truth of type Bool where a = Bool
|
|
11
|
+
| Plus of type record{ left :: Expr Integer right :: Expr Integer} where a = Integer
|
|
12
|
+
| Same of type record{ left :: Expr Integer right :: Expr Integer} where a = Bool
|
|
13
|
+
| Negate of type Expr Bool where a = Bool
|
|
14
|
+
| Both of type record{ first :: Expr b second :: Expr c} where a = Pair b c
|
|
15
|
+
end type
|
|
16
16
|
|
|
17
17
|
-- Matching Number refines a to BigInt in that branch, so v is a value of a.
|
|
18
18
|
-- eval calls itself at other types (Expr BigInt inside Expr Bool): each type
|
|
19
19
|
-- it is used at becomes a checked instance, and unreachable branches vanish.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
end
|
|
20
|
+
function eval (e :: Expr a) -> a is
|
|
21
|
+
first matching case of e :
|
|
22
|
+
when Number v then v
|
|
23
|
+
when Truth b then b
|
|
24
|
+
when Plus record{ left = l , right = r} then eval l + eval r
|
|
25
|
+
when Same record{ left = l , right = r} then eval l = eval r
|
|
26
|
+
when Negate x then !(eval x)
|
|
27
|
+
when Both record{ first = l , second = r} then Pair record{ first = (eval l) , second = (eval r)}
|
|
28
|
+
end case
|
|
29
|
+
end function
|
|
30
30
|
|
|
31
|
-
evalNumber :: Expr
|
|
31
|
+
evalNumber :: Expr Integer -> Integer
|
|
32
32
|
evalTruth :: Expr Bool -> Bool
|
|
33
|
-
evalPair :: Expr (Pair
|
|
33
|
+
evalPair :: Expr (Pair Integer Bool) -> Pair Integer Bool
|
|
34
34
|
-- Constant folding: a single number with the same value.
|
|
35
|
-
fold :: Expr
|
|
35
|
+
fold :: Expr Integer -> Expr Integer
|
|
36
36
|
|
|
37
37
|
-- A shown value's type is existential and only the value says what it is:
|
|
38
38
|
-- each value carries its type, as a witness, to native code.
|
|
39
|
-
type Shown is
|
|
40
|
-
| Shown
|
|
41
|
-
end
|
|
39
|
+
type Shown is one of
|
|
40
|
+
| Shown of type b
|
|
41
|
+
end type
|
|
42
42
|
|
|
43
43
|
-- The name of the type a shown value holds.
|
|
44
44
|
describe :: Shown -> Text
|
|
45
45
|
|
|
46
|
-
law
|
|
47
|
-
definition
|
|
48
|
-
end
|
|
46
|
+
law "|numbers agree with eval| is
|
|
47
|
+
definition : for all (e :: Expr Integer) => evalNumber e = eval e end for all end definition
|
|
48
|
+
end law
|
|
49
49
|
|
|
50
|
-
law
|
|
51
|
-
definition
|
|
52
|
-
end
|
|
50
|
+
law "|truths agree with eval| is
|
|
51
|
+
definition : for all (e :: Expr Bool) => evalTruth e = eval e end for all end definition
|
|
52
|
+
end law
|
|
53
53
|
|
|
54
|
-
law
|
|
55
|
-
definition
|
|
56
|
-
end
|
|
54
|
+
law "|pairs agree with eval| is
|
|
55
|
+
definition : for all (e :: Expr (Pair Integer Bool)) => evalPair e = eval e end for all end definition
|
|
56
|
+
end law
|
|
57
57
|
|
|
58
|
-
law
|
|
59
|
-
definition
|
|
60
|
-
end
|
|
58
|
+
law "|folding keeps the value| is
|
|
59
|
+
definition : for all (e :: Expr Integer) => eval (fold e) = eval e end for all end definition
|
|
60
|
+
end law
|
|
61
61
|
|
|
62
|
-
law
|
|
63
|
-
definition
|
|
64
|
-
end
|
|
62
|
+
law "|a shown number names its type| is
|
|
63
|
+
definition : for all (x :: Int32) => describe (Shown x) = "Int32" end for all end definition
|
|
64
|
+
end law
|
|
65
65
|
|
|
66
|
-
law
|
|
67
|
-
definition
|
|
68
|
-
end
|
|
66
|
+
law "|a shown flag names its type| is
|
|
67
|
+
definition : for all (b :: Bool) => describe (Shown b) = "Bool" end for all end definition
|
|
68
|
+
end law
|
|
69
69
|
|
|
70
|
-
law
|
|
71
|
-
definition
|
|
72
|
-
end
|
|
70
|
+
law "|every shown value is described| is
|
|
71
|
+
definition : for all (s :: Shown) => prelude.length (describe s) > 0 end for all end definition
|
|
72
|
+
end law
|
|
73
73
|
|
|
74
|
-
law
|
|
75
|
-
definition
|
|
76
|
-
end
|
|
74
|
+
law "|two plus three| is
|
|
75
|
+
definition : for all (x :: Integer) => eval (Plus record{ left = (Number 2) , right = (Number 3)}) = 5 end for all end definition
|
|
76
|
+
end law
|
|
77
|
+
end unit
|
|
@@ -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
|