Adjust test
This commit is contained in:
parent
bb53331b65
commit
45384fb394
@ -1,19 +1,27 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tree_sitter::Node;
|
use tree_sitter::Node;
|
||||||
|
|
||||||
use crate::{AbstractTree, Error, Expression, FunctionExpression, Map, Result, Type, Value};
|
use crate::{
|
||||||
|
AbstractTree, Error, Expression, FunctionExpression, Map, Result, SyntaxPosition, Type, Value,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
|
||||||
pub struct FunctionCall {
|
pub struct FunctionCall {
|
||||||
function_expression: FunctionExpression,
|
function_expression: FunctionExpression,
|
||||||
arguments: Vec<Expression>,
|
arguments: Vec<Expression>,
|
||||||
|
syntax_position: SyntaxPosition,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FunctionCall {
|
impl FunctionCall {
|
||||||
pub fn new(function_expression: FunctionExpression, arguments: Vec<Expression>) -> Self {
|
pub fn new(
|
||||||
|
function_expression: FunctionExpression,
|
||||||
|
arguments: Vec<Expression>,
|
||||||
|
syntax_position: SyntaxPosition,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
function_expression,
|
function_expression,
|
||||||
arguments,
|
arguments,
|
||||||
|
syntax_position,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,6 +49,7 @@ impl AbstractTree for FunctionCall {
|
|||||||
Ok(FunctionCall {
|
Ok(FunctionCall {
|
||||||
function_expression,
|
function_expression,
|
||||||
arguments,
|
arguments,
|
||||||
|
syntax_position: node.range().into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +76,10 @@ impl AbstractTree for FunctionCall {
|
|||||||
|
|
||||||
if self.arguments.len() != parameter_types.len() {
|
if self.arguments.len() != parameter_types.len() {
|
||||||
return Err(Error::ExpectedFunctionArgumentAmount {
|
return Err(Error::ExpectedFunctionArgumentAmount {
|
||||||
source: "TODO".to_string(),
|
|
||||||
expected: parameter_types.len(),
|
expected: parameter_types.len(),
|
||||||
actual: self.arguments.len(),
|
actual: self.arguments.len(),
|
||||||
});
|
}
|
||||||
|
.at_source_position(_source, self.syntax_position));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -39,7 +39,7 @@ impl AbstractTree for Yield {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let call = FunctionCall::new(function_expression, arguments);
|
let call = FunctionCall::new(function_expression, arguments, node.range().into());
|
||||||
|
|
||||||
Ok(Yield { call })
|
Ok(Yield { call })
|
||||||
}
|
}
|
||||||
|
12
src/error.rs
12
src/error.rs
@ -77,7 +77,6 @@ pub enum Error {
|
|||||||
|
|
||||||
/// A function was called with the wrong amount of arguments.
|
/// A function was called with the wrong amount of arguments.
|
||||||
ExpectedFunctionArgumentAmount {
|
ExpectedFunctionArgumentAmount {
|
||||||
source: String,
|
|
||||||
expected: usize,
|
expected: usize,
|
||||||
actual: usize,
|
actual: usize,
|
||||||
},
|
},
|
||||||
@ -334,14 +333,9 @@ impl fmt::Display for Error {
|
|||||||
f,
|
f,
|
||||||
"{tool_name} expected {expected} arguments, but got {actual}.",
|
"{tool_name} expected {expected} arguments, but got {actual}.",
|
||||||
),
|
),
|
||||||
ExpectedFunctionArgumentAmount {
|
ExpectedFunctionArgumentAmount { expected, actual } => {
|
||||||
source,
|
write!(f, "Expected {expected} arguments, but got {actual}.",)
|
||||||
expected,
|
}
|
||||||
actual,
|
|
||||||
} => write!(
|
|
||||||
f,
|
|
||||||
"{source} expected {expected} arguments, but got {actual}.",
|
|
||||||
),
|
|
||||||
ExpectedFunctionArgumentMinimum {
|
ExpectedFunctionArgumentMinimum {
|
||||||
source,
|
source,
|
||||||
minumum_expected,
|
minumum_expected,
|
||||||
|
@ -443,22 +443,17 @@ mod type_definition {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn argument_count_check() {
|
fn argument_count_check() {
|
||||||
let result = interpret(
|
let source = "
|
||||||
"
|
|
||||||
foo = (x <int>) <bool> {
|
foo = (x <int>) <bool> {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
foo()
|
foo()
|
||||||
",
|
";
|
||||||
);
|
let result = interpret(&source);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Err(Error::ExpectedFunctionArgumentAmount {
|
"Expected 1 arguments, but got 0. Occured at (4, 12) to (4, 17). Source: foo()",
|
||||||
source: "foo".to_string(),
|
result.unwrap_err().to_string()
|
||||||
expected: 1,
|
|
||||||
actual: 0
|
|
||||||
}),
|
|
||||||
result
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user