Fix tests and parser

This commit is contained in:
Jeff 2024-03-17 09:54:15 -04:00
parent 765decdd41
commit 062a3b606c

View File

@ -179,14 +179,14 @@ pub fn parser<'src>() -> DustParser<'src> {
let function = identifier let function = identifier
.clone() .clone()
.then(r#type.clone()) .then(type_specification.clone())
.separated_by(just(Token::Control(Control::Comma))) .separated_by(just(Token::Control(Control::Comma)))
.collect() .collect()
.delimited_by( .delimited_by(
just(Token::Control(Control::ParenOpen)), just(Token::Control(Control::ParenOpen)),
just(Token::Control(Control::ParenClose)), just(Token::Control(Control::ParenClose)),
) )
.then(r#type.clone()) .then(type_specification.clone())
.then(block.clone()) .then(block.clone())
.map_with(|((parameters, return_type), body), state| { .map_with(|((parameters, return_type), body), state| {
Expression::Value(ValueNode::Function { Expression::Value(ValueNode::Function {
@ -432,7 +432,7 @@ mod tests {
#[test] #[test]
fn r#while() { fn r#while() {
assert_eq!( assert_eq!(
parse(&lex("while true { output('hi') }").unwrap()).unwrap()[0], parse(&lex("while true { output('hi') }").unwrap()).unwrap()[0].node,
Statement::While(While::new( Statement::While(While::new(
Expression::Value(ValueNode::Boolean(true)).with_position((6, 11)), Expression::Value(ValueNode::Boolean(true)).with_position((6, 11)),
Block::new(vec![Statement::Expression(Expression::FunctionCall( Block::new(vec![Statement::Expression(Expression::FunctionCall(
@ -444,14 +444,13 @@ mod tests {
)) ))
.with_position((13, 26))]) .with_position((13, 26))])
)) ))
.with_position((0, 27))
) )
} }
#[test] #[test]
fn boolean_type() { fn boolean_type() {
assert_eq!( assert_eq!(
parse(&lex("foobar : bool = true").unwrap()).unwrap()[0], parse(&lex("foobar : bool = true").unwrap()).unwrap()[0].node,
Statement::Assignment(Assignment::new( Statement::Assignment(Assignment::new(
Identifier::new("foobar"), Identifier::new("foobar"),
Some(Type::Boolean.with_position((9, 14))), Some(Type::Boolean.with_position((9, 14))),
@ -459,14 +458,27 @@ mod tests {
Statement::Expression(Expression::Value(ValueNode::Boolean(true))) Statement::Expression(Expression::Value(ValueNode::Boolean(true)))
.with_position((16, 20)) .with_position((16, 20))
),) ),)
.with_position((0, 20)) );
}
#[test]
fn list_type() {
assert_eq!(
parse(&lex("foobar: list = []").unwrap()).unwrap()[0].node,
Statement::Assignment(Assignment::new(
Identifier::new("foobar"),
Some(Type::List.with_position((8, 13))),
AssignmentOperator::Assign,
Statement::Expression(Expression::Value(ValueNode::List(vec![])))
.with_position((15, 17))
),)
); );
} }
#[test] #[test]
fn list_of_type() { fn list_of_type() {
assert_eq!( assert_eq!(
parse(&lex("foobar : list(bool) = [true]").unwrap()).unwrap()[0], parse(&lex("foobar : list(bool) = [true]").unwrap()).unwrap()[0].node,
Statement::Assignment(Assignment::new( Statement::Assignment(Assignment::new(
Identifier::new("foobar"), Identifier::new("foobar"),
Some(Type::ListOf(Box::new(Type::Boolean)).with_position((9, 20))), Some(Type::ListOf(Box::new(Type::Boolean)).with_position((9, 20))),
@ -477,7 +489,6 @@ mod tests {
.with_position((23, 27))]))) .with_position((23, 27))])))
.with_position((22, 28)) .with_position((22, 28))
)) ))
.with_position((0, 28))
); );
} }
@ -502,7 +513,7 @@ mod tests {
#[test] #[test]
fn function_type() { fn function_type() {
assert_eq!( assert_eq!(
parse(&lex("foobar : () -> any = some_function").unwrap()).unwrap()[0], parse(&lex("foobar : () -> any = some_function").unwrap()).unwrap()[0].node,
Statement::Assignment(Assignment::new( Statement::Assignment(Assignment::new(
Identifier::new("foobar"), Identifier::new("foobar"),
Some( Some(
@ -516,165 +527,154 @@ mod tests {
Statement::Expression(Expression::Identifier(Identifier::new("some_function"))) Statement::Expression(Expression::Identifier(Identifier::new("some_function")))
.with_position((21, 34)) .with_position((21, 34))
),) ),)
.with_position((0, 34))
); );
} }
#[test] #[test]
fn function_call() { fn function_call() {
assert_eq!( assert_eq!(
parse(&lex("output()").unwrap()).unwrap()[0], parse(&lex("output()").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::FunctionCall(FunctionCall::new( Statement::Expression(Expression::FunctionCall(FunctionCall::new(
Expression::Identifier(Identifier::new("output")).with_position((0, 6)), Expression::Identifier(Identifier::new("output")).with_position((0, 6)),
Vec::with_capacity(0), Vec::with_capacity(0),
))) )))
.with_position((0, 8))
) )
} }
#[test] #[test]
fn range() { fn range() {
assert_eq!( assert_eq!(
parse(&lex("1, 10").unwrap()).unwrap()[0], parse(&lex("1..10").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Range(1..10))).with_position((0, 5)) Statement::Expression(Expression::Value(ValueNode::Range(1..10)))
) )
} }
#[test] #[test]
fn function() { fn function() {
assert_eq!( assert_eq!(
parse(&lex("(x: int): int { x }").unwrap()).unwrap()[0], parse(&lex("(x: int) : int { x }").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Function { Statement::Expression(Expression::Value(ValueNode::Function {
parameters: vec![(Identifier::new("x"), Type::Integer.with_position((0, 0)))], parameters: vec![(Identifier::new("x"), Type::Integer.with_position((4, 7)))],
return_type: Type::Integer.with_position((0, 0)), return_type: Type::Integer.with_position((11, 15)),
body: Block::new(vec![Statement::Expression(Expression::Identifier( body: Block::new(vec![Statement::Expression(Expression::Identifier(
Identifier::new("x") Identifier::new("x")
),) ),)
.with_position((0, 0))]) .with_position((17, 18))])
.with_position((0, 0)) .with_position((0, 20))
}),) }),)
.with_position((0, 0))
) )
} }
#[test] #[test]
fn r#if() { fn r#if() {
assert_eq!( assert_eq!(
parse(&lex("if true { 'foo' }").unwrap()).unwrap()[0], parse(&lex("if true { 'foo' }").unwrap()).unwrap()[0].node,
Statement::IfElse(IfElse::new( Statement::IfElse(IfElse::new(
Expression::Value(ValueNode::Boolean(true)).with_position((0, 0)), Expression::Value(ValueNode::Boolean(true)).with_position((3, 8)),
Block::new(vec![Statement::Expression(Expression::Value( Block::new(vec![Statement::Expression(Expression::Value(
ValueNode::String("foo".to_string()) ValueNode::String("foo".to_string())
),) ),)
.with_position((0, 0))]) .with_position((10, 15))])
.with_position((0, 0)), .with_position((8, 17)),
None None
),) ),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn if_else() { fn if_else() {
assert_eq!( assert_eq!(
parse(&lex("if true {'foo' } else { 'bar' }").unwrap()).unwrap()[0], parse(&lex("if true {'foo' } else { 'bar' }").unwrap()).unwrap()[0].node,
Statement::IfElse(IfElse::new( Statement::IfElse(IfElse::new(
Expression::Value(ValueNode::Boolean(true)).with_position((0, 0)), Expression::Value(ValueNode::Boolean(true)).with_position((3, 8)),
Block::new(vec![Statement::Expression(Expression::Value( Block::new(vec![Statement::Expression(Expression::Value(
ValueNode::String("foo".to_string()) ValueNode::String("foo".to_string())
),) ),)
.with_position((0, 0))]) .with_position((9, 14))])
.with_position((0, 0)), .with_position((8, 17)),
Some( Some(
Block::new(vec![Statement::Expression(Expression::Value( Block::new(vec![Statement::Expression(Expression::Value(
ValueNode::String("bar".to_string()) ValueNode::String("bar".to_string())
),) ),)
.with_position((0, 0))]) .with_position((24, 29))])
.with_position((0, 0)) .with_position((22, 31))
) )
),) ),)
.with_position((0, 0))
) )
} }
#[test] #[test]
fn map() { fn map() {
assert_eq!( assert_eq!(
parse(&lex("{ foo = 'bar' }").unwrap()).unwrap()[0], parse(&lex("{ foo = 'bar' }").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Map(vec![( Statement::Expression(Expression::Value(ValueNode::Map(vec![(
Identifier::new("foo"), Identifier::new("foo"),
None, None,
Expression::Value(ValueNode::String("bar".to_string())).with_position((0, 0)) Expression::Value(ValueNode::String("bar".to_string())).with_position((8, 13))
)])),) )])),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("{ x = 1, y = 2, }").unwrap()).unwrap()[0], parse(&lex("{ x = 1, y = 2, }").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Map(vec![ Statement::Expression(Expression::Value(ValueNode::Map(vec![
( (
Identifier::new("x"), Identifier::new("x"),
None, None,
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)) Expression::Value(ValueNode::Integer(1)).with_position((6, 7))
), ),
( (
Identifier::new("y"), Identifier::new("y"),
None, None,
Expression::Value(ValueNode::Integer(2)).with_position((0, 0)) Expression::Value(ValueNode::Integer(2)).with_position((13, 14))
), ),
])),) ])),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("{ x = 1 y = 2 }").unwrap()).unwrap()[0], parse(&lex("{ x = 1 y = 2 }").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Map(vec![ Statement::Expression(Expression::Value(ValueNode::Map(vec![
( (
Identifier::new("x"), Identifier::new("x"),
None, None,
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)) Expression::Value(ValueNode::Integer(1)).with_position((6, 7))
), ),
( (
Identifier::new("y"), Identifier::new("y"),
None, None,
Expression::Value(ValueNode::Integer(2)).with_position((0, 0)) Expression::Value(ValueNode::Integer(2)).with_position((12, 13))
), ),
])),) ])),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn math() { fn math() {
assert_eq!( assert_eq!(
parse(&lex("1 + 1").unwrap()).unwrap()[0], parse(&lex("1 + 1").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Math(Box::new(Math::Add( Statement::Expression(Expression::Math(Box::new(Math::Add(
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)), Expression::Value(ValueNode::Integer(1)).with_position((0, 1)),
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)) Expression::Value(ValueNode::Integer(1)).with_position((4, 5))
))),) ))),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn r#loop() { fn r#loop() {
assert_eq!( assert_eq!(
parse(&lex("loop { 42 }").unwrap()).unwrap()[0], parse(&lex("loop { 42 }").unwrap()).unwrap()[0].node,
Statement::Loop(Loop::new(vec![Statement::Expression(Expression::Value( Statement::Loop(Loop::new(vec![Statement::Expression(Expression::Value(
ValueNode::Integer(42) ValueNode::Integer(42)
),) ),)
.with_position((0, 0))]),) .with_position((7, 9))]),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn block() { fn block() {
assert_eq!( assert_eq!(
parse(&lex("{ x }").unwrap()).unwrap()[0], parse(&lex("{ x }").unwrap()).unwrap()[0].node,
Statement::Block(Block::new(vec![Statement::Expression( Statement::Block(Block::new(vec![Statement::Expression(
Expression::Identifier(Identifier::new("x")), Expression::Identifier(Identifier::new("x")),
) )
.with_position((0, 0))]),) .with_position((2, 3))]),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
@ -688,16 +688,16 @@ mod tests {
") ")
.unwrap() .unwrap()
) )
.unwrap()[0], .unwrap()[0]
.node,
Statement::Block(Block::new(vec![ Statement::Block(Block::new(vec![
Statement::Expression(Expression::Identifier(Identifier::new("x"))) Statement::Expression(Expression::Identifier(Identifier::new("x")))
.with_position((0, 0)), .with_position((39, 40)),
Statement::Expression(Expression::Identifier(Identifier::new("y"))) Statement::Expression(Expression::Identifier(Identifier::new("y")))
.with_position((0, 0)), .with_position((62, 63)),
Statement::Expression(Expression::Identifier(Identifier::new("z"))) Statement::Expression(Expression::Identifier(Identifier::new("z")))
.with_position((0, 0)), .with_position((85, 86)),
]),) ]),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
@ -710,264 +710,205 @@ mod tests {
") ")
.unwrap() .unwrap()
) )
.unwrap()[0], .unwrap()[0]
.node,
Statement::Block(Block::new(vec![ Statement::Block(Block::new(vec![
Statement::Expression(Expression::Logic(Box::new(Logic::Equal( Statement::Expression(Expression::Logic(Box::new(Logic::Equal(
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)), Expression::Value(ValueNode::Integer(1)).with_position((39, 40)),
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)) Expression::Value(ValueNode::Integer(1)).with_position((44, 45))
))),) ))),)
.with_position((0, 0)), .with_position((39, 45)),
Statement::Expression(Expression::Identifier(Identifier::new("z"))) Statement::Expression(Expression::Identifier(Identifier::new("z")))
.with_position((0, 0)), .with_position((66, 67)),
]),) ]),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn identifier() { fn identifier() {
assert_eq!( assert_eq!(
parse(&lex("x").unwrap()).unwrap()[0], parse(&lex("x").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Identifier(Identifier::new("x"))) Statement::Expression(Expression::Identifier(Identifier::new("x")))
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("foobar").unwrap()).unwrap()[0], parse(&lex("foobar").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Identifier(Identifier::new("foobar"))) Statement::Expression(Expression::Identifier(Identifier::new("foobar")))
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("HELLO").unwrap()).unwrap()[0], parse(&lex("HELLO").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Identifier(Identifier::new("HELLO"))) Statement::Expression(Expression::Identifier(Identifier::new("HELLO")))
.with_position((0, 0))
); );
} }
#[test] #[test]
fn assignment() { fn assignment() {
assert_eq!( assert_eq!(
parse(&lex("foobar = 1").unwrap()).unwrap()[0], parse(&lex("foobar = 1").unwrap()).unwrap()[0].node,
Statement::Assignment(Assignment::new( Statement::Assignment(Assignment::new(
Identifier::new("foobar"), Identifier::new("foobar"),
None, None,
AssignmentOperator::Assign, AssignmentOperator::Assign,
Statement::Expression(Expression::Value(ValueNode::Integer(1))) Statement::Expression(Expression::Value(ValueNode::Integer(1)))
.with_position((0, 0)) .with_position((9, 10))
),) ),)
.with_position((0, 0)),
); );
} }
#[test] #[test]
fn assignment_with_basic_type() { fn assignment_with_type() {
assert_eq!( assert_eq!(
parse(&lex("foobar: int = 1").unwrap()).unwrap()[0], parse(&lex("foobar: int = 1").unwrap()).unwrap()[0].node,
Statement::Assignment(Assignment::new( Statement::Assignment(Assignment::new(
Identifier::new("foobar"), Identifier::new("foobar"),
Some(Type::Integer.with_position((0, 0))), Some(Type::Integer.with_position((8, 12))),
AssignmentOperator::Assign, AssignmentOperator::Assign,
Statement::Expression(Expression::Value(ValueNode::Integer(1))) Statement::Expression(Expression::Value(ValueNode::Integer(1)))
.with_position((0, 0)) .with_position((14, 15))
),) ),)
.with_position((0, 0)),
);
}
#[test]
fn assignment_with_list_types() {
assert_eq!(
parse(&lex("foobar: list = []").unwrap()).unwrap()[0],
Statement::Assignment(Assignment::new(
Identifier::new("foobar"),
Some(Type::List.with_position((0, 0))),
AssignmentOperator::Assign,
Statement::Expression(Expression::Value(ValueNode::List(vec![])))
.with_position((0, 0))
),)
.with_position((0, 0)),
);
assert_eq!(
parse(&lex("foobar: list(int) = []").unwrap()).unwrap()[0],
Statement::Assignment(Assignment::new(
Identifier::new("foobar"),
Some(Type::ListOf(Box::new(Type::Integer)).with_position((0, 0))),
AssignmentOperator::Assign,
Statement::Expression(Expression::Value(ValueNode::List(vec![])))
.with_position((0, 0))
),)
.with_position((0, 0)),
);
assert_eq!(
parse(&lex("foobar: [int, str] = [ 42, 'foo' ]").unwrap()).unwrap()[0],
Statement::Assignment(Assignment::new(
Identifier::new("foobar"),
Some(Type::ListExact(vec![Type::Integer, Type::String]).with_position((0, 0))),
AssignmentOperator::Assign,
Statement::Expression(Expression::Value(ValueNode::List(vec![
Expression::Value(ValueNode::Integer(42)).with_position((0, 0)),
Expression::Value(ValueNode::String("foo".to_string())).with_position((0, 0)),
])),)
.with_position((0, 0))
),)
.with_position((0, 0)),
); );
} }
#[test] #[test]
fn logic() { fn logic() {
assert_eq!( assert_eq!(
parse(&lex("x == 1").unwrap()).unwrap()[0], parse(&lex("x == 1").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Logic(Box::new(Logic::Equal( Statement::Expression(Expression::Logic(Box::new(Logic::Equal(
Expression::Identifier(Identifier::new("x")).with_position((0, 0)), Expression::Identifier(Identifier::new("x")).with_position((0, 1)),
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)), Expression::Value(ValueNode::Integer(1)).with_position((5, 6)),
))),) ))),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("(x == 1) && (y == 2)").unwrap()).unwrap()[0], parse(&lex("(x == 1) && (y == 2)").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Logic(Box::new(Logic::And( Statement::Expression(Expression::Logic(Box::new(Logic::And(
Expression::Logic(Box::new(Logic::Equal( Expression::Logic(Box::new(Logic::Equal(
Expression::Identifier(Identifier::new("x")).with_position((0, 0)), Expression::Identifier(Identifier::new("x")).with_position((1, 2)),
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)), Expression::Value(ValueNode::Integer(1)).with_position((6, 7)),
))) )))
.with_position((0, 0)), .with_position((1, 7)),
Expression::Logic(Box::new(Logic::Equal( Expression::Logic(Box::new(Logic::Equal(
Expression::Identifier(Identifier::new("y")).with_position((0, 0)), Expression::Identifier(Identifier::new("y")).with_position((13, 14)),
Expression::Value(ValueNode::Integer(2)).with_position((0, 0)), Expression::Value(ValueNode::Integer(2)).with_position((18, 19)),
))) )))
.with_position((0, 0)), .with_position((13, 19)),
))),) ))),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("(x == 1) && (y == 2) && true").unwrap()).unwrap()[0], parse(&lex("(x == 1) && (y == 2) && true").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Logic(Box::new(Logic::And( Statement::Expression(Expression::Logic(Box::new(Logic::And(
Expression::Logic(Box::new(Logic::And( Expression::Logic(Box::new(Logic::And(
Expression::Logic(Box::new(Logic::Equal( Expression::Logic(Box::new(Logic::Equal(
Expression::Identifier(Identifier::new("x")).with_position((0, 0)), Expression::Identifier(Identifier::new("x")).with_position((1, 2)),
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)) Expression::Value(ValueNode::Integer(1)).with_position((6, 7))
))) )))
.with_position((0, 0)), .with_position((1, 7)),
Expression::Logic(Box::new(Logic::Equal( Expression::Logic(Box::new(Logic::Equal(
Expression::Identifier(Identifier::new("y")).with_position((0, 0)), Expression::Identifier(Identifier::new("y")).with_position((13, 14)),
Expression::Value(ValueNode::Integer(2)).with_position((0, 0)) Expression::Value(ValueNode::Integer(2)).with_position((18, 19))
))) )))
.with_position((0, 0)), .with_position((13, 19)),
))) )))
.with_position((0, 0)), .with_position((0, 21)),
Expression::Value(ValueNode::Boolean(true)).with_position((0, 0)) Expression::Value(ValueNode::Boolean(true)).with_position((24, 28))
))),) ))),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn list() { fn list() {
assert_eq!( assert_eq!(
parse(&lex("[]").unwrap()).unwrap()[0], parse(&lex("[]").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::List(Vec::with_capacity(0))),) Statement::Expression(Expression::Value(ValueNode::List(Vec::with_capacity(0))),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("[42]").unwrap()).unwrap()[0], parse(&lex("[42]").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::List(vec![Expression::Value( Statement::Expression(Expression::Value(ValueNode::List(vec![Expression::Value(
ValueNode::Integer(42) ValueNode::Integer(42)
) )
.with_position((0, 0))])),) .with_position((1, 3))])),)
.with_position((0, 0))
); );
assert_eq!( assert_eq!(
parse(&lex("[42, 'foo', 'bar', [1, 2, 3,]]").unwrap()).unwrap()[0], parse(&lex("[42, 'foo', 'bar', [1, 2, 3,]]").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::List(vec![ Statement::Expression(Expression::Value(ValueNode::List(vec![
Expression::Value(ValueNode::Integer(42)).with_position((0, 0)), Expression::Value(ValueNode::Integer(42)).with_position((1, 3)),
Expression::Value(ValueNode::String("foo".to_string())).with_position((0, 0)), Expression::Value(ValueNode::String("foo".to_string())).with_position((5, 10)),
Expression::Value(ValueNode::String("bar".to_string())).with_position((0, 0)), Expression::Value(ValueNode::String("bar".to_string())).with_position((12, 17)),
Expression::Value(ValueNode::List(vec![ Expression::Value(ValueNode::List(vec![
Expression::Value(ValueNode::Integer(1)).with_position((0, 0)), Expression::Value(ValueNode::Integer(1)).with_position((20, 21)),
Expression::Value(ValueNode::Integer(2)).with_position((0, 0)), Expression::Value(ValueNode::Integer(2)).with_position((23, 24)),
Expression::Value(ValueNode::Integer(3)).with_position((0, 0)), Expression::Value(ValueNode::Integer(3)).with_position((26, 27)),
])) ]))
.with_position((0, 0)) .with_position((19, 29))
])),) ])),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn r#true() { fn r#true() {
assert_eq!( assert_eq!(
parse(&lex("true").unwrap()).unwrap()[0], parse(&lex("true").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Boolean(true))) Statement::Expression(Expression::Value(ValueNode::Boolean(true)))
.with_position((0, 0))
); );
} }
#[test] #[test]
fn r#false() { fn r#false() {
assert_eq!( assert_eq!(
parse(&lex("false").unwrap()).unwrap()[0], parse(&lex("false").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Boolean(false))) Statement::Expression(Expression::Value(ValueNode::Boolean(false)))
.with_position((0, 0))
); );
} }
#[test] #[test]
fn positive_float() { fn positive_float() {
assert_eq!( assert_eq!(
parse(&lex("0").unwrap()).unwrap()[0], parse(&lex("0.0").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(0.0))).with_position((0, 0)) Statement::Expression(Expression::Value(ValueNode::Float(0.0)))
); );
assert_eq!( assert_eq!(
parse(&lex("42").unwrap()).unwrap()[0], parse(&lex("42.0").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(42.0))).with_position((0, 0)) Statement::Expression(Expression::Value(ValueNode::Float(42.0)))
); );
let max_float = f64::MAX.to_string() + ".0"; let max_float = f64::MAX.to_string() + ".0";
assert_eq!( assert_eq!(
parse(&lex(&max_float).unwrap()).unwrap()[0], parse(&lex(&max_float).unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(f64::MAX))) Statement::Expression(Expression::Value(ValueNode::Float(f64::MAX)))
.with_position((0, 0))
); );
let min_positive_float = f64::MIN_POSITIVE.to_string(); let min_positive_float = f64::MIN_POSITIVE.to_string();
assert_eq!( assert_eq!(
parse(&lex(&min_positive_float).unwrap()).unwrap()[0], parse(&lex(&min_positive_float).unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(f64::MIN_POSITIVE)),) Statement::Expression(Expression::Value(ValueNode::Float(f64::MIN_POSITIVE)),)
.with_position((0, 0))
); );
} }
#[test] #[test]
fn negative_float() { fn negative_float() {
assert_eq!( assert_eq!(
parse(&lex("-0.0").unwrap()).unwrap()[0], parse(&lex("-0.0").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(-0.0))).with_position((0, 0)) Statement::Expression(Expression::Value(ValueNode::Float(-0.0)))
); );
assert_eq!( assert_eq!(
parse(&lex("-42.0").unwrap()).unwrap()[0], parse(&lex("-42.0").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(-42.0))).with_position((0, 0)) Statement::Expression(Expression::Value(ValueNode::Float(-42.0)))
); );
let min_float = f64::MIN.to_string() + ".0"; let min_float = f64::MIN.to_string() + ".0";
assert_eq!( assert_eq!(
parse(&lex(&min_float).unwrap()).unwrap()[0], parse(&lex(&min_float).unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(f64::MIN))) Statement::Expression(Expression::Value(ValueNode::Float(f64::MIN)))
.with_position((0, 0))
); );
let max_negative_float = format!("-{}", f64::MIN_POSITIVE); let max_negative_float = format!("-{}", f64::MIN_POSITIVE);
assert_eq!( assert_eq!(
parse(&lex(&max_negative_float).unwrap()).unwrap()[0], parse(&lex(&max_negative_float).unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Float(-f64::MIN_POSITIVE)),) Statement::Expression(Expression::Value(ValueNode::Float(-f64::MIN_POSITIVE)),)
.with_position((0, 0))
); );
} }
@ -1031,8 +972,8 @@ mod tests {
} }
assert_eq!( assert_eq!(
parse(&lex("-42").unwrap()).unwrap()[0], parse(&lex("-42").unwrap()).unwrap()[0].node,
Statement::Expression(Expression::Value(ValueNode::Integer(-42))).with_position((0, 0)) Statement::Expression(Expression::Value(ValueNode::Integer(-42)))
); );
let minimum_integer = i64::MIN.to_string(); let minimum_integer = i64::MIN.to_string();