Skip to content

Commit

Permalink
Merge pull request #334 from Chia-Network/test-api-clippy
Browse files Browse the repository at this point in the history
Resolve clippy warnings for TestAllocator
  • Loading branch information
Rigidity authored Dec 5, 2023
2 parents b7d6812 + 9324704 commit 7f30786
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions clvm-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ pub mod tests {
Pair(Box<TestNode>, Box<TestNode>),
}

#[derive(Default)]
pub struct TestAllocator {
atoms: Vec<Vec<u8>>,
}

impl TestAllocator {
pub fn new() -> Self {
TestAllocator { atoms: vec![] }
TestAllocator::default()
}

fn new_atom(&mut self, buf: &[u8]) -> TestNode {
Expand All @@ -64,18 +65,18 @@ pub mod tests {
(TestNode::Pair(l1, r1), TestNode::Pair(l2, r2)) => {
node_eq(a, l1, l2) && node_eq(a, r1, r2)
}
(_, _) => false,
_ => false,
}
}

pub fn node_to_str(a: &TestAllocator, input: &TestNode) -> String {
match input {
TestNode::Atom(v) => {
let atom = a.atom(*v);
if atom.len() == 0 {
if atom.is_empty() {
"NIL".to_owned()
} else {
format!("{}", &hex::encode(&atom))
hex::encode(atom)
}
}
TestNode::Pair(l, r) => format!("( {} {}", node_to_str(a, l), node_to_str(a, r)),
Expand All @@ -94,15 +95,13 @@ pub mod tests {
let (rest, left) = str_to_node(a, rest);
let (rest, right) = str_to_node(a, rest);
(rest, TestNode::Pair(Box::new(left), Box::new(right)))
} else if first == "NIL" {
(rest, a.new_atom(&[]))
} else {
if first == "NIL" {
(rest, a.new_atom(&[]))
} else {
(
rest,
a.new_atom(hex::decode(first).expect("invalid hex").as_slice()),
)
}
(
rest,
a.new_atom(hex::decode(first).expect("invalid hex").as_slice()),
)
}
}

Expand Down

0 comments on commit 7f30786

Please sign in to comment.