Use const generics for helper traits (From, PartialEq, PartialOrd) (#284)

This commit is contained in:
Nikolay Kim 2024-01-16 19:18:17 +06:00 committed by GitHub
parent f40608633e
commit d99178519e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 216 additions and 45 deletions

View file

@ -1,6 +1,6 @@
#![deny(warnings, rust_2018_idioms)]
use ntex_bytes::Buf;
use ntex_bytes::{Buf, Bytes, BytesMut};
#[test]
fn test_fresh_cursor_vec() {
@ -20,6 +20,43 @@ fn test_fresh_cursor_vec() {
assert_eq!(buf.chunk(), b"");
}
#[test]
fn test_bytes() {
let mut buf = Bytes::from(b"hello");
assert_eq!(bytes::buf::Buf::remaining(&buf), 5);
assert_eq!(bytes::buf::Buf::chunk(&buf), b"hello");
bytes::buf::Buf::advance(&mut buf, 2);
assert_eq!(bytes::buf::Buf::remaining(&buf), 3);
assert_eq!(bytes::buf::Buf::chunk(&buf), b"llo");
bytes::buf::Buf::advance(&mut buf, 3);
assert_eq!(bytes::buf::Buf::remaining(&buf), 0);
assert_eq!(bytes::buf::Buf::chunk(&buf), b"");
}
#[test]
fn test_bytes_mut() {
let mut buf = BytesMut::from(b"hello");
assert_eq!(bytes::buf::Buf::remaining(&buf), 5);
assert_eq!(bytes::buf::Buf::chunk(&buf), b"hello");
assert_eq!(bytes::buf::BufMut::remaining_mut(&mut buf), 27);
bytes::buf::Buf::advance(&mut buf, 2);
assert_eq!(bytes::buf::Buf::remaining(&buf), 3);
assert_eq!(bytes::buf::Buf::chunk(&buf), b"llo");
bytes::buf::Buf::advance(&mut buf, 3);
assert_eq!(bytes::buf::Buf::remaining(&buf), 0);
assert_eq!(bytes::buf::Buf::chunk(&buf), b"");
}
#[test]
fn test_get_u8() {
let mut buf = &b"\x21zomg"[..];