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,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
- Pair first :: a second :: b
7
- end
5
+ type Pair (a :: Type) (b :: Type) is a record{
6
+ first :: a second :: b}
7
+ end type
8
8
 
9
- law `sum constructors remain distinct` is
10
- definition is
11
- `for all` (choice :: Choice) .
12
- (match choice with
13
- | Yes -> Yes
14
- | No -> No
15
- end) = choice
16
- end
17
- example `yes` is choice = Yes expect choice = Yes end
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 `products preserve both fields` is
21
- definition is
22
- `for all` (pair :: Pair Bool Bool) .
23
- (match pair with
24
- | Pair first second -> Pair first second
25
- end) = pair
26
- end
27
- example `different fields` is
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 `nested optional products keep presence states` is
34
- definition is
35
- `for all` (value :: Maybe (Pair Choice (Nullable Bool))) . value = value
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 :: Natural) is
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
- definition pushed (x :: Int8) (s :: Stack n / Stack (n + 1)) :: Unit is
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 `pop returns what push pushed` is
24
- definition is
25
- `for all` (x :: Int8) (s :: Stack n) . (push x ~s; pop ~s) = x
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 `push grows the stack` is
30
- definition is
31
- `for all` (x :: Int8) (s :: Stack n) . (push x ~s; nOfStack s) = n + 1
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 `pops come back in reverse` is
36
- definition is
37
- `for all` (x :: Int8) (y :: Int8) (s :: Stack n) .
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 `peek and pop agree` is
44
- definition is
45
- `for all` (s :: Stack (k + 1)) . peek ~s = pop ~s
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 `pop shrinks the stack` is
50
- definition is
51
- `for all` (s :: Stack (k + 1)) . (pop ~s; nOfStack s) = k
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 `push agrees with the reference` is
56
- definition is
57
- `for all` (x :: Int8) (s :: Stack n) . (pushed x ~s; pop ~s) = x
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
- definition pushBoth (x :: Int8) (a :: Stack n / Stack (n + 1)) (b :: Stack m / Stack (m + 1)) :: Unit is
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 `both stacks get the value` is
68
- definition is
69
- `for all` (x :: Int8) (a :: Stack n) (b :: Stack m) . (pushBoth x ~a ~b; pop ~a; pop ~b) = x
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 `a push in each branch` is
76
- definition is
77
- `for all` (x :: Int8) (s :: Stack n) .
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 `a push chosen by a match` is
83
- definition is
84
- `for all` (m :: Maybe Int8) (s :: Stack n) .
85
- ((match m with
86
- | Just v -> push v ~s
87
- | Nothing -> push 0 ~s
88
- end); pop ~s) = (match m with
89
- | Just v -> v
90
- | Nothing -> prelude.Int8 0
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 Pair first :: a second :: b end
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 value :: BigInt where a = BigInt
10
- | Truth value :: Bool where a = Bool
11
- | Plus left :: Expr BigInt right :: Expr BigInt where a = BigInt
12
- | Same left :: Expr BigInt right :: Expr BigInt where a = Bool
13
- | Negate operand :: Expr Bool where a = Bool
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
- definition eval (e :: Expr a) :: a is
21
- match e with
22
- | Number v -> v
23
- | Truth b -> b
24
- | Plus l r -> eval l + eval r
25
- | Same l r -> eval l == eval r
26
- | Negate x -> !(eval x)
27
- | Both l r -> Pair (eval l) (eval r)
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 BigInt -> BigInt
31
+ evalNumber :: Expr Integer -> Integer
32
32
  evalTruth :: Expr Bool -> Bool
33
- evalPair :: Expr (Pair BigInt Bool) -> Pair BigInt Bool
33
+ evalPair :: Expr (Pair Integer Bool) -> Pair Integer Bool
34
34
  -- Constant folding: a single number with the same value.
35
- fold :: Expr BigInt -> Expr BigInt
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 value :: b
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 `numbers agree with eval` is
47
- definition is `for all` (e :: Expr BigInt) . evalNumber e = eval e end
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 `truths agree with eval` is
51
- definition is `for all` (e :: Expr Bool) . evalTruth e = eval e end
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 `pairs agree with eval` is
55
- definition is `for all` (e :: Expr (Pair BigInt Bool)) . evalPair e = eval e end
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 `folding keeps the value` is
59
- definition is `for all` (e :: Expr BigInt) . eval (fold e) = eval e end
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 `a shown number names its type` is
63
- definition is `for all` (x :: Int32) . describe (Shown x) = "Int32" end
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 `a shown flag names its type` is
67
- definition is `for all` (b :: Bool) . describe (Shown b) = "Bool" end
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 `every shown value is described` is
71
- definition is `for all` (s :: Shown) . prelude.length (describe s) > 0 end
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 `two plus three` is
75
- definition is `for all` (x :: BigInt) . eval (Plus (Number 2) (Number 3)) = 5 end
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 `int8` is
11
- definition is
12
- `for all` (seed :: UInt64) . prelude.length (generated "(int Int8 -128 127)" seed 4 5) = 5
13
- end
14
- example `seed 42` is
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 `unbounded integers` is
22
- definition is
23
- `for all` (seed :: UInt64) . prelude.length (generated "(int Integer _ _)" seed 4 4) = 4
24
- end
25
- example `seed 7` is
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 `a lower bound` is
33
- definition is
34
- `for all` (seed :: UInt64) . prelude.length (generated "(int Int32 5 _)" seed 4 4) = 4
35
- end
36
- example `seed 7` is
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 `the full UInt64 range` is
44
- definition is
45
- `for all` (seed :: UInt64) . prelude.length (generated "(int UInt64 0 18446744073709551615)" seed 4 3) = 3
46
- end
47
- example `seed 1` is
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 `booleans` is
55
- definition is
56
- `for all` (seed :: UInt64) . prelude.length (generated "(bool)" seed 4 6) = 6
57
- end
58
- example `seed 3` is
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 `text` is
66
- definition is
67
- `for all` (seed :: UInt64) . prelude.length (generated "(text)" seed 6 3) = 3
68
- end
69
- example `seed 9` is
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 `unit` is
77
- definition is
78
- `for all` (seed :: UInt64) . prelude.length (generated "(unit)" seed 1 2) = 2
79
- end
80
- example `seed 1` is
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 `lists` is
88
- definition is
89
- `for all` (seed :: UInt64) . prelude.length (generated "(list (int Int32 0 _))" seed 4 3) = 3
90
- end
91
- example `seed 42` is
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 `maybe` is
99
- definition is
100
- `for all` (seed :: UInt64) . prelude.length (generated "(maybe (bool))" seed 4 4) = 4
101
- end
102
- example `seed 5` is
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 `either` is
110
- definition is
111
- `for all` (seed :: UInt64) . prelude.length (generated "(either (text) (int Int8 -128 127))" seed 4 4) = 4
112
- end
113
- example `seed 11` is
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 `a recursive tree` is
121
- definition is
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
123
- end
124
- example `seed 13` is
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 Purse coins :: Int64 end
134
+ type Purse is a record{ coins :: Int64} end type
135
135
 
136
- definition spend (p :: Purse) (amount :: Int32 where amount >= 1 && amount <= 1000) :: Int32 is amount end
136
+ function spend (p :: Purse) (amount :: Int32 where amount >= 1 && amount <= 1000) -> Int32 is amount end function
137
137
 
138
- law `refined amounts are drawn from their range` is
139
- definition is
140
- `for all` (p :: Purse) (amount :: Int32 where amount >= 1 && amount <= 1000) . spend p amount >= 1
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
- definition 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
148
- end
149
-
150
- law `a share is at most the total` is
151
- definition is
152
- `for all` (t :: Int32 where t >= 0 && t <= 1000) (n :: Int32 where n >= 0 && n <= 10) . share t n <= t
153
- end
154
- example `nobody to share with` is
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 `three people` is
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 `several non-empty texts are drawn` is
170
- definition is
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
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