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.
- package/CHANGELOG.md +109 -1
- package/README.md +34 -26
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +6 -23
- package/bin/lawspec.mjs +148 -65
- package/build.json +245 -177
- package/builtin-data-names.mjs +73 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/examples/native-payments/clojure/lawspec.json +13 -2
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +14 -3
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +14 -3
- package/examples/native-payments/swift/lawspec.json +14 -3
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +57 -53
- package/examples/packages/shop-domain/src/domain.lawspec +36 -33
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +5 -4
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +6 -4
- package/examples/rc1/authorization-snapshots.lawspec +113 -0
- package/examples/rc1/banner-filenames.lawspec +64 -0
- package/examples/rc1/bit-codec.lawspec +57 -0
- package/examples/rc1/bounded-witness-search.lawspec +151 -0
- package/examples/rc1/conflicting-requirements.lawspec +31 -0
- package/examples/rc1/constructive-witnesses.lawspec +120 -0
- package/examples/rc1/documentary-review.lawspec +43 -0
- package/examples/rc1/empty-domains.lawspec +47 -0
- package/examples/rc1/finite-integer-domains.lawspec +76 -0
- package/examples/rc1/law-metadata.lawspec +30 -0
- package/examples/rc1/native-payments.lawspec +108 -0
- package/examples/rc1/nesting/rrr.lawspec +34 -0
- package/examples/rc1/nesting/rru.lawspec +57 -0
- package/examples/rc1/nesting/rur.lawspec +58 -0
- package/examples/rc1/nesting/ruu.lawspec +78 -0
- package/examples/rc1/nesting/urr.lawspec +53 -0
- package/examples/rc1/nesting/uru.lawspec +73 -0
- package/examples/rc1/nesting/uur.lawspec +74 -0
- package/examples/rc1/nesting/uuu.lawspec +96 -0
- package/examples/rc1/order-workflow.lawspec +127 -0
- package/examples/rc1/parcel-measurements.lawspec +93 -0
- package/examples/rc1/picture-records.lawspec +52 -0
- package/examples/rc1/picture-tuples.lawspec +48 -0
- package/examples/rc1/record-payloads.lawspec +57 -0
- package/examples/rc1/recursive-records.lawspec +65 -0
- package/examples/rc1/refund-conformance.lawspec +45 -0
- package/examples/rc1/refund-policy.lawspec +89 -0
- package/examples/rc1/requirement-composition.lawspec +90 -0
- package/examples/rc1/structural-records.lawspec +54 -0
- package/examples/rc1-authoring.lawspec +57 -0
- 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 +8 -4
- package/explain.mjs +114 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +406 -11
- package/launcher.mjs +9 -2
- package/lsp.mjs +235 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/starter-rc1.lawspec +26 -0
- package/starter.lawspec +16 -15
- package/templates.mjs +6 -4
- package/test-command.mjs +107 -35
- package/typed-presentation.mjs +165 -0
|
@@ -9,27 +9,28 @@ unit example.approvals
|
|
|
9
9
|
-- longer one, not the two together).
|
|
10
10
|
async approvedQuickly :: Int64 -> Bool
|
|
11
11
|
|
|
12
|
-
law
|
|
13
|
-
definition
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
example
|
|
12
|
+
law "|an all group's checks run at the same time| is
|
|
13
|
+
definition :
|
|
14
|
+
for all (n :: Int64) => approvedQuickly n = true end for all
|
|
15
|
+
end definition
|
|
16
|
+
example "|the slow order| :
|
|
17
17
|
n = -1
|
|
18
18
|
expect approvedQuickly n = true
|
|
19
|
-
end
|
|
20
|
-
end
|
|
19
|
+
end example
|
|
20
|
+
end law
|
|
21
21
|
|
|
22
22
|
-- Approves order n: the messages of its failures, as the workflow reports
|
|
23
23
|
-- them. Order -1's credit check finishes first, but is declared second.
|
|
24
24
|
async approvalErrors :: Int64 -> List Text
|
|
25
25
|
|
|
26
|
-
law
|
|
27
|
-
definition
|
|
28
|
-
|
|
29
|
-
approvalErrors n = prelude.select (n < 0) ["no stock", "no credit"] []
|
|
30
|
-
end
|
|
31
|
-
example
|
|
26
|
+
law "|failures are reported in declaration order| is
|
|
27
|
+
definition :
|
|
28
|
+
for all (n :: Int64) =>
|
|
29
|
+
approvalErrors n = prelude.select (n < 0) ["no stock", "no credit"] [] end for all
|
|
30
|
+
end definition
|
|
31
|
+
example "|the slow order| :
|
|
32
32
|
n = -1
|
|
33
33
|
expect approvalErrors n = ["no stock", "no credit"]
|
|
34
|
-
end
|
|
35
|
-
end
|
|
34
|
+
end example
|
|
35
|
+
end law
|
|
36
|
+
end unit
|
|
@@ -11,13 +11,13 @@ async priceOf :: Text -> Int32
|
|
|
11
11
|
-- The same price, computed by a native synchronous function.
|
|
12
12
|
quoteOf :: Text -> Int32
|
|
13
13
|
|
|
14
|
-
law
|
|
15
|
-
definition
|
|
16
|
-
example
|
|
14
|
+
law "|a looked-up price is the quoted price| is
|
|
15
|
+
definition : for all (sku :: Text) => priceOf sku = quoteOf sku end for all end definition
|
|
16
|
+
example "|a free sample| :
|
|
17
17
|
sku = "free"
|
|
18
18
|
expect priceOf sku = 0
|
|
19
|
-
end
|
|
20
|
-
end
|
|
19
|
+
end example
|
|
20
|
+
end law
|
|
21
21
|
|
|
22
22
|
-- A shelf is a native object; its methods are asynchronous.
|
|
23
23
|
handle Shelf
|
|
@@ -26,14 +26,15 @@ newShelf :: Unit -> Shelf
|
|
|
26
26
|
async restock :: Shelf -> (amount :: Int32 where amount >= 0 && amount <= 100) -> Unit
|
|
27
27
|
async count :: Shelf -> Int64
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
function modelRestock (amount :: Int32 where amount >= 0 && amount <= 100) (total :: Int64 where total >= 0 && total <= 1000000) -> Int64 is
|
|
30
30
|
total + amount
|
|
31
|
-
end
|
|
31
|
+
end function
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
function modelCount (total :: Int64) -> Pair Int64 Int64 is Pair total total end function
|
|
34
34
|
|
|
35
35
|
model shelf :: shared Shelf by Int64 is
|
|
36
36
|
start newShelf ~ 0
|
|
37
37
|
restock ~ modelRestock
|
|
38
38
|
count ~ modelCount
|
|
39
|
-
end
|
|
39
|
+
end model
|
|
40
|
+
end unit
|
|
@@ -11,20 +11,21 @@ async stock :: Text -> Int32
|
|
|
11
11
|
-- A local quote of the same price.
|
|
12
12
|
quote :: Text -> Int32
|
|
13
13
|
|
|
14
|
-
law
|
|
15
|
-
definition
|
|
16
|
-
example
|
|
14
|
+
law "|prices agree with quotes| is
|
|
15
|
+
definition : for all (sku :: Text) => price sku = quote sku end for all end definition
|
|
16
|
+
example "|a free sample| :
|
|
17
17
|
sku = "free"
|
|
18
18
|
expect price sku = 0
|
|
19
|
-
end
|
|
20
|
-
end
|
|
19
|
+
end example
|
|
20
|
+
end law
|
|
21
21
|
|
|
22
22
|
-- Two awaited calls in one clause.
|
|
23
|
-
law
|
|
24
|
-
definition
|
|
25
|
-
end
|
|
23
|
+
law "|stock never lowers a price| is
|
|
24
|
+
definition : for all (sku :: Text) => price sku + stock sku >= stock sku end for all end definition
|
|
25
|
+
end law
|
|
26
26
|
|
|
27
27
|
-- An awaited call in a guard.
|
|
28
|
-
law
|
|
29
|
-
definition
|
|
30
|
-
end
|
|
28
|
+
law "|stocked products have prices| is
|
|
29
|
+
definition : for all (sku :: Text) => stock sku > 0 implies price sku >= 0 end for all end definition
|
|
30
|
+
end law
|
|
31
|
+
end unit
|
|
@@ -3,33 +3,34 @@ unit example.atoi_codec
|
|
|
3
3
|
itoa :: Int32 -> Text
|
|
4
4
|
atoi :: Text -> Int32
|
|
5
5
|
|
|
6
|
-
law
|
|
7
|
-
definition
|
|
8
|
-
|
|
9
|
-
end
|
|
6
|
+
law "|itoa and then atoi yields a| is
|
|
7
|
+
definition :
|
|
8
|
+
apply law "|round trip identity is preserved| itoa atoi
|
|
9
|
+
end definition
|
|
10
10
|
|
|
11
|
-
description
|
|
11
|
+
description :
|
|
12
12
|
"converting an Int32 to Text with {itoa} and then back with {atoi} yields the original Int32"
|
|
13
|
-
end
|
|
13
|
+
end description
|
|
14
14
|
|
|
15
|
-
rationale
|
|
15
|
+
rationale :
|
|
16
16
|
"representing an Int32 as Text must not change its value"
|
|
17
|
-
end
|
|
17
|
+
end rationale
|
|
18
18
|
|
|
19
|
-
example
|
|
19
|
+
example "|negative integers use a minus sign and round-trip unchanged| :
|
|
20
20
|
x = -42
|
|
21
21
|
expect itoa x = "-42"
|
|
22
22
|
expect atoi (itoa x) = -42
|
|
23
|
-
end
|
|
23
|
+
end example
|
|
24
24
|
|
|
25
|
-
example
|
|
25
|
+
example "|zero renders as 0 and round-trips unchanged| :
|
|
26
26
|
x = 0
|
|
27
27
|
expect itoa x = "0"
|
|
28
28
|
expect atoi (itoa x) = 0
|
|
29
|
-
end
|
|
29
|
+
end example
|
|
30
30
|
|
|
31
|
-
references
|
|
31
|
+
references :
|
|
32
32
|
"left inverse"
|
|
33
33
|
"round-trip property"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
34
|
+
end references
|
|
35
|
+
end law
|
|
36
|
+
end unit
|
|
@@ -2,20 +2,21 @@ unit example.boolean_flags
|
|
|
2
2
|
|
|
3
3
|
flipFlag :: Bool -> Bool
|
|
4
4
|
|
|
5
|
-
law
|
|
6
|
-
definition
|
|
7
|
-
|
|
8
|
-
end
|
|
5
|
+
law "|flipping twice restores either flag| is
|
|
6
|
+
definition :
|
|
7
|
+
apply law "|left inverse| flipFlag flipFlag
|
|
8
|
+
end definition
|
|
9
9
|
|
|
10
|
-
example
|
|
10
|
+
example "|disabled becomes enabled and then disabled again| :
|
|
11
11
|
x = false
|
|
12
12
|
expect flipFlag x = true
|
|
13
13
|
expect flipFlag (flipFlag x) = false
|
|
14
|
-
end
|
|
14
|
+
end example
|
|
15
15
|
|
|
16
|
-
example
|
|
16
|
+
example "|enabled becomes disabled and then enabled again| :
|
|
17
17
|
x = true
|
|
18
18
|
expect flipFlag x = false
|
|
19
19
|
expect flipFlag (flipFlag x) = true
|
|
20
|
-
end
|
|
21
|
-
end
|
|
20
|
+
end example
|
|
21
|
+
end law
|
|
22
|
+
end unit
|
|
@@ -10,112 +10,113 @@ import lawspec.concurrent
|
|
|
10
10
|
|
|
11
11
|
-- Time. A deadline is now plus a wait; instants move by durations and are
|
|
12
12
|
-- a duration apart.
|
|
13
|
-
|
|
13
|
+
procedure deadline (wait :: Duration where wait <= 1h) -> Instant uses Clock is now + wait end procedure
|
|
14
14
|
|
|
15
15
|
-- Under the virtual clock, time moves only when told to.
|
|
16
|
-
law
|
|
17
|
-
definition
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
law
|
|
23
|
-
definition
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
end
|
|
16
|
+
law "|a deadline is as far off as the wait| using virtual clock is
|
|
17
|
+
definition :
|
|
18
|
+
for all (wait :: Duration where wait <= 1h) => (let d = deadline wait in d - now end let) = wait end for all
|
|
19
|
+
end definition
|
|
20
|
+
end law
|
|
21
|
+
|
|
22
|
+
law "|advancing moves the virtual clock| using virtual clock is
|
|
23
|
+
definition :
|
|
24
|
+
for all (d :: Duration where d <= 1h) => (let a = now in advance d; let b = now in b - a end let end let) = d end for all
|
|
25
|
+
end definition
|
|
26
|
+
end law
|
|
27
27
|
|
|
28
28
|
-- Time in laws: temporal propositions check over the clock, so under the
|
|
29
29
|
-- virtual clock they are deterministic.
|
|
30
|
-
law
|
|
31
|
-
definition
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
end
|
|
30
|
+
law "|a deadline eventually passes| using virtual clock is
|
|
31
|
+
definition :
|
|
32
|
+
for all (wait :: Duration where wait <= 1s) => (let d = deadline wait in eventually within 2 s, now >= d end let) = true end for all
|
|
33
|
+
end definition
|
|
34
|
+
end law
|
|
35
35
|
|
|
36
|
-
law
|
|
37
|
-
definition
|
|
38
|
-
end
|
|
36
|
+
law "|nothing is late before its deadline| using virtual clock is
|
|
37
|
+
definition : (let d = deadline 3s in always within 2 s, now < d end let) = true end definition
|
|
38
|
+
end law
|
|
39
39
|
|
|
40
40
|
-- A performance budget, measured on the real clock.
|
|
41
|
-
law
|
|
42
|
-
definition
|
|
43
|
-
example
|
|
41
|
+
law "|a deadline is quick to make| is
|
|
42
|
+
definition : for all (wait :: Duration where wait <= 1h) => deadline wait takes at most 500 ms end for all end definition
|
|
43
|
+
example "|an hour| :
|
|
44
44
|
wait = 1h
|
|
45
45
|
expect deadline wait takes at most 500 ms
|
|
46
|
-
end
|
|
47
|
-
end
|
|
46
|
+
end example
|
|
47
|
+
end law
|
|
48
48
|
|
|
49
49
|
-- A native adapter gets its handlers as arguments: here the real clock.
|
|
50
50
|
elapsed :: Int32 -> Duration uses Clock
|
|
51
51
|
|
|
52
|
-
law
|
|
53
|
-
definition
|
|
54
|
-
end
|
|
52
|
+
law "|elapsed time is never negative| is
|
|
53
|
+
definition : for all (n :: Int32 where n >= 0 && n <= 3) => elapsed n >= 0ms end for all end definition
|
|
54
|
+
end law
|
|
55
55
|
|
|
56
56
|
-- Random draws are reproducible: the same seed gives the same draws, on
|
|
57
57
|
-- every target.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
law
|
|
61
|
-
definition
|
|
62
|
-
|
|
63
|
-
handle roll sides with seededRandom end = handle roll sides with seededRandom end
|
|
64
|
-
end
|
|
65
|
-
example
|
|
58
|
+
procedure roll (sides :: Int64 where sides >= 1) -> Integer uses Random is randomBelow sides + 1 end procedure
|
|
59
|
+
|
|
60
|
+
law "|a seed fixes the rolls| is
|
|
61
|
+
definition :
|
|
62
|
+
for all (sides :: Int64 where sides >= 1) =>
|
|
63
|
+
handle roll sides with seededRandom end handle = handle roll sides with seededRandom end handle end for all
|
|
64
|
+
end definition
|
|
65
|
+
example "|the first roll from seed 0| :
|
|
66
66
|
sides = 6
|
|
67
|
-
expect handle roll sides with seededRandom end = 6
|
|
68
|
-
end
|
|
69
|
-
example
|
|
67
|
+
expect handle roll sides with seededRandom end handle = 6
|
|
68
|
+
end example
|
|
69
|
+
example "|the first roll from seed 42| :
|
|
70
70
|
sides = 1000
|
|
71
|
-
expect handle roll sides with seededRandom 42 end = 78
|
|
72
|
-
end
|
|
73
|
-
end
|
|
71
|
+
expect handle roll sides with seededRandom 42 end handle = 78
|
|
72
|
+
end example
|
|
73
|
+
end law
|
|
74
74
|
|
|
75
|
-
law
|
|
76
|
-
definition
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
end
|
|
75
|
+
law "|rolls are on the die| using seeded random 42 is
|
|
76
|
+
definition :
|
|
77
|
+
for all (sides :: Int64 where sides >= 1) => (let r = roll sides in r >= 1 && r <= sides end let) = true end for all
|
|
78
|
+
end definition
|
|
79
|
+
end law
|
|
80
80
|
|
|
81
81
|
-- Secure draws come from SecureRandom, which a seeded source cannot answer.
|
|
82
82
|
token :: Int32 -> Bytes uses SecureRandom
|
|
83
83
|
|
|
84
|
-
law
|
|
85
|
-
definition
|
|
86
|
-
end
|
|
84
|
+
law "|a token has the length asked| is
|
|
85
|
+
definition : for all (n :: Int32 where n >= 0 && n <= 64) => prelude.length (token n) = n end for all end definition
|
|
86
|
+
end law
|
|
87
87
|
|
|
88
88
|
-- Files, the environment and ports.
|
|
89
|
-
|
|
90
|
-
writeBytes ".lawspec-note" note; let read = readBytes ".lawspec-note" in removePath ".lawspec-note"; read
|
|
91
|
-
end
|
|
89
|
+
procedure remember (note :: Bytes) -> Maybe Bytes uses FileSystem is
|
|
90
|
+
writeBytes ".lawspec-note" note; let read = readBytes ".lawspec-note" in removePath ".lawspec-note"; read end let
|
|
91
|
+
end procedure
|
|
92
92
|
|
|
93
|
-
law
|
|
94
|
-
definition
|
|
95
|
-
end
|
|
93
|
+
law "|a remembered note reads back| is
|
|
94
|
+
definition : for all (note :: Bytes) => remember note = Just note end for all end definition
|
|
95
|
+
end law
|
|
96
96
|
|
|
97
|
-
law
|
|
98
|
-
definition
|
|
99
|
-
end
|
|
97
|
+
law "|an empty environment has no variables| using emptyEnvironment is
|
|
98
|
+
definition : for all (name :: Text) => environmentVariable name = Nothing end for all end definition
|
|
99
|
+
end law
|
|
100
100
|
|
|
101
101
|
listening :: Int32 -> Bool uses Ports
|
|
102
102
|
|
|
103
|
-
law
|
|
104
|
-
definition
|
|
105
|
-
end
|
|
103
|
+
law "|a free port can be listened on| is
|
|
104
|
+
definition : for all (n :: Int32 where n >= 0 && n <= 2) => listening n = true end for all end definition
|
|
105
|
+
end law
|
|
106
106
|
|
|
107
107
|
-- Logs. A law that inspects what was logged records the log.
|
|
108
108
|
charge :: Int32 -> Bool uses Log
|
|
109
109
|
|
|
110
|
-
law
|
|
111
|
-
definition
|
|
112
|
-
|
|
113
|
-
(if charge cents then calls of logMessage
|
|
114
|
-
end
|
|
115
|
-
end
|
|
110
|
+
law "|a charge is logged once| using recording Log is
|
|
111
|
+
definition :
|
|
112
|
+
for all (cents :: Int32 where cents >= 0 && cents <= 1000) =>
|
|
113
|
+
(if charge cents then calls of logMessage = 1 else calls of logMessage = 0 end if) = true end for all
|
|
114
|
+
end definition
|
|
115
|
+
end law
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
procedure traced (n :: Int32) -> Int32 uses Trace, Async is traceEvent "traced"; pause; n end procedure
|
|
118
118
|
|
|
119
|
-
law
|
|
120
|
-
definition
|
|
121
|
-
end
|
|
119
|
+
law "|tracing keeps the value| is
|
|
120
|
+
definition : for all (n :: Int32) => traced n = n end for all end definition
|
|
121
|
+
end law
|
|
122
|
+
end unit
|
|
@@ -2,23 +2,24 @@ unit example.canonical_url
|
|
|
2
2
|
|
|
3
3
|
canonicalize :: Text -> Text
|
|
4
4
|
|
|
5
|
-
law
|
|
6
|
-
definition
|
|
7
|
-
|
|
8
|
-
end
|
|
9
|
-
description
|
|
5
|
+
law "|canonicalization reaches a fixed point| is
|
|
6
|
+
definition :
|
|
7
|
+
apply law "|idempotent| canonicalize
|
|
8
|
+
end definition
|
|
9
|
+
description :
|
|
10
10
|
"{canonicalize} removes trailing slashes until the result is stable"
|
|
11
|
-
end
|
|
12
|
-
example
|
|
11
|
+
end description
|
|
12
|
+
example "|all trailing slashes are removed in one pass| :
|
|
13
13
|
x = "https://example.com/path///"
|
|
14
14
|
expect canonicalize x = "https://example.com/path"
|
|
15
|
-
end
|
|
16
|
-
example
|
|
15
|
+
end example
|
|
16
|
+
example "|a URL without trailing slashes stays unchanged| :
|
|
17
17
|
x = "https://example.com/path"
|
|
18
18
|
expect canonicalize x = "https://example.com/path"
|
|
19
|
-
end
|
|
20
|
-
example
|
|
19
|
+
end example
|
|
20
|
+
example "|empty input remains empty| :
|
|
21
21
|
x = ""
|
|
22
22
|
expect canonicalize x = ""
|
|
23
|
-
end
|
|
24
|
-
end
|
|
23
|
+
end example
|
|
24
|
+
end law
|
|
25
|
+
end unit
|