51 lines
1.8 KiB
Rust
51 lines
1.8 KiB
Rust
// expect: run
|
|
// result: 0
|
|
// phase: 6
|
|
// spec: docs/spec/16-standard-library.md §2.6; docs/spec/08-verifier.md §11.2
|
|
module test.text_disjoint
|
|
import std.encoding.hex;
|
|
import std.encoding.base64;
|
|
import std.bytes;
|
|
|
|
fn main() -> u8
|
|
effects []
|
|
{
|
|
var buf: [u8; 16] = [165; 16];
|
|
buf[0] = 0; buf[1] = 127; buf[2] = 128; buf[3] = 255;
|
|
{
|
|
mut all = buf;
|
|
let (src, dst) = all.split_at(4);
|
|
match std.encoding.hex.encode(mut dst, ref src) {
|
|
std.encoding.hex.EncodeResult::ok(count) => { assert(count == 8); }
|
|
std.encoding.hex.EncodeResult::short_output => { trap; }
|
|
}
|
|
}
|
|
assert(std.bytes.equal(ref buf[4..12], b"007f80ff"));
|
|
{
|
|
mut all = buf;
|
|
let (dst, src) = all.split_at(4);
|
|
match std.encoding.hex.decode(mut dst, ref src[0..8]) {
|
|
std.encoding.hex.DecodeResult::ok(count) => { assert(count == 4); }
|
|
std.encoding.hex.DecodeResult::invalid_input => { trap; }
|
|
std.encoding.hex.DecodeResult::short_output => { trap; }
|
|
}
|
|
match std.encoding.base64.encode(mut src, ref dst) {
|
|
std.encoding.base64.EncodeResult::ok(count) => { assert(count == 8); }
|
|
std.encoding.base64.EncodeResult::short_output => { trap; }
|
|
}
|
|
}
|
|
assert(std.bytes.equal(ref buf[4..12], b"AH+A/w=="));
|
|
{
|
|
mut all = buf;
|
|
let (dst, src) = all.split_at(4);
|
|
match std.encoding.base64.decode(mut dst, ref src[0..8]) {
|
|
std.encoding.base64.DecodeResult::ok(count) => { assert(count == 4); }
|
|
std.encoding.base64.DecodeResult::invalid_input => { trap; }
|
|
std.encoding.base64.DecodeResult::short_output => { trap; }
|
|
}
|
|
}
|
|
assert(std.bytes.equal(ref buf[0..4], b"\x00\x7f\x80\xff"));
|
|
for i in 12usize..buf.len { assert(buf[i] == 165); }
|
|
return 0;
|
|
}
|