lawspec 0.23.0 → 0.25.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 +167 -1
- package/README.md +29 -22
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +14 -23
- package/bin/lawspec.mjs +200 -67
- package/build.json +381 -155
- package/builtin-data-names.mjs +73 -0
- package/compatibility.json +21 -0
- package/core.wasm +2 -2
- package/doctor.mjs +98 -1
- package/examples/native-payments/clojure/lawspec.json +62 -0
- package/examples/native-payments/clojure/src/domain/payments.clj +11 -0
- package/examples/native-payments/clojure/test/domain/payment_generators.clj +9 -0
- 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 +176 -0
- package/examples/native-payments/groovy/src/main/groovy/domain/PaymentsDomain.groovy +49 -0
- package/examples/native-payments/groovy/src/test/groovy/domain/PaymentGenerators.groovy +15 -0
- 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 +176 -0
- package/examples/native-payments/scala/src/main/scala/domain/PaymentsDomain.scala +18 -0
- package/examples/native-payments/scala/src/test/scala/domain/PaymentGenerators.scala +8 -0
- package/examples/native-payments/swift/lawspec.json +165 -0
- package/examples/native-payments/swift/src/Native/PaymentsDomain.swift +35 -0
- package/examples/native-payments/swift/tests/Native/PaymentGenerators.swift +12 -0
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +36 -34
- package/examples/packages/shop-domain/src/domain.lawspec +23 -21
- package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
- package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
- package/examples/rc1/authorization-snapshots.lawspec +112 -0
- package/examples/rc1/banner-filenames.lawspec +63 -0
- package/examples/rc1/bit-codec.lawspec +56 -0
- package/examples/rc1/bounded-witness-search.lawspec +144 -0
- package/examples/rc1/conflicting-requirements.lawspec +30 -0
- package/examples/rc1/constructive-witnesses.lawspec +113 -0
- package/examples/rc1/documentary-review.lawspec +42 -0
- package/examples/rc1/empty-domains.lawspec +46 -0
- package/examples/rc1/finite-integer-domains.lawspec +75 -0
- package/examples/rc1/law-metadata.lawspec +29 -0
- package/examples/rc1/native-payments.lawspec +107 -0
- package/examples/rc1/nesting/rrr.lawspec +33 -0
- package/examples/rc1/nesting/rru.lawspec +56 -0
- package/examples/rc1/nesting/rur.lawspec +57 -0
- package/examples/rc1/nesting/ruu.lawspec +77 -0
- package/examples/rc1/nesting/urr.lawspec +52 -0
- package/examples/rc1/nesting/uru.lawspec +72 -0
- package/examples/rc1/nesting/uur.lawspec +73 -0
- package/examples/rc1/nesting/uuu.lawspec +95 -0
- package/examples/rc1/order-workflow.lawspec +126 -0
- package/examples/rc1/parcel-measurements.lawspec +92 -0
- package/examples/rc1/picture-records.lawspec +51 -0
- package/examples/rc1/picture-tuples.lawspec +47 -0
- package/examples/rc1/record-payloads.lawspec +56 -0
- package/examples/rc1/recursive-records.lawspec +64 -0
- package/examples/rc1/refund-conformance.lawspec +44 -0
- package/examples/rc1/refund-policy.lawspec +88 -0
- package/examples/rc1/requirement-composition.lawspec +89 -0
- package/examples/rc1/structural-records.lawspec +53 -0
- package/examples/rc1-authoring.lawspec +56 -0
- package/examples-command.mjs +11 -5
- package/explain.mjs +112 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +934 -12
- package/lsp.mjs +231 -0
- package/migrate.mjs +135 -0
- package/migration-bindings.mjs +86 -0
- package/migration-cases.mjs +45 -0
- package/migration-collections.mjs +54 -0
- package/migration-correspondence.mjs +275 -0
- package/migration-generation.mjs +99 -0
- package/migration-laws.mjs +102 -0
- package/migration-records.mjs +166 -0
- package/migration-source.mjs +247 -0
- package/migration-write.mjs +156 -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/scala-coverage.mjs +56 -0
- package/starter-rc1.lawspec +25 -0
- package/templates.mjs +65 -3
- package/test-command.mjs +177 -29
- package/typed-presentation.mjs +165 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,170 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.25.0] - 2026-10-18
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Optional case warnings through `lawspec check --warn-matches`, SDK requests
|
|
14
|
+
with `warnMatches: true`, and the VS Code `lawspec.warnMatches` setting.
|
|
15
|
+
Findings retain source spans and remain separate from compiler errors and
|
|
16
|
+
law evidence. An empty warning list does not prove that every branch is reachable.
|
|
17
|
+
|
|
18
|
+
- Checked documentation rejection examples with `reject=<diagnostic-code>`.
|
|
19
|
+
Each fixture requires exactly its expected compiler diagnostic, preserves
|
|
20
|
+
failure context and reports unexpected acceptance after editing.
|
|
21
|
+
- Canonical authoring with `function` and `procedure`, phrase names, explicit
|
|
22
|
+
record and alternative payloads, first-matching cases, readable equality
|
|
23
|
+
wording and nested logical quantifiers.
|
|
24
|
+
- Checked mappings over resolved scalar, record, constructor and collection
|
|
25
|
+
constants. Typed Eq detects duplicate and non-reflexive keys; complete finite
|
|
26
|
+
coverage or an explicit fallback is required. Complete mappings derive
|
|
27
|
+
preimages and, when justified by unique outputs, a Maybe-valued inverse.
|
|
28
|
+
- Formatting, validated project migration from 0.24, four explanation views,
|
|
29
|
+
and compiler-backed editor support. Ordinary interfaces use API schema 5,
|
|
30
|
+
configuration version 2 and the technical language profile `1.0-rc.1`.
|
|
31
|
+
- A canonical Chapter 6 specification, with independent native Python oracles
|
|
32
|
+
for all A-instruction addresses and C-instruction combinations.
|
|
33
|
+
- Scoped native execution evidence shared by the four explanation views,
|
|
34
|
+
including current/stale inputs, actual completions, seeds and failure output.
|
|
35
|
+
Interrupted or undiscovered checks cannot reuse an older successful result;
|
|
36
|
+
sampled model runs remain distinct from proofs.
|
|
37
|
+
- Refund policy and native conformance examples, contradictory requirements
|
|
38
|
+
with concrete refutations, and a stateful order-processing example.
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- Formatting omits optional record-type field commas using the parser's source
|
|
43
|
+
inventory, retaining commas in values, patterns, tuples, comments and text.
|
|
44
|
+
- Formatting preserves line-scoped scenario arguments, including command
|
|
45
|
+
bindings, parallel branches and recovery, while wrapping surrounding code.
|
|
46
|
+
Multiline literal contents retain their whitespace, and block endings after
|
|
47
|
+
a closing quote update the indentation of subsequent declarations.
|
|
48
|
+
- Documentation highlighting now uses the editor's shared TextMate grammar and
|
|
49
|
+
tokenizer. Phrase names end at their delimiter, and canonical function/type
|
|
50
|
+
syntax receives the editor's scopes. Highlighting asset failures preserve
|
|
51
|
+
readable source and compiler interaction.
|
|
52
|
+
- Formatting retains the indentation of abilities, stateful handler operations
|
|
53
|
+
and handled expressions, including conditional initializers.
|
|
54
|
+
- Source formatting covers workflows, models, actors, supervisors, protocols,
|
|
55
|
+
scenarios, resources, wrappers, refinements and harness groups. Paired scenario
|
|
56
|
+
and benchmark names remain indivisible; words inside them do not affect block
|
|
57
|
+
indentation. A top-level `handle` declaration does not open an expression block.
|
|
58
|
+
|
|
59
|
+
- Law verification layers are selected independently and default to none.
|
|
60
|
+
Definition validation and deliberately deferred runtime contracts remain
|
|
61
|
+
mandatory. New-project instructions explicitly select starter law checks.
|
|
62
|
+
- Model checks can be selected independently on all 17 native targets while
|
|
63
|
+
actor and supervisor APIs remain available to ordinary law tests. Native
|
|
64
|
+
manifests register model checks, and runners require their actual completions.
|
|
65
|
+
- Canonical `Set` uses Eq and first-occurrence order; legacy ordered-set uses
|
|
66
|
+
migrate to `SortedSet`. Canonical numeric names distinguish `Whole` and `Nat`.
|
|
67
|
+
- Validated payload transport preserves indexed, GADT and existential metadata.
|
|
68
|
+
Unsupported source, population, dependency and native-binding correspondence
|
|
69
|
+
continues to block migration writes.
|
|
70
|
+
- Java and Groovy structural property checks retain seeded generation and native
|
|
71
|
+
shrinking without exhausting a small domain's JetCheck generation trees.
|
|
72
|
+
Go equality generation handles payload-free alternatives alongside payloads.
|
|
73
|
+
|
|
74
|
+
## [0.24.0] - 2026-10-13
|
|
75
|
+
|
|
76
|
+
### Added
|
|
77
|
+
|
|
78
|
+
- A Scala target (`--target scala`): Scala 3.9 over the shared JVM runtime,
|
|
79
|
+
built and tested with Scala CLI (`scala test .`) in sbt's source layout.
|
|
80
|
+
Data types are case classes and enums, and the built-in types are Scala's
|
|
81
|
+
own: `List`, `Option`, `Either`, `Set`, `Map`, `Queue`, `Vector`, `BigInt`,
|
|
82
|
+
exact `BigDecimal`, `FiniteDuration` and `IArray`. Abilities are traits,
|
|
83
|
+
and an adapter or operation that fails with `E` returns `Either[E, R]`;
|
|
84
|
+
async adapters return `Future`. Laws are ScalaTest suites whose properties
|
|
85
|
+
run on ScalaCheck 1.20.0 with LawSpec's shrink-tree generators, so shrinks
|
|
86
|
+
stay inside refinements and `LAWSPEC_SEED` replays a run
|
|
87
|
+
(DEC-scala-property-library). Checked definitions run on the shared JVM
|
|
88
|
+
bodies, typed where the plan allows; actors, supervisors, sessions,
|
|
89
|
+
mailboxes, remote evaluation, the secure network, post-quantum crypto, the
|
|
90
|
+
built-in abilities' default handlers, native bindings and every harness
|
|
91
|
+
feature (strategies, cover, targeted search, the failure database, retries,
|
|
92
|
+
timeouts, order random, parallel units, benchmarks and JUnit reports) are
|
|
93
|
+
supported. `lawspec test --coverage` measures Scala with Scala 3's own
|
|
94
|
+
instrumentation and the scoverage reporter, with nothing to install.
|
|
95
|
+
- Typed BEAM code: on Erlang, Elixir and Gleam, a checked definition whose
|
|
96
|
+
values all have native forms, and a spec handler whose clauses are all
|
|
97
|
+
typed, run as native Erlang in `lawspec_typed`, over each language's own
|
|
98
|
+
tuples, structs or custom types, with `KeyVal` as maps and `Set` as
|
|
99
|
+
version 2 `sets` whose entries and items come out in the portable order.
|
|
100
|
+
Integers are checked where their type bounds them, raise and attempt fail
|
|
101
|
+
as the dynamic code does, and definitions that perform other abilities'
|
|
102
|
+
operations take the handler context. A typed handler keeps its state in
|
|
103
|
+
its cell's process and runs each operation there, so an operation copies
|
|
104
|
+
only its arguments and result; `cluster_typed_state` and
|
|
105
|
+
`cluster_set_typed_state` read and replace that state without
|
|
106
|
+
conversion. `lawspec-dev bench kafka` has Erlang, Elixir and Gleam
|
|
107
|
+
drivers: at 10,000 produces the workload took 34 to 36 seconds on the
|
|
108
|
+
dynamic path and 0.02 to 0.03 seconds typed, and a million produces now
|
|
109
|
+
run at 400,000 to 770,000 operations a second. `--typed` reports the BEAM
|
|
110
|
+
plan too.
|
|
111
|
+
- Groovy target (`--target groovy`) on Groovy 5.0, Gradle and Spock 2.5. Groovy
|
|
112
|
+
runs over the Java model: the data types (records and sealed interfaces),
|
|
113
|
+
codecs, ability interfaces, checked definitions, actors, sessions, mailboxes,
|
|
114
|
+
the network and the secure handler are the Java target's, compiled jointly
|
|
115
|
+
with the Groovy sources. Adapters and bound application code are Groovy
|
|
116
|
+
classes checked with `@CompileStatic`, and each unit's laws are a Spock
|
|
117
|
+
specification with a feature per test, named in words. Properties run on
|
|
118
|
+
JetCheck with LawSpec's generators, so shrinks stay inside refinements, and
|
|
119
|
+
`LAWSPEC_SEED` replays a run; `order random` and `parallel` become a seeded
|
|
120
|
+
feature order and Spock's concurrent execution. The surveys behind the
|
|
121
|
+
property libraries are DEC-groovy-property-library and
|
|
122
|
+
DEC-clojure-property-library.
|
|
123
|
+
- Clojure target (`--target clojure`) on Clojure 1.12 with deps.edn,
|
|
124
|
+
`clojure.test` and test.check. Clojure runs over the Java model too, which
|
|
125
|
+
`lawspec.build` compiles with the JDK's compiler. Each unit's adapters are
|
|
126
|
+
functions of a namespace, called through a generated Java bridge, and
|
|
127
|
+
values cross as Clojure data: tagged maps (`{:lawspec/tag
|
|
128
|
+
:payment/approved, :cents 500}`) or a tag alone for a constructor without
|
|
129
|
+
fields, vectors, sets, maps, nil for Maybe's nothing, `[:left e]` and
|
|
130
|
+
`[:right a]`, and failures as ex-info. Native handlers are maps of
|
|
131
|
+
operations. `lawspec.json` binds functions, handle constructors and
|
|
132
|
+
methods, handlers and failures (an ex-info's `:type`) to Clojure.
|
|
133
|
+
Properties run on test.check: LawSpec's generators make rose trees whose
|
|
134
|
+
shrinks stay inside refinements, and `LAWSPEC_SEED` replays a run; a
|
|
135
|
+
namespace's `test-ns-hook` gives `order random` and `parallel`.
|
|
136
|
+
- A Swift target (`--target swift`) on Swift 6.2 and later, with SwiftPM and
|
|
137
|
+
`swift test`. Its runtime is written for Swift 6 with strict concurrency:
|
|
138
|
+
structs and enums with associated values (`indirect` where recursive) in
|
|
139
|
+
LawSpec's order, exact integers, persistent lists (`PersistentList`) and
|
|
140
|
+
sorted collections, typed throws for failures, abilities as protocols,
|
|
141
|
+
`async` adapters, supervised actors whose messages also have `async`
|
|
142
|
+
overloads, single-use session ends, mailboxes, a virtual clock, workflow
|
|
143
|
+
policies, remote evaluation and the secure network on the shared wire
|
|
144
|
+
format, and post-quantum crypto from CryptoKit (macOS 26), with the
|
|
145
|
+
runtime's own SHAKE256 and SLH-DSA where CryptoKit has none. Tests are Swift
|
|
146
|
+
Testing functions; no maintained Swift property library shrinks inside
|
|
147
|
+
refinements and replays from a seed, so properties run on a small
|
|
148
|
+
shrink-tree engine in `LawSpecTesting`, with `LAWSPEC_SEED` replay. Models,
|
|
149
|
+
linearizability, scenarios and the whole harness run around it.
|
|
150
|
+
Definitions whose values all have native types run typed, with self tail
|
|
151
|
+
calls as loops, and each spec handler is a native class with its state to
|
|
152
|
+
read or restore. `lawspec test`, `lawspec doctor` and `lawspec examples`
|
|
153
|
+
support it. See [Set up Swift](docs/how-to/targets/swift.md).
|
|
154
|
+
|
|
155
|
+
### Fixed
|
|
156
|
+
|
|
157
|
+
- Erlang and Elixir: a data type named after a built-in type that a module
|
|
158
|
+
may redefine, such as `Record`, no longer makes `lawspec_data` warn. The
|
|
159
|
+
type takes its qualified name, and its constructors keep their tags.
|
|
160
|
+
- Erlang and Elixir: EUnit and ExUnit now allow a law, model check or
|
|
161
|
+
benchmark ten minutes on top of its own timeouts. This is a guard against
|
|
162
|
+
hangs, not a budget. Before, the limit was 60 s, and a law that retries
|
|
163
|
+
over a lossy network on the real clock could run past it on a loaded
|
|
164
|
+
machine.
|
|
165
|
+
- BEAM parallel model checks pause with a run of yields instead of a 1 ms
|
|
166
|
+
timer, which a loaded machine stretches across hundreds of runs.
|
|
167
|
+
- Refined record fields are now generated instead of filtered. On Python, a
|
|
168
|
+
constructor field refined by a regex also draws samples of that regex. On
|
|
169
|
+
every target, a data input whose refinement matches one of its fields
|
|
170
|
+
against a regex (`validPet p`) now starts from values whose field matches.
|
|
171
|
+
This stops Hypothesis's `filter_too_much` health check from failing.
|
|
172
|
+
|
|
9
173
|
## [0.23.0] - 2026-10-12
|
|
10
174
|
|
|
11
175
|
### Added
|
|
@@ -1535,7 +1699,9 @@ A maintenance release. The language, generated code and API are unchanged from
|
|
|
1535
1699
|
machine-sized bindings reject an architecture mismatch. Rust adapters take
|
|
1536
1700
|
owned values.
|
|
1537
1701
|
|
|
1538
|
-
[Unreleased]: https://github.com/brain-fuel/lawspec/compare/v0.
|
|
1702
|
+
[Unreleased]: https://github.com/brain-fuel/lawspec/compare/v0.25.0...HEAD
|
|
1703
|
+
[0.25.0]: https://github.com/brain-fuel/lawspec/compare/v0.24.0...v0.25.0
|
|
1704
|
+
[0.24.0]: https://github.com/brain-fuel/lawspec/compare/v0.23.0...v0.24.0
|
|
1539
1705
|
[0.23.0]: https://github.com/brain-fuel/lawspec/compare/v0.22.0...v0.23.0
|
|
1540
1706
|
[0.22.0]: https://github.com/brain-fuel/lawspec/compare/v0.21.0...v0.22.0
|
|
1541
1707
|
[0.21.0]: https://github.com/brain-fuel/lawspec/compare/v0.20.1...v0.21.0
|
package/README.md
CHANGED
|
@@ -5,21 +5,28 @@
|
|
|
5
5
|
LawSpec is a specification language for the laws your code must obey. It
|
|
6
6
|
compiles reusable laws and concrete examples into native property-based tests
|
|
7
7
|
and implementation adapters for Java, Python, JavaScript, TypeScript, Go,
|
|
8
|
-
Haskell, Kotlin
|
|
9
|
-
|
|
8
|
+
Haskell, Kotlin, Rust, C#, F#, Swift, Erlang, Elixir, Gleam, Clojure, Groovy and
|
|
9
|
+
Scala. The compiler is written in Haskell and distributed on npm as prebuilt
|
|
10
|
+
WebAssembly, with a Node CLI and a typed JavaScript API.
|
|
11
|
+
|
|
12
|
+
The canonical authoring examples below target 0.25.0, the minor in preparation
|
|
13
|
+
on `main`.
|
|
14
|
+
Install the development checkout as shown below. For released 0.24.0, use the
|
|
15
|
+
[0.24.0 documentation](https://github.com/brain-fuel/lawspec/tree/v0.24.0).
|
|
10
16
|
|
|
11
17
|
## Features
|
|
12
18
|
|
|
13
19
|
- **Reusable laws.** A prelude of [round-trip, equivalence and algebraic laws](docs/reference/prelude-algebra.md), and your own generic laws.
|
|
14
20
|
- **Examples with expected results** that [pin each law down](docs/reference/language/laws-and-examples.md).
|
|
15
|
-
- **Native tests** with each target's framework, generators and shrinkers
|
|
21
|
+
- **Native tests** with each [target's framework, generators and shrinkers](docs/how-to/targets/index.md).
|
|
16
22
|
- **A full scalar catalog** with [exact arithmetic](docs/reference/primitives.md) that never wraps.
|
|
17
23
|
- **Structural data**: [lists, `Maybe`, `Either`, products and sums](docs/reference/language/types-and-data.md).
|
|
18
24
|
- **Refinements and contracts** with [dependent generation](docs/reference/refinements.md) that constructs valid inputs.
|
|
19
|
-
- **
|
|
25
|
+
- **Automatic definition checks** for [exhaustiveness, termination, definedness and contracts](docs/reference/language/definitions.md), with deliberately deferred postconditions enforced at runtime.
|
|
20
26
|
- **Indexed families** such as [length-indexed vectors](docs/reference/language/indexed-families.md), with proved indices.
|
|
21
27
|
- **Domain modeling** with [wrappers and workflows](docs/reference/language/domain-modeling.md).
|
|
22
28
|
- **Imports and versioned packages** of [shared laws and types](docs/reference/language/imports-and-packages.md).
|
|
29
|
+
- **Optional Z3 law proofs** through an [explicit solver host](docs/explanation/smt-proof.md), with task identities, limits and outcomes recorded.
|
|
23
30
|
- **Evidence** for every obligation: [proved, exhaustively checked, property tested, runtime checked or assumed](docs/reference/language/evidence-and-discharge.md).
|
|
24
31
|
- **Native bindings** to [your existing domain types and generators](docs/how-to/bind-native-types.md).
|
|
25
32
|
- **Safe regeneration**: [your adapters and build files stay yours](docs/explanation/ownership-and-regeneration.md).
|
|
@@ -29,33 +36,33 @@ npm as prebuilt WebAssembly, with a Node CLI and a typed JavaScript API.
|
|
|
29
36
|
Node 22+ and the selected target's build tools are required. No Haskell
|
|
30
37
|
toolchain is needed. The reference platforms are macOS and Linux.
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
To try it in a **new, empty directory**, initialize before installing, so that
|
|
38
|
-
LawSpec can create `package.json` and its test script:
|
|
39
|
+
The checkout includes the development WASM package. To try it in a **new, empty
|
|
40
|
+
directory**, initialize before installing, so that LawSpec can create
|
|
41
|
+
`package.json` and its test script:
|
|
39
42
|
|
|
40
43
|
```sh
|
|
44
|
+
git clone https://github.com/brain-fuel/lawspec.git lawspec
|
|
41
45
|
mkdir lawspec-example
|
|
42
46
|
cd lawspec-example
|
|
43
|
-
|
|
44
|
-
npm install --save-dev lawspec
|
|
47
|
+
node ../lawspec/npm/bin/lawspec.mjs init --target javascript
|
|
48
|
+
npm install --save-dev ../lawspec/npm
|
|
49
|
+
npx lawspec --version
|
|
45
50
|
npx lawspec check
|
|
46
|
-
npx lawspec explain 'example.
|
|
51
|
+
npx lawspec explain 'example.codec::codec'
|
|
47
52
|
npx lawspec doctor
|
|
48
|
-
npx lawspec generate
|
|
49
53
|
```
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
New projects start with `verification.layers: []`: intrinsic definition checks
|
|
56
|
+
run, and no law verification is selected. Set `verification.layers` to
|
|
57
|
+
`["property", "examples"]` in `lawspec.json`, then run `npx lawspec generate`.
|
|
58
|
+
Implement `src/example/codec.mjs`, then run `npm test`:
|
|
52
59
|
|
|
53
60
|
```javascript
|
|
54
61
|
export function itoa(value) { return String(value); }
|
|
55
62
|
export function atoi(value) { return Number(value); }
|
|
56
63
|
```
|
|
57
64
|
|
|
58
|
-
In an existing project, install
|
|
65
|
+
In an existing project, install the checkout's `npm` directory first, then run
|
|
59
66
|
`npx lawspec init --target javascript`. Existing build files are preserved;
|
|
60
67
|
apply the printed setup instructions before generating. See
|
|
61
68
|
[Install LawSpec and create a project](docs/how-to/install-and-init.md).
|
|
@@ -68,14 +75,14 @@ unit example.atoi_codec
|
|
|
68
75
|
itoa :: Int32 -> Text
|
|
69
76
|
atoi :: Text -> Int32
|
|
70
77
|
|
|
71
|
-
law
|
|
72
|
-
definition
|
|
73
|
-
|
|
78
|
+
law "|round trip| is
|
|
79
|
+
definition :
|
|
80
|
+
apply law "|left inverse| atoi itoa
|
|
74
81
|
end
|
|
75
|
-
description
|
|
82
|
+
description :
|
|
76
83
|
"applying {itoa} and then {atoi} recovers the original integer"
|
|
77
84
|
end
|
|
78
|
-
example
|
|
85
|
+
example "|negative integers use a minus sign and round-trip unchanged| :
|
|
79
86
|
x = -42
|
|
80
87
|
expect itoa x = "-42"
|
|
81
88
|
expect atoi (itoa x) = -42
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
UNICODE LICENSE V3
|
|
2
|
+
|
|
3
|
+
COPYRIGHT AND PERMISSION NOTICE
|
|
4
|
+
|
|
5
|
+
Copyright © 1991-2026 Unicode, Inc.
|
|
6
|
+
|
|
7
|
+
NOTICE TO USER: Carefully read the following legal agreement. BY
|
|
8
|
+
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
|
|
9
|
+
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
|
|
10
|
+
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
|
|
11
|
+
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
14
|
+
copy of data files and any associated documentation (the "Data Files") or
|
|
15
|
+
software and any associated documentation (the "Software") to deal in the
|
|
16
|
+
Data Files or Software without restriction, including without limitation
|
|
17
|
+
the rights to use, copy, modify, merge, publish, distribute, and/or sell
|
|
18
|
+
copies of the Data Files or Software, and to permit persons to whom the
|
|
19
|
+
Data Files or Software are furnished to do so, provided that either (a)
|
|
20
|
+
this copyright and permission notice appear with all copies of the Data
|
|
21
|
+
Files or Software, or (b) this copyright and permission notice appear in
|
|
22
|
+
associated Documentation.
|
|
23
|
+
|
|
24
|
+
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
25
|
+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
26
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
27
|
+
THIRD PARTY RIGHTS.
|
|
28
|
+
|
|
29
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
|
|
30
|
+
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
|
|
31
|
+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
32
|
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
33
|
+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
|
|
34
|
+
FILES OR SOFTWARE.
|
|
35
|
+
|
|
36
|
+
Except as contained in this notice, the name of a copyright holder shall
|
|
37
|
+
not be used in advertising or otherwise to promote the sale, use or other
|
|
38
|
+
dealings in these Data Files or Software without prior written
|
|
39
|
+
authorization of the copyright holder.
|
package/api.mjs
CHANGED
|
@@ -4,29 +4,20 @@ import {loadCore} from './launcher.mjs';
|
|
|
4
4
|
export async function createCompiler() {
|
|
5
5
|
const call = await loadCore();
|
|
6
6
|
return {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
method: 'check',
|
|
13
|
-
}
|
|
14
|
-
),
|
|
15
|
-
expand: (input) =>
|
|
16
|
-
call(
|
|
17
|
-
{
|
|
18
|
-
schemaVersion: input.nativeBindings === undefined ? 3 : 4,
|
|
19
|
-
...input,
|
|
20
|
-
method: 'expand',
|
|
21
|
-
}
|
|
22
|
-
),
|
|
7
|
+
format: (input) => call({schemaVersion: 5, ...input, method: 'format'}),
|
|
8
|
+
check: (input) => call({schemaVersion: 5, ...input, method: 'check'}),
|
|
9
|
+
expand: (input) => call({schemaVersion: 5, ...input, method: 'expand'}),
|
|
10
|
+
proofTasks: (input) =>
|
|
11
|
+
call({schemaVersion: 5, ...input, method: 'proofTasks'}),
|
|
23
12
|
planGeneration: (input) =>
|
|
24
|
-
call(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
),
|
|
13
|
+
call({schemaVersion: 5, ...input, method: 'planGeneration'}),
|
|
14
|
+
migrationBaseline: (input) =>
|
|
15
|
+
call({schemaVersion: 5, ...input, method: 'migrationBaseline'}),
|
|
16
|
+
migrationComparison: (input) =>
|
|
17
|
+
call({schemaVersion: 5, ...input, method: 'migrationComparison'}),
|
|
18
|
+
migrationBindings: (input) =>
|
|
19
|
+
call({schemaVersion: 5, ...input, method: 'migrationBindings'}),
|
|
20
|
+
migrationGeneration: (input) =>
|
|
21
|
+
call({schemaVersion: 5, ...input, method: 'migrationGeneration'}),
|
|
31
22
|
};
|
|
32
23
|
}
|