fix: do not panic with zero-sized result
This commit is contained in:
parent
3745b655ba
commit
00dfcdb10c
1 changed files with 12 additions and 2 deletions
|
|
@ -28,8 +28,8 @@ impl Nodes {
|
|||
let len = nodes.len();
|
||||
collapse_toplevel(nodes, len)?;
|
||||
|
||||
match nodes.pop().unwrap() {
|
||||
Node::Number(n) => Ok(n),
|
||||
match nodes.pop() {
|
||||
Some(Node::Number(n)) => Ok(n),
|
||||
_ => Err(Error::CollapseFailed(self)),
|
||||
}
|
||||
}
|
||||
|
|
@ -193,6 +193,8 @@ impl Function {
|
|||
|
||||
#[cfg(test)]
|
||||
use super::PREC;
|
||||
#[cfg(test)]
|
||||
use std::assert_matches;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
|
|
@ -211,3 +213,11 @@ fn test() {
|
|||
1.9092974268256817,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zerosized() {
|
||||
assert_matches!(
|
||||
Nodes(vec![Node::ParenthesisStart, Node::ParenthesisEnd]).evaluate(),
|
||||
Err(Error::CollapseFailed(Nodes(v))) if v.is_empty()
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue