mirror of
https://github.com/danog/parser.git
synced 2025-01-22 13:01:32 +01:00
parser: add tests for param types
This commit is contained in:
parent
cb2fb3b8c9
commit
401ea81a5e
@ -493,7 +493,7 @@ impl Display for ParseError {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use trunk_lexer::Lexer;
|
||||
use crate::{Statement, Param, Expression, ast::{InfixOp}};
|
||||
use crate::{Statement, Param, Expression, ast::{InfixOp}, Type};
|
||||
use super::Parser;
|
||||
|
||||
macro_rules! function {
|
||||
@ -678,6 +678,77 @@ mod tests {
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_typestrings_test() {
|
||||
assert_ast("<?php function foo(string $b) {}", &[
|
||||
Statement::Function {
|
||||
name: "foo".to_string().into(),
|
||||
params: vec![
|
||||
Param {
|
||||
name: Expression::Variable("b".into()),
|
||||
r#type: Some(Type::Plain("string".into()))
|
||||
}
|
||||
],
|
||||
body: vec![]
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nullable_typestrings_test() {
|
||||
assert_ast("<?php function foo(?string $b) {}", &[
|
||||
Statement::Function {
|
||||
name: "foo".to_string().into(),
|
||||
params: vec![
|
||||
Param {
|
||||
name: Expression::Variable("b".into()),
|
||||
r#type: Some(Type::Nullable("string".into()))
|
||||
}
|
||||
],
|
||||
body: vec![]
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn union_typestrings_test() {
|
||||
assert_ast("<?php function foo(int|float $b) {}", &[
|
||||
Statement::Function {
|
||||
name: "foo".to_string().into(),
|
||||
params: vec![
|
||||
Param {
|
||||
name: Expression::Variable("b".into()),
|
||||
r#type: Some(Type::Union(vec![
|
||||
"int".into(),
|
||||
"float".into()
|
||||
]))
|
||||
}
|
||||
],
|
||||
body: vec![]
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersection_typestrings_test() {
|
||||
assert_ast("<?php function foo(Foo&Bar $b) {}", &[
|
||||
Statement::Function {
|
||||
name: "foo".to_string().into(),
|
||||
params: vec![
|
||||
Param {
|
||||
name: Expression::Variable("b".into()),
|
||||
r#type: Some(Type::Intersection(vec![
|
||||
"Foo".into(),
|
||||
"Bar".into()
|
||||
]))
|
||||
}
|
||||
],
|
||||
body: vec![]
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn noop() {
|
||||
assert_ast("<?php ;", &[
|
||||
|
Loading…
x
Reference in New Issue
Block a user