fix(parser::ast_builder): test
This commit is contained in:
parent
c35996c0d4
commit
c4f2288861
src/parser
|
@ -23,11 +23,6 @@ fn rational_one() -> Rational {
|
|||
Rational::new(1, 1)
|
||||
}
|
||||
|
||||
fn rational_minus_one() -> Rational {
|
||||
Rational::new(-1, 1)
|
||||
}
|
||||
|
||||
|
||||
fn zero() -> GaussianRational {
|
||||
GaussianRational::new(rational_zero(), rational_zero())
|
||||
}
|
||||
|
@ -36,26 +31,14 @@ fn one() -> GaussianRational {
|
|||
GaussianRational::new(rational_one(), rational_zero())
|
||||
}
|
||||
|
||||
fn minus_one() -> GaussianRational {
|
||||
GaussianRational::new(rational_minus_one(), rational_zero())
|
||||
}
|
||||
|
||||
fn i() -> GaussianRational {
|
||||
GaussianRational::new(rational_zero(), rational_one())
|
||||
}
|
||||
|
||||
fn minus_i() -> GaussianRational {
|
||||
GaussianRational::new(rational_zero(), rational_minus_one())
|
||||
}
|
||||
|
||||
fn x() -> Vec<GaussianRational> {
|
||||
vec![zero(), one()]
|
||||
}
|
||||
|
||||
fn minus_x() -> Vec<GaussianRational> {
|
||||
vec![zero(), minus_one()]
|
||||
}
|
||||
|
||||
fn insert_operator_node(mut tokens: Vec<Token>, position: usize) -> Node {
|
||||
let tokens_right = tokens.split_off(position + 1);
|
||||
let token = tokens.pop().unwrap();
|
||||
|
@ -389,15 +372,40 @@ mod tests {
|
|||
#[test]
|
||||
fn negative_one() {
|
||||
let tokens = vec![minus(), one_token()];
|
||||
let results = Node::Leaf(vec![minus_one()]);
|
||||
let results = Node::Unary {
|
||||
operator: minus(),
|
||||
operand: Box::new(Node::Leaf(vec![one()])),
|
||||
};
|
||||
assert_eq!(build_ast(tokens), results);
|
||||
|
||||
let tokens = vec![minus(), x_token()];
|
||||
let results = Node::Leaf(minus_x());
|
||||
let results = Node::Unary {
|
||||
operator: minus(),
|
||||
operand: Box::new(Node::Leaf(x())),
|
||||
};
|
||||
assert_eq!(build_ast(tokens), results);
|
||||
|
||||
let tokens = vec![minus(), i_token()];
|
||||
let results = Node::Leaf(vec![minus_i()]);
|
||||
let results = Node::Unary {
|
||||
operator: minus(),
|
||||
operand: Box::new(Node::Leaf(vec![i()])),
|
||||
};
|
||||
assert_eq!(build_ast(tokens), results);
|
||||
}
|
||||
|
||||
fn negative_parenthesis() {
|
||||
let tokens = vec![minus(), one_token(), times(), open(), one_token(), close()];
|
||||
let results = Node::Binary {
|
||||
operator: times(),
|
||||
lhs: Box::new(Node::Unary {
|
||||
operator: minus(),
|
||||
operand: Box::new(Node::Leaf(vec![one()])),
|
||||
}),
|
||||
rhs: Box::new(Node::Unary {
|
||||
operator: minus(),
|
||||
operand: Box::new(Node::Leaf(vec![one()])),
|
||||
}),
|
||||
};
|
||||
assert_eq!(build_ast(tokens), results);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue