-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add various specs for slice skip/take
We had several low-level specs, especially in the untyped library, but the typed library was missing many things that seem obvious in retrospect. There are six variants based on how ownership is divided, and it makes sense to provide all of these specs since they are not obvious consequences of more general specs: 1. SliceTake with `own_slice_small`. Straightforward. 2. SliceSkip with `own_slice_small`. Straightforward. 3. SliceTake with `own_slice`. Consumes the remainder of the slice to become the capacity of the prefix. This is the most distant from the code; it is not obvious that the original slice should no longer be used, even for reads. 4. SliceSkip with `own_slice`. The capacity is retained as-is. 5. std.SliceSplit with `own_slice_small`. This is a function in the Goose standard library that makes it easy to specify that doing `s[:n]` and `s[n:]` at the same time splits ownership, in a straightforward way. It is possible but more awkward to do this by directly writing `s[:n]` and `s[n:]` in the code. 6. std.SliceSplit with `own_slice`. Similar to the `own_slice_small` spec, because the capacity of the original slice is identical to the capacity of the skipped part. Splitting in this case allows using the original capacity as the capacity of the `s[n:]` end, while not allowing appending to the `s[:n]` end since this capacity aliases the `s[n:]`.
- Loading branch information
Showing
4 changed files
with
156 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters