Skip to content

Commit

Permalink
fix: split_by_ascii_whitespace (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang authored May 23, 2023
1 parent 11e0ebc commit 1820e9c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions snark-verifier/src/loader/evm/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,10 @@ pub fn compile_yul(code: &str) -> Vec<u8> {
.arg("-")
.spawn()
.unwrap();
cmd.stdin
.take()
.unwrap()
.write_all(code.as_bytes())
.unwrap();
cmd.stdin.take().unwrap().write_all(code.as_bytes()).unwrap();
let output = cmd.wait_with_output().unwrap().stdout;
let binary = *split_by_ascii_whitespace(&output).last().unwrap();
assert!(!binary.is_empty());
hex::decode(binary).unwrap()
}

Expand All @@ -136,5 +133,22 @@ fn split_by_ascii_whitespace(bytes: &[u8]) -> Vec<&[u8]> {
start = Some(idx);
}
}
if let Some(last) = start {
split.push(&bytes[last..]);
}
split
}

#[test]
fn test_split_by_ascii_whitespace_1() {
let bytes = b" \x01 \x02 \x03";
let split = split_by_ascii_whitespace(bytes);
assert_eq!(split, [b"\x01", b"\x02", b"\x03"]);
}

#[test]
fn test_split_by_ascii_whitespace_2() {
let bytes = b"123456789abc";
let split = split_by_ascii_whitespace(bytes);
assert_eq!(split, [b"123456789abc"]);
}

0 comments on commit 1820e9c

Please sign in to comment.