Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kindywu committed Aug 2, 2024
1 parent 9c4c2b1 commit 37bf3c9
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions examples/expect_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ use winnow::{
const CRLF: &[u8] = b"\r\n";

fn main() {
// let buf = b"+OK\r\n";
// expect_length(buf).unwrap();
// let buf = b"+OK\r";
// println!("{:?}", expect_length(buf));

// let buf = b"$5\r\nhello\r\n";
// expect_length(buf).unwrap();

// let buf = b"$-1\r\n";
// expect_length(buf).unwrap();
// let buf = b"$0\r\n";
// expect_length(buf).unwrap();
// let buf = b"$5\r\nhello\r\n";
// expect_length(buf).unwrap();
// let buf = b"$5\r\nhello\r";
// println!("{:?}", expect_length(buf));

// let buf = b"*-1\r\n";
// expect_length(buf).unwrap();
// let buf = b"*0\r\n";
// expect_length(buf).unwrap();
// let buf = b"*2\r\n$4\r\necho\r\n$5\r\nhello\r\n";
// expect_length(buf).unwrap();
let buf = b"+OK\r\n";
expect_length(buf).unwrap();
let buf = b"+OK\r";
println!("{:?}", expect_length(buf));

let buf = b"$5\r\nhello\r\n";
expect_length(buf).unwrap();

let buf = b"$-1\r\n";
expect_length(buf).unwrap();
let buf = b"$0\r\n\r\n";
expect_length(buf).unwrap();
let buf = b"$5\r\nhello\r\n";
expect_length(buf).unwrap();
let buf = b"$5\r\nhello\r";
println!("{:?}", expect_length(buf));

let buf = b"*-1\r\n";
expect_length(buf).unwrap();
let buf = b"*0\r\n";
expect_length(buf).unwrap();
let buf = b"*2\r\n$4\r\necho\r\n$5\r\nhello\r\n";
expect_length(buf).unwrap();

let buf = b"%2\r\n+hello\r\n$5\r\nworld\r\n+foo\r\n$3\r\nbar\r\n";
expect_length(buf).unwrap();
Expand Down Expand Up @@ -164,6 +164,14 @@ fn cal_map(input: &[u8]) -> PResult<(&[u8], usize)> {
mod test {
use super::*;

#[test]
fn cal_crlf_should_fail() -> PResult<()> {
let buf = b"abc";
let result = cal_crlf(buf);
assert!(result.is_err());
Ok(())
}

#[test]
fn cal_crlf_should_work() -> PResult<()> {
let buf = b"\r\n";
Expand Down

0 comments on commit 37bf3c9

Please sign in to comment.