cli: add bounded std copy/search and checked arithmetic
This commit is contained in:
36 files changed
+1533
-7
No files matched your search
@@ -0,0 +1,34 @@
|
||||
// expect: run
|
||||
// result: 0
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.4; docs/spec/15-source-language.md §6
|
||||
module test.bounded_split
|
||||
import std.bytes;
|
||||
|
||||
fn check(data: slice<u8>, separator: slice<u8>, expected_left: slice<u8>, expected_right: slice<u8>) -> void
|
||||
effects []
|
||||
{
|
||||
match std.bytes.find_slice(ref data, ref separator) {
|
||||
std.bytes.FindResult::found(index) => {
|
||||
let (left, tail) = data.split_at(index);
|
||||
ref right = tail[separator.len..tail.len];
|
||||
assert(std.bytes.equal(ref left, ref expected_left));
|
||||
assert(std.bytes.equal(ref right, ref expected_right));
|
||||
}
|
||||
std.bytes.FindResult::not_found => { trap; }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> u8
|
||||
effects []
|
||||
{
|
||||
var storage: [u8; 1] = zero;
|
||||
check(b"key=value", b"=", b"key", b"value");
|
||||
check(b"=value", b"=", ref storage[0..0], b"value");
|
||||
check(b"key=", b"=", b"key", ref storage[0..0]);
|
||||
check(b"==", b"=", ref storage[0..0], b"=");
|
||||
check(b"key::value::tail", b"::", b"key", b"value::tail");
|
||||
check(b"abc", ref storage[0..0], ref storage[0..0], b"abc");
|
||||
check(ref storage[0..0], ref storage[0..0], ref storage[0..0], ref storage[0..0]);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user