Adjust test
This commit is contained in:
parent
bb53331b65
commit
45384fb394
@ -1,19 +1,27 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
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)]
|
||||
pub struct FunctionCall {
|
||||
function_expression: FunctionExpression,
|
||||
arguments: Vec<Expression>,
|
||||
syntax_position: SyntaxPosition,
|
||||
}
|
||||
|
||||
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 {
|
||||
function_expression,
|
||||
arguments,
|
||||
syntax_position,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,6 +49,7 @@ impl AbstractTree for FunctionCall {
|
||||
Ok(FunctionCall {
|
||||
function_expression,
|
||||
arguments,
|
||||
syntax_position: node.range().into(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -67,10 +76,10 @@ impl AbstractTree for FunctionCall {
|
||||
|
||||
if self.arguments.len() != parameter_types.len() {
|
||||
return Err(Error::ExpectedFunctionArgumentAmount {
|
||||
source: "TODO".to_string(),
|
||||
expected: parameter_types.len(),
|
||||
actual: self.arguments.len(),
|
||||
});
|
||||
}
|
||||
.at_source_position(_source, self.syntax_position));
|
||||
}
|
||||
|
||||
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 })
|
||||
}
|
||||
|
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.
|
||||
ExpectedFunctionArgumentAmount {
|
||||
source: String,
|
||||
expected: usize,
|
||||
actual: usize,
|
||||
},
|
||||
@ -334,14 +333,9 @@ impl fmt::Display for Error {
|
||||
f,
|
||||
"{tool_name} expected {expected} arguments, but got {actual}.",
|
||||
),
|
||||
ExpectedFunctionArgumentAmount {
|
||||
source,
|
||||
expected,
|
||||
actual,
|
||||
} => write!(
|
||||
f,
|
||||
"{source} expected {expected} arguments, but got {actual}.",
|
||||
),
|
||||
ExpectedFunctionArgumentAmount { expected, actual } => {
|
||||
write!(f, "Expected {expected} arguments, but got {actual}.",)
|
||||
}
|
||||
ExpectedFunctionArgumentMinimum {
|
||||
source,
|
||||
minumum_expected,
|
||||
|
@ -443,22 +443,17 @@ mod type_definition {
|
||||
|
||||
#[test]
|
||||
fn argument_count_check() {
|
||||
let result = interpret(
|
||||
"
|
||||
let source = "
|
||||
foo = (x <int>) <bool> {
|
||||
x
|
||||
}
|
||||
foo()
|
||||
",
|
||||
);
|
||||
";
|
||||
let result = interpret(&source);
|
||||
|
||||
assert_eq!(
|
||||
Err(Error::ExpectedFunctionArgumentAmount {
|
||||
source: "foo".to_string(),
|
||||
expected: 1,
|
||||
actual: 0
|
||||
}),
|
||||
result
|
||||
"Expected 1 arguments, but got 0. Occured at (4, 12) to (4, 17). Source: foo()",
|
||||
result.unwrap_err().to_string()
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user