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
|
@@ -1,51 +1,52 @@
|
|
|
1
1
|
unit example.list_refinements
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
end
|
|
8
|
-
end
|
|
3
|
+
function above (floor :: Int8) (xs :: List Int8) -> Bool is
|
|
4
|
+
first matching case of xs :
|
|
5
|
+
when Nil then true
|
|
6
|
+
when Cons first rest then first > floor && above floor rest
|
|
7
|
+
end case
|
|
8
|
+
end function
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
end
|
|
10
|
+
function positiveRows (rows :: List (List Int8)) -> Bool is
|
|
11
|
+
first matching case of rows :
|
|
12
|
+
when Nil then true
|
|
13
|
+
when Cons first rest then above 0 first && positiveRows rest
|
|
14
|
+
end case
|
|
15
|
+
end function
|
|
16
16
|
|
|
17
|
-
law
|
|
18
|
-
definition
|
|
19
|
-
above 0 xs = true
|
|
20
|
-
end
|
|
21
|
-
example
|
|
22
|
-
example
|
|
23
|
-
end
|
|
17
|
+
law "|each element is positive| is
|
|
18
|
+
definition : for all (xs :: List (value :: Int8 where value > 0)) =>
|
|
19
|
+
above 0 xs = true end for all
|
|
20
|
+
end definition
|
|
21
|
+
example "|empty| : xs = [] expect above 0 xs = true end example
|
|
22
|
+
example "|positive values| : xs = [1, 127] expect above 0 xs = true end example
|
|
23
|
+
end law
|
|
24
24
|
|
|
25
|
-
law
|
|
26
|
-
definition
|
|
27
|
-
positiveRows rows = true
|
|
28
|
-
end
|
|
29
|
-
example
|
|
30
|
-
end
|
|
25
|
+
law "|nested element domains| is
|
|
26
|
+
definition : for all (rows :: List (List (value :: Int8 where value > 0))) =>
|
|
27
|
+
positiveRows rows = true end for all
|
|
28
|
+
end definition
|
|
29
|
+
example "|empty rows| : rows = [[], [1, 2]] expect positiveRows rows = true end example
|
|
30
|
+
end law
|
|
31
31
|
|
|
32
|
-
law
|
|
33
|
-
definition
|
|
34
|
-
(xs :: List (value :: Int8 where value > lawspecElement))
|
|
35
|
-
above lawspecElement xs = true
|
|
36
|
-
end
|
|
37
|
-
example
|
|
32
|
+
law "|dependent elements| is
|
|
33
|
+
definition : for all (lawspecElement :: Int8)
|
|
34
|
+
(xs :: List (value :: Int8 where value > lawspecElement)) =>
|
|
35
|
+
above lawspecElement xs = true end for all
|
|
36
|
+
end definition
|
|
37
|
+
example "|maximum prefix still permits empty| :
|
|
38
38
|
lawspecElement = 127 xs = [] expect above lawspecElement xs = true
|
|
39
|
-
end
|
|
40
|
-
example
|
|
39
|
+
end example
|
|
40
|
+
example "|nonempty continuation| :
|
|
41
41
|
lawspecElement = 0 xs = [1, 2] expect above lawspecElement xs = true
|
|
42
|
-
end
|
|
43
|
-
end
|
|
42
|
+
end example
|
|
43
|
+
end law
|
|
44
44
|
|
|
45
|
-
law
|
|
46
|
-
definition
|
|
47
|
-
(xs :: List (value :: Int8 where value != 0 && 1 / value > 0))
|
|
48
|
-
above 0 xs = true
|
|
49
|
-
end
|
|
50
|
-
example
|
|
51
|
-
end
|
|
45
|
+
law "|division stays behind its guard| is
|
|
46
|
+
definition : for all
|
|
47
|
+
(xs :: List (value :: Int8 where value != 0 && 1 / value > 0)) =>
|
|
48
|
+
above 0 xs = true end for all
|
|
49
|
+
end definition
|
|
50
|
+
example "|positive denominator| : xs = [1] expect above 0 xs = true end example
|
|
51
|
+
end law
|
|
52
|
+
end unit
|
|
@@ -8,60 +8,61 @@ echoMaybe :: Maybe (Maybe Bool) -> Maybe (Maybe Bool)
|
|
|
8
8
|
echoEither :: Either (List Int32) (Maybe Bool) -> Either (List Int32) (Maybe Bool)
|
|
9
9
|
echoNested :: List (Maybe (Either CodeUnit16 Bytes)) -> List (Maybe (Either CodeUnit16 Bytes))
|
|
10
10
|
|
|
11
|
-
law
|
|
12
|
-
definition
|
|
13
|
-
end
|
|
11
|
+
law "|list involution| (f :: List a -> List a) requires Eq a is
|
|
12
|
+
definition : apply law "|involution| f end definition
|
|
13
|
+
end law
|
|
14
14
|
|
|
15
|
-
law
|
|
16
|
-
definition
|
|
17
|
-
example
|
|
15
|
+
law "|reverse twice restores the list| is
|
|
16
|
+
definition : apply law "|list involution| reverse end definition
|
|
17
|
+
example "|ordered input| :
|
|
18
18
|
x = [3, 1, 2]
|
|
19
19
|
expect reverse x = [2, 1, 3]
|
|
20
|
-
end
|
|
21
|
-
example
|
|
22
|
-
end
|
|
20
|
+
end example
|
|
21
|
+
example "|empty input| : x = [] expect reverse x = [] end example
|
|
22
|
+
end law
|
|
23
23
|
|
|
24
|
-
law
|
|
25
|
-
definition
|
|
26
|
-
example
|
|
27
|
-
end
|
|
24
|
+
law "|sorting is idempotent| is
|
|
25
|
+
definition : apply law "|idempotent| sort end definition
|
|
26
|
+
example "|duplicates| : x = [3, 1, 3] expect sort x = [1, 3, 3] end example
|
|
27
|
+
end law
|
|
28
28
|
|
|
29
|
-
law
|
|
30
|
-
definition
|
|
31
|
-
end
|
|
29
|
+
law "|sort produces sorted output| is
|
|
30
|
+
definition : for all (xs :: List Int32) => sorted (sort xs) end for all end definition
|
|
31
|
+
end law
|
|
32
32
|
|
|
33
|
-
law
|
|
34
|
-
definition
|
|
35
|
-
end
|
|
33
|
+
law "|sort preserves length| is
|
|
34
|
+
definition : for all (xs :: List Int32) => prelude.length (sort xs) = prelude.length xs end for all end definition
|
|
35
|
+
end law
|
|
36
36
|
|
|
37
|
-
law
|
|
38
|
-
definition
|
|
39
|
-
end
|
|
37
|
+
law "|sort preserves elements| is
|
|
38
|
+
definition : for all (xs :: List Int32) => permutation (sort xs) xs end for all end definition
|
|
39
|
+
end law
|
|
40
40
|
|
|
41
|
-
law
|
|
42
|
-
definition
|
|
43
|
-
|
|
44
|
-
prelude.length (reverse xs) = prelude.length xs
|
|
45
|
-
end
|
|
46
|
-
end
|
|
41
|
+
law "|nonempty reversal preserves length| is
|
|
42
|
+
definition :
|
|
43
|
+
for all (xs :: List Int32 where prelude.length xs > 0) =>
|
|
44
|
+
prelude.length (reverse xs) = prelude.length xs end for all
|
|
45
|
+
end definition
|
|
46
|
+
end law
|
|
47
47
|
|
|
48
|
-
law
|
|
49
|
-
definition
|
|
50
|
-
example
|
|
51
|
-
example
|
|
52
|
-
example
|
|
53
|
-
end
|
|
48
|
+
law "|Maybe preserves nested absence| is
|
|
49
|
+
definition : for all (x :: Maybe (Maybe Bool)) => echoMaybe x = x end for all end definition
|
|
50
|
+
example "|outer absence| : x = Nothing expect echoMaybe x = Nothing end example
|
|
51
|
+
example "|inner absence| : x = Just Nothing expect echoMaybe x = Just Nothing end example
|
|
52
|
+
example "|present| : x = Just (Just true) expect echoMaybe x = Just (Just true) end example
|
|
53
|
+
end law
|
|
54
54
|
|
|
55
|
-
law
|
|
56
|
-
definition
|
|
57
|
-
example
|
|
58
|
-
example
|
|
59
|
-
end
|
|
55
|
+
law "|Either preserves branches| is
|
|
56
|
+
definition : for all (x :: Either (List Int32) (Maybe Bool)) => echoEither x = x end for all end definition
|
|
57
|
+
example "|left list| : x = Left [3, 1, 3] expect echoEither x = Left [3, 1, 3] end example
|
|
58
|
+
example "|right absence| : x = Right Nothing expect echoEither x = Right Nothing end example
|
|
59
|
+
end law
|
|
60
60
|
|
|
61
|
-
law
|
|
62
|
-
definition
|
|
63
|
-
example
|
|
61
|
+
law "|nested raw values survive| is
|
|
62
|
+
definition : for all (xs :: List (Maybe (Either CodeUnit16 Bytes))) => echoNested xs = xs end for all end definition
|
|
63
|
+
example "|surrogate and octets| :
|
|
64
64
|
xs = [Nothing, Just (Left codeUnit16(55296)), Just (Right bytes([0, 255]))]
|
|
65
65
|
expect echoNested xs = [Nothing, Just (Left codeUnit16(55296)), Just (Right bytes([0, 255]))]
|
|
66
|
-
end
|
|
67
|
-
end
|
|
66
|
+
end example
|
|
67
|
+
end law
|
|
68
|
+
end unit
|
|
@@ -4,11 +4,11 @@ unit example.matchers
|
|
|
4
4
|
-- Bool, so a law may combine them with && and ||, and an example may expect
|
|
5
5
|
-- one to hold.
|
|
6
6
|
|
|
7
|
-
type Order is
|
|
8
|
-
| Pending
|
|
9
|
-
| Shipped id :: Int32 carrier :: Text
|
|
10
|
-
| Cancelled id :: Int32 reason :: Maybe Text
|
|
11
|
-
end
|
|
7
|
+
type Order is one of
|
|
8
|
+
| Pending of type Int32
|
|
9
|
+
| Shipped of type record{ id :: Int32 carrier :: Text}
|
|
10
|
+
| Cancelled of type record{ id :: Int32 reason :: Maybe Text}
|
|
11
|
+
end type
|
|
12
12
|
|
|
13
13
|
-- Native adapters, written on each target.
|
|
14
14
|
sortItems :: List Int32 -> List Int32
|
|
@@ -17,96 +17,97 @@ average :: Int32 -> Int32 -> Float64
|
|
|
17
17
|
slug :: Text -> Text
|
|
18
18
|
ship :: Int32 -> Order
|
|
19
19
|
|
|
20
|
-
law
|
|
21
|
-
definition
|
|
22
|
-
|
|
23
|
-
end
|
|
24
|
-
example
|
|
20
|
+
law "|sorting keeps every item| is
|
|
21
|
+
definition :
|
|
22
|
+
for all (xs :: List Int32) => sortItems xs has same items as xs end for all
|
|
23
|
+
end definition
|
|
24
|
+
example "|duplicates stay| :
|
|
25
25
|
xs = [3, 1, 3]
|
|
26
26
|
expect sortItems xs = [1, 3, 3]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
27
|
+
end example
|
|
28
|
+
end law
|
|
29
29
|
|
|
30
|
-
law
|
|
31
|
-
definition
|
|
32
|
-
|
|
33
|
-
uniqueTags tags is subset of tags && tags contains all of uniqueTags tags
|
|
34
|
-
end
|
|
35
|
-
end
|
|
30
|
+
law "|unique tags come from the input| is
|
|
31
|
+
definition :
|
|
32
|
+
for all (tags :: List Text) =>
|
|
33
|
+
uniqueTags tags is subset of tags && tags contains all of uniqueTags tags end for all
|
|
34
|
+
end definition
|
|
35
|
+
end law
|
|
36
36
|
|
|
37
|
-
law
|
|
38
|
-
definition
|
|
39
|
-
|
|
40
|
-
tags contains tag implies uniqueTags tags contains tag
|
|
41
|
-
end
|
|
42
|
-
end
|
|
37
|
+
law "|unique tags keep each tag| is
|
|
38
|
+
definition :
|
|
39
|
+
for all (tags :: List Text) (tag :: Text) =>
|
|
40
|
+
tags contains tag implies uniqueTags tags contains tag end for all
|
|
41
|
+
end definition
|
|
42
|
+
end law
|
|
43
43
|
|
|
44
|
-
law
|
|
45
|
-
definition
|
|
46
|
-
|
|
47
|
-
average a b is within 0.5 of prelude.Float64 (prelude.quot (a + b) 2)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
44
|
+
law "|the average lies between the two| is
|
|
45
|
+
definition :
|
|
46
|
+
for all (a :: Int32) (b :: Int32) =>
|
|
47
|
+
average a b is within 0.5 of prelude.Float64 (prelude.quot (a + b) 2) end for all
|
|
48
|
+
end definition
|
|
49
|
+
end law
|
|
50
50
|
|
|
51
|
-
law
|
|
52
|
-
definition
|
|
53
|
-
|
|
54
|
-
slug title matches regex "([a-z0-9]+(-[a-z0-9]+)*)?"
|
|
55
|
-
end
|
|
56
|
-
example
|
|
51
|
+
law "|a slug is lowercase words joined by dashes| is
|
|
52
|
+
definition :
|
|
53
|
+
for all (title :: Text) =>
|
|
54
|
+
slug title matches regex "([a-z0-9]+(-[a-z0-9]+)*)?" end for all
|
|
55
|
+
end definition
|
|
56
|
+
example "|a title| :
|
|
57
57
|
title = "Hello World"
|
|
58
58
|
expect slug title = "hello-world"
|
|
59
59
|
expect slug title starts with "hello"
|
|
60
60
|
expect slug title ends with "world"
|
|
61
61
|
expect slug title contains "o-w"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
62
|
+
end example
|
|
63
|
+
end law
|
|
64
64
|
|
|
65
|
-
law
|
|
66
|
-
definition
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
example
|
|
65
|
+
law "|shipping gives a shipped order| is
|
|
66
|
+
definition :
|
|
67
|
+
for all (id :: Int32) => ship id matches Shipped record{ id = _ , carrier = _} end for all
|
|
68
|
+
end definition
|
|
69
|
+
example "|the carrier is never empty| :
|
|
70
70
|
id = 7
|
|
71
|
-
expect ship id matches Shipped 7 _
|
|
72
|
-
expect !(ship id matches Shipped _ "")
|
|
73
|
-
end
|
|
74
|
-
end
|
|
71
|
+
expect ship id matches Shipped record{ id = 7 , carrier = _}
|
|
72
|
+
expect !(ship id matches Shipped record{ id = _ , carrier = ""})
|
|
73
|
+
end example
|
|
74
|
+
end law
|
|
75
75
|
|
|
76
76
|
-- Laws of the matchers themselves.
|
|
77
|
-
law
|
|
78
|
-
definition
|
|
79
|
-
|
|
80
|
-
(xs has same items as ys) = (ys has same items as xs)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
77
|
+
law "|having the same items is symmetric| is
|
|
78
|
+
definition :
|
|
79
|
+
for all (xs :: List Int8) (ys :: List Int8) =>
|
|
80
|
+
(xs has same items as ys) = (ys has same items as xs) end for all
|
|
81
|
+
end definition
|
|
82
|
+
end law
|
|
83
83
|
|
|
84
|
-
law
|
|
85
|
-
definition
|
|
86
|
-
|
|
87
|
-
end
|
|
88
|
-
end
|
|
84
|
+
law "|a list contains each of its items| is
|
|
85
|
+
definition :
|
|
86
|
+
for all (x :: Int8) (xs :: List Int8) => Cons x xs contains x end for all
|
|
87
|
+
end definition
|
|
88
|
+
end law
|
|
89
89
|
|
|
90
|
-
law
|
|
91
|
-
definition
|
|
92
|
-
|
|
93
|
-
end
|
|
94
|
-
end
|
|
90
|
+
law "|a list is a subset of itself| is
|
|
91
|
+
definition :
|
|
92
|
+
for all (xs :: List Int8) => xs is subset of xs && xs contains all of xs end for all
|
|
93
|
+
end definition
|
|
94
|
+
end law
|
|
95
95
|
|
|
96
|
-
law
|
|
97
|
-
definition
|
|
98
|
-
|
|
99
|
-
end
|
|
100
|
-
end
|
|
96
|
+
law "|a text starts and ends with itself| is
|
|
97
|
+
definition :
|
|
98
|
+
for all (t :: Text) => t starts with t && t ends with t && t contains t && t contains "" end for all
|
|
99
|
+
end definition
|
|
100
|
+
end law
|
|
101
101
|
|
|
102
|
-
law
|
|
103
|
-
definition
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
end
|
|
102
|
+
law "|a number is within any tolerance of itself| is
|
|
103
|
+
definition :
|
|
104
|
+
for all (x :: Int32) (d :: Int32 where d >= 0) => x is within d of x end for all
|
|
105
|
+
end definition
|
|
106
|
+
end law
|
|
107
107
|
|
|
108
|
-
law
|
|
109
|
-
definition
|
|
110
|
-
|
|
111
|
-
end
|
|
112
|
-
end
|
|
108
|
+
law "|a regex value matches like a literal| is
|
|
109
|
+
definition :
|
|
110
|
+
for all (t :: Text) => (t matches regex "[a-c]*") = (t matches regex "[a-c]*") end for all
|
|
111
|
+
end definition
|
|
112
|
+
end law
|
|
113
|
+
end unit
|
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
unit example.matching
|
|
2
2
|
|
|
3
3
|
-- Rebuilding values checks both constructor identity and every payload field.
|
|
4
|
-
law
|
|
5
|
-
definition
|
|
6
|
-
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end) = xs
|
|
11
|
-
end
|
|
12
|
-
end
|
|
4
|
+
law "|list patterns preserve the head and tail| is
|
|
5
|
+
definition :
|
|
6
|
+
for all (xs :: List Int8) =>
|
|
7
|
+
(first matching case of xs :
|
|
8
|
+
when Nil then []
|
|
9
|
+
when Cons head tail then Cons head tail
|
|
10
|
+
end case) = xs end for all
|
|
11
|
+
end definition
|
|
12
|
+
end law
|
|
13
13
|
|
|
14
|
-
law
|
|
15
|
-
definition
|
|
16
|
-
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end)
|
|
23
|
-
end) = value
|
|
24
|
-
end
|
|
25
|
-
end
|
|
14
|
+
law "|nested Maybe patterns preserve each absence state| is
|
|
15
|
+
definition :
|
|
16
|
+
for all (value :: Maybe (Maybe Bool)) =>
|
|
17
|
+
(first matching case of value :
|
|
18
|
+
when Nothing then Nothing
|
|
19
|
+
when Just inner then Just (first matching case of inner :
|
|
20
|
+
when Nothing then Nothing
|
|
21
|
+
when Just payload then Just payload
|
|
22
|
+
end case)
|
|
23
|
+
end case) = value end for all
|
|
24
|
+
end definition
|
|
25
|
+
end law
|
|
26
26
|
|
|
27
|
-
law
|
|
28
|
-
definition
|
|
29
|
-
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end) = value
|
|
34
|
-
end
|
|
35
|
-
end
|
|
27
|
+
law "|Either patterns preserve their constructor| is
|
|
28
|
+
definition :
|
|
29
|
+
for all (value :: Either (List Int8) (Maybe Bool)) =>
|
|
30
|
+
(first matching case of value :
|
|
31
|
+
when Left items then Left items
|
|
32
|
+
when Right optional then Right optional
|
|
33
|
+
end case) = value end for all
|
|
34
|
+
end definition
|
|
35
|
+
end law
|
|
36
36
|
|
|
37
37
|
-- The annotation gives the empty-case literal the same primitive type as head.
|
|
38
|
-
law
|
|
39
|
-
definition
|
|
40
|
-
|
|
41
|
-
((
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
end) :: Int8) = ((
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end) :: Int8)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
38
|
+
law "|matching can provide a default value| is
|
|
39
|
+
definition :
|
|
40
|
+
for all (value :: Maybe Int8) =>
|
|
41
|
+
((first matching case of value :
|
|
42
|
+
when Nothing then 0
|
|
43
|
+
when Just payload then payload
|
|
44
|
+
end case) :: Int8) = ((first matching case of value :
|
|
45
|
+
when Just payload then payload
|
|
46
|
+
when Nothing then 0
|
|
47
|
+
end case) :: Int8) end for all
|
|
48
|
+
end definition
|
|
49
|
+
end law
|
|
50
|
+
end unit
|
|
@@ -3,39 +3,40 @@ unit example.mixed.inputs
|
|
|
3
3
|
normalize :: Text -> Text
|
|
4
4
|
identity :: Int32 -> Int32
|
|
5
5
|
|
|
6
|
-
law
|
|
7
|
-
definition
|
|
8
|
-
|
|
9
|
-
normalize text = normalize (normalize text)
|
|
10
|
-
end
|
|
11
|
-
example
|
|
6
|
+
law "|text normalization reaches a fixed point with an unused integer input| is
|
|
7
|
+
definition :
|
|
8
|
+
for all (text :: Text) (number :: Int32) =>
|
|
9
|
+
normalize text = normalize (normalize text) end for all
|
|
10
|
+
end definition
|
|
11
|
+
example "|text normalization and integer identity have explicit results| :
|
|
12
12
|
text = "Hello, World!"
|
|
13
13
|
number = -42
|
|
14
14
|
expect normalize text = "Hello,-World!"
|
|
15
15
|
expect identity number = -42
|
|
16
|
-
end
|
|
17
|
-
end
|
|
16
|
+
end example
|
|
17
|
+
end law
|
|
18
18
|
|
|
19
|
-
law
|
|
20
|
-
definition
|
|
21
|
-
|
|
22
|
-
identity number = number
|
|
23
|
-
end
|
|
24
|
-
example
|
|
19
|
+
law "|integer identity with an unused text input| is
|
|
20
|
+
definition :
|
|
21
|
+
for all (text :: Text) (number :: Int32) =>
|
|
22
|
+
identity number = number end for all
|
|
23
|
+
end definition
|
|
24
|
+
example "|text normalization and integer identity have explicit results| :
|
|
25
25
|
text = "λ 😀"
|
|
26
26
|
number = 2147483647
|
|
27
27
|
expect normalize text = "λ-😀"
|
|
28
28
|
expect identity number = 2147483647
|
|
29
|
-
end
|
|
30
|
-
end
|
|
29
|
+
end example
|
|
30
|
+
end law
|
|
31
31
|
|
|
32
|
-
law
|
|
33
|
-
definition
|
|
34
|
-
|
|
35
|
-
normalize "" = ""
|
|
36
|
-
end
|
|
37
|
-
example
|
|
32
|
+
law "|normalizing an empty literal| is
|
|
33
|
+
definition :
|
|
34
|
+
for all (text :: Text) =>
|
|
35
|
+
normalize "" = "" end for all
|
|
36
|
+
end definition
|
|
37
|
+
example "|empty literal stays empty; quantified text is unused| :
|
|
38
38
|
text = "unused context"
|
|
39
39
|
expect normalize "" = ""
|
|
40
|
-
end
|
|
41
|
-
end
|
|
40
|
+
end example
|
|
41
|
+
end law
|
|
42
|
+
end unit
|