Add test
This commit is contained in:
parent
b66710e3eb
commit
9cb6873618
@ -227,16 +227,7 @@ impl<'src> Parser<'src> {
|
||||
|
||||
fn parse_grouped(&mut self, _allow_assignment: bool) -> Result<(), ParseError> {
|
||||
self.parse_expression()?;
|
||||
|
||||
if self.previous_token == Token::RightParenthesis {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ParseError::ExpectedToken {
|
||||
expected: TokenKind::RightParenthesis,
|
||||
found: self.current_token.to_owned(),
|
||||
position: self.current_position,
|
||||
})
|
||||
}
|
||||
self.expect(TokenKind::RightParenthesis)
|
||||
}
|
||||
|
||||
fn parse_unary(&mut self, _allow_assignment: bool) -> Result<(), ParseError> {
|
||||
|
@ -2,6 +2,30 @@ use crate::Local;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parentheses_precedence() {
|
||||
assert_eq!(
|
||||
parse("(1 + 2) * 3"),
|
||||
Ok(Chunk::with_data(
|
||||
vec![
|
||||
(
|
||||
*Instruction::add(0, 0, 1)
|
||||
.set_first_argument_to_constant()
|
||||
.set_second_argument_to_constant(),
|
||||
Span(3, 4)
|
||||
),
|
||||
(
|
||||
*Instruction::multiply(1, 0, 2).set_second_argument_to_constant(),
|
||||
Span(8, 9)
|
||||
),
|
||||
(Instruction::r#return(), Span(0, 11)),
|
||||
],
|
||||
vec![Value::integer(1), Value::integer(2), Value::integer(3)],
|
||||
vec![]
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_multiply_precedence() {
|
||||
assert_eq!(
|
||||
@ -42,7 +66,7 @@ fn let_statement() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn integer() {
|
||||
fn constant() {
|
||||
assert_eq!(
|
||||
parse("42"),
|
||||
Ok(Chunk::with_data(
|
||||
|
Loading…
Reference in New Issue
Block a user