forked from mirrors/gecko-dev
Differential Revision: https://phabricator.services.mozilla.com/D45719 --HG-- rename : third_party/rust/regex-0.2.2/src/freqs.rs => third_party/rust/aho-corasick/src/byte_frequencies.rs rename : third_party/rust/crc/Cargo.toml => third_party/rust/blake2b_simd/Cargo.toml rename : third_party/rust/miniz_oxide_c_api/LICENSE => third_party/rust/miniz_oxide/LICENSE rename : third_party/rust/redox_users/tests/group => third_party/rust/redox_users/tests/etc/group rename : third_party/rust/redox_users/tests/passwd => third_party/rust/redox_users/tests/etc/passwd rename : third_party/rust/redox_users/tests/shadow => third_party/rust/redox_users/tests/etc/shadow rename : third_party/rust/utf8-ranges/src/lib.rs => third_party/rust/regex-syntax/src/utf8.rs rename : third_party/rust/crossbeam-channel/LICENSE-APACHE => third_party/rust/rust-argon2/LICENSE-APACHE rename : third_party/rust/memchr-1.0.2/COPYING => third_party/rust/winapi-util/COPYING rename : third_party/rust/ucd-util/Cargo.toml => third_party/rust/winapi-util/Cargo.toml rename : third_party/rust/memchr-1.0.2/LICENSE-MIT => third_party/rust/winapi-util/LICENSE-MIT rename : third_party/rust/memchr-1.0.2/UNLICENSE => third_party/rust/winapi-util/UNLICENSE extra : moz-landing-system : lando
59 lines
2 KiB
Rust
59 lines
2 KiB
Rust
use serde_bytes::{ByteBuf, Bytes};
|
|
use serde_test::{assert_de_tokens, assert_ser_tokens, assert_tokens, Token};
|
|
|
|
#[test]
|
|
fn test_bytes() {
|
|
let empty = Bytes::new(&[]);
|
|
assert_tokens(&empty, &[Token::BorrowedBytes(b"")]);
|
|
assert_ser_tokens(&empty, &[Token::Bytes(b"")]);
|
|
assert_ser_tokens(&empty, &[Token::ByteBuf(b"")]);
|
|
assert_de_tokens(&empty, &[Token::BorrowedStr("")]);
|
|
|
|
let buf = vec![65, 66, 67];
|
|
let bytes = Bytes::new(&buf);
|
|
assert_tokens(&bytes, &[Token::BorrowedBytes(b"ABC")]);
|
|
assert_ser_tokens(&bytes, &[Token::Bytes(b"ABC")]);
|
|
assert_ser_tokens(&bytes, &[Token::ByteBuf(b"ABC")]);
|
|
assert_de_tokens(&bytes, &[Token::BorrowedStr("ABC")]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_byte_buf() {
|
|
let empty = ByteBuf::new();
|
|
assert_tokens(&empty, &[Token::BorrowedBytes(b"")]);
|
|
assert_tokens(&empty, &[Token::Bytes(b"")]);
|
|
assert_tokens(&empty, &[Token::ByteBuf(b"")]);
|
|
assert_de_tokens(&empty, &[Token::BorrowedStr("")]);
|
|
assert_de_tokens(&empty, &[Token::Str("")]);
|
|
assert_de_tokens(&empty, &[Token::String("")]);
|
|
assert_de_tokens(&empty, &[Token::Seq { len: None }, Token::SeqEnd]);
|
|
assert_de_tokens(&empty, &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
|
|
|
|
let buf = ByteBuf::from(vec![65, 66, 67]);
|
|
assert_tokens(&buf, &[Token::BorrowedBytes(b"ABC")]);
|
|
assert_tokens(&buf, &[Token::Bytes(b"ABC")]);
|
|
assert_tokens(&buf, &[Token::ByteBuf(b"ABC")]);
|
|
assert_de_tokens(&buf, &[Token::BorrowedStr("ABC")]);
|
|
assert_de_tokens(&buf, &[Token::Str("ABC")]);
|
|
assert_de_tokens(&buf, &[Token::String("ABC")]);
|
|
assert_de_tokens(
|
|
&buf,
|
|
&[
|
|
Token::Seq { len: None },
|
|
Token::U8(65),
|
|
Token::U8(66),
|
|
Token::U8(67),
|
|
Token::SeqEnd,
|
|
],
|
|
);
|
|
assert_de_tokens(
|
|
&buf,
|
|
&[
|
|
Token::Seq { len: Some(3) },
|
|
Token::U8(65),
|
|
Token::U8(66),
|
|
Token::U8(67),
|
|
Token::SeqEnd,
|
|
],
|
|
);
|
|
}
|