Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions LICENSES/Go-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2009 The Go Authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 3 additions & 1 deletion Path/Basic.lean
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/-
Lexical path cleaning, as Go's `path.Clean` and `path.Join` do it
(go1.24.7, src/path/path.go). The loop below follows Go's line by
(go1.24.7, src/path/path.go). Derived from `Clean` in src/path/path.go
(go1.24.7); copyright 2009 The Go Authors, under the BSD-3-Clause
license in LICENSES/Go-LICENSE. The loop below follows Go's line by
line. Go writes into a buffer and keeps its length `w`; here the
buffer is a list, kept reversed so that writing and removing at the
end take one step, and `w` is its length. Go reads the input by
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ python3 tests/plant_bugs.py
- `Spec/Defs.lean`: the rules the statements use, written from Go's documentation.
- `Proofs.lean` and `Proofs/`: the proofs.
- `Main.lean`: the command-line tool the tests drive.
- `lakefile.toml`: the build. It names the package and its version, its libraries and executable, and the default targets, and sets nothing else.
- `lakefile.toml`: the build. It names the package, its version and license, its libraries and executable, and the default targets, and sets nothing else.
- `comparator.json`: which theorems `lake comparator` checks, and which axioms it allows.
- `bar.toml`: the record for the bar check: status, authors, approvals, and where things are.
- `SPEC.md`: the specification in plain words.
- `tests/`: the differential tests, the oracles, and the planted bugs.
- `LICENSE`: the Apache License 2.0, for this library's own code and documents.
- `LICENSES/Go-LICENSE`: Go's BSD-3-Clause license, for the material copied from Go (below).

## License

The library's own code and documents are under the Apache License 2.0 (`LICENSE`). Some material is Go's, copyright 2009 The Go Authors, and keeps Go's BSD-3-Clause license (`LICENSES/Go-LICENSE`): the loop in `Path/Basic.lean`, a line-by-line port of `path.Clean`; the test tables `cleantests` and `jointests` from src/path/path_test.go (go1.24.7), copied into `Spec.lean` and `tests/run_tests.py`; and the quotations of Go's documentation in `SPEC.md`, `Spec/Defs.lean`, `Spec.lean` and this page.
2 changes: 1 addition & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Specification: path

Go's documentation of `path.Clean` (https://pkg.go.dev/path#Clean) says it gives "the shortest path name equivalent to path by purely lexical processing". It reads only the string: it never looks at a file system. This library cleans paths by the rules of that documentation, and joins them as `path.Join` does, in Lean, on strings. That the result is the shortest such path is Go's description; it is not a statement here.
Go's documentation of `path.Clean` (https://pkg.go.dev/path#Clean) says it gives "the shortest path name equivalent to path by purely lexical processing". It reads only the string: it never looks at a file system. This library cleans paths by the rules of that documentation, and joins them as `path.Join` does, in Lean, on strings. That the result is the shortest such path is Go's description; it is not a statement here. Quotations of Go's documentation here are copyright 2009 The Go Authors, under the BSD-3-Clause license in `LICENSES/Go-LICENSE`.

A reviewer who did not write this specification approves it. The approval also covers `Spec.lean`, `Spec/Defs.lean`, and the other files that `bar.toml` lists.

Expand Down
13 changes: 8 additions & 5 deletions Spec.lean
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ theorem clean_shape (p : String) (es : List Element)
theorem clean_idem (p : String) : Path.clean (Path.clean p) = Path.clean p := by
sorry

/-- `join`, as Go's documentation says: "Join joins any number of path
elements into a single path, separating them with slashes. Empty
elements are ignored. The result is Cleaned. However, if the
/-- `join`, as Go's documentation says (copyright 2009 The Go Authors,
BSD-3-Clause, see LICENSES/Go-LICENSE): "Join joins any number of
path elements into a single path, separating them with slashes.
Empty elements are ignored. The result is Cleaned. However, if the
argument list is empty or all its elements are empty, Join returns
an empty string." -/
theorem join_eq (es : List String) :
Expand All @@ -77,7 +78,8 @@ theorem join_root_inside (b u : String) (hb : b ≠ "") :
sorry

/-- Go's tests of `Clean`, `cleantests` in src/path/path_test.go
(go1.24.7): each path cleans to its result, and the result cleans
(go1.24.7; copyright 2009 The Go Authors, BSD-3-Clause, see
LICENSES/Go-LICENSE): each path cleans to its result, and the result cleans
to itself. Among them, `//abc` cleans to `/abc`: two slashes at the
start are one slash, though POSIX lets a system give them a meaning
of their own. -/
Expand Down Expand Up @@ -107,7 +109,8 @@ theorem go_clean_tests :
sorry

/-- Go's tests of `Join`, `jointests` in src/path/path_test.go
(go1.24.7), and one more: an empty first element is left out, so
(go1.24.7; copyright 2009 The Go Authors, BSD-3-Clause, see
LICENSES/Go-LICENSE), and one more: an empty first element is left out, so
joining it to a rooted path gives a rooted path. -/
theorem go_join_tests :
∀ t ∈ [
Expand Down
4 changes: 3 additions & 1 deletion Spec/Defs.lean
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/-
The rules of Go's `path.Clean`, written from its documentation
(https://pkg.go.dev/path#Clean, go1.24.7):
(https://pkg.go.dev/path#Clean, go1.24.7). The quoted text is Go's,
copyright 2009 The Go Authors, under the BSD-3-Clause license in
LICENSES/Go-LICENSE:

Clean returns the shortest path name equivalent to path by purely
lexical processing. It applies the following rules iteratively
Expand Down
3 changes: 2 additions & 1 deletion tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def model_join(es):
return model_clean("/".join(kept))


# Go's tests: src/path/path_test.go, go1.24.7.
# Go's tests: src/path/path_test.go, go1.24.7. Copyright 2009 The Go Authors,
# under the BSD-3-Clause license in LICENSES/Go-LICENSE.
GO_CLEAN = [
("", "."), ("abc", "abc"), ("abc/def", "abc/def"), ("a/b/c", "a/b/c"), (".", "."),
("..", ".."), ("../..", "../.."), ("../../abc", "../../abc"), ("/abc", "/abc"), ("/", "/"),
Expand Down