1#![warn(rust_2018_idioms)]
2#![cfg(feature = "std")]
3
4use std::io::{BufRead, Read};
5
6use bytes::Buf;
7
8#[test]
9fn read() {
10 let buf1 = &b"hello "[..];
11 let buf2 = &b"world"[..];
12 let buf = Buf::chain(buf1, buf2); // Disambiguate with Read::chain
13 let mut buffer = Vec::new();
14 buf.reader().read_to_end(&mut buffer).unwrap();
15 assert_eq!(b"hello world", &buffer[..]);
16}
17
18#[test]
19fn buf_read() {
20 let buf1 = &b"hell"[..];
21 let buf2 = &b"o\nworld"[..];
22 let mut reader = Buf::chain(buf1, buf2).reader();
23 let mut line = String::new();
24 reader.read_line(&mut line).unwrap();
25 assert_eq!("hello\n", &line);
26 line.clear();
27 reader.read_line(&mut line).unwrap();
28 assert_eq!("world", &line);
29}
30