mirror of
https://github.com/casey/just.git
synced 2024-11-26 23:27:26 +03:00
Fix function argument count mismatch error message (#2231)
This commit is contained in:
parent
0c9b159aa4
commit
241e7b46a5
@ -66,7 +66,7 @@ pub(crate) enum CompileErrorKind<'src> {
|
|||||||
FunctionArgumentCountMismatch {
|
FunctionArgumentCountMismatch {
|
||||||
function: &'src str,
|
function: &'src str,
|
||||||
found: usize,
|
found: usize,
|
||||||
expected: Range<usize>,
|
expected: RangeInclusive<usize>,
|
||||||
},
|
},
|
||||||
Include,
|
Include,
|
||||||
InconsistentLeadingWhitespace {
|
InconsistentLeadingWhitespace {
|
||||||
|
@ -108,15 +108,15 @@ pub(crate) fn get(name: &str) -> Option<Function> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Function {
|
impl Function {
|
||||||
pub(crate) fn argc(&self) -> Range<usize> {
|
pub(crate) fn argc(&self) -> RangeInclusive<usize> {
|
||||||
match *self {
|
match *self {
|
||||||
Nullary(_) => 0..0,
|
Nullary(_) => 0..=0,
|
||||||
Unary(_) => 1..1,
|
Unary(_) => 1..=1,
|
||||||
UnaryOpt(_) => 1..2,
|
UnaryOpt(_) => 1..=2,
|
||||||
UnaryPlus(_) => 1..usize::MAX,
|
UnaryPlus(_) => 1..=usize::MAX,
|
||||||
Binary(_) => 2..2,
|
Binary(_) => 2..=2,
|
||||||
BinaryPlus(_) => 2..usize::MAX,
|
BinaryPlus(_) => 2..=usize::MAX,
|
||||||
Ternary(_) => 3..3,
|
Ternary(_) => 3..=3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2568,7 +2568,7 @@ mod tests {
|
|||||||
kind: FunctionArgumentCountMismatch {
|
kind: FunctionArgumentCountMismatch {
|
||||||
function: "arch",
|
function: "arch",
|
||||||
found: 1,
|
found: 1,
|
||||||
expected: 0..0,
|
expected: 0..=0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2582,7 +2582,7 @@ mod tests {
|
|||||||
kind: FunctionArgumentCountMismatch {
|
kind: FunctionArgumentCountMismatch {
|
||||||
function: "env_var",
|
function: "env_var",
|
||||||
found: 0,
|
found: 0,
|
||||||
expected: 1..1,
|
expected: 1..=1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2596,7 +2596,7 @@ mod tests {
|
|||||||
kind: FunctionArgumentCountMismatch {
|
kind: FunctionArgumentCountMismatch {
|
||||||
function: "env",
|
function: "env",
|
||||||
found: 3,
|
found: 3,
|
||||||
expected: 1..2,
|
expected: 1..=2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2610,7 +2610,7 @@ mod tests {
|
|||||||
kind: FunctionArgumentCountMismatch {
|
kind: FunctionArgumentCountMismatch {
|
||||||
function: "env",
|
function: "env",
|
||||||
found: 0,
|
found: 0,
|
||||||
expected: 1..2,
|
expected: 1..=2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2624,7 +2624,7 @@ mod tests {
|
|||||||
kind: FunctionArgumentCountMismatch {
|
kind: FunctionArgumentCountMismatch {
|
||||||
function: "env_var_or_default",
|
function: "env_var_or_default",
|
||||||
found: 1,
|
found: 1,
|
||||||
expected: 2..2,
|
expected: 2..=2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2638,7 +2638,7 @@ mod tests {
|
|||||||
kind: FunctionArgumentCountMismatch {
|
kind: FunctionArgumentCountMismatch {
|
||||||
function: "join",
|
function: "join",
|
||||||
found: 1,
|
found: 1,
|
||||||
expected: 2..usize::MAX,
|
expected: 2..=usize::MAX,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2652,7 +2652,7 @@ mod tests {
|
|||||||
kind: FunctionArgumentCountMismatch {
|
kind: FunctionArgumentCountMismatch {
|
||||||
function: "replace",
|
function: "replace",
|
||||||
found: 1,
|
found: 1,
|
||||||
expected: 3..3,
|
expected: 3..=3,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,16 +10,14 @@ pub(crate) trait RangeExt<T> {
|
|||||||
|
|
||||||
pub(crate) struct DisplayRange<T>(T);
|
pub(crate) struct DisplayRange<T>(T);
|
||||||
|
|
||||||
impl Display for DisplayRange<&Range<usize>> {
|
impl Display for DisplayRange<&RangeInclusive<usize>> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
if self.0.start == self.0.end {
|
if self.0.start() == self.0.end() {
|
||||||
write!(f, "0")?;
|
write!(f, "{}", self.0.start())?;
|
||||||
} else if self.0.start == self.0.end - 1 {
|
} else if *self.0.end() == usize::MAX {
|
||||||
write!(f, "{}", self.0.start)?;
|
write!(f, "{} or more", self.0.start())?;
|
||||||
} else if self.0.end == usize::MAX {
|
|
||||||
write!(f, "{} or more", self.0.start)?;
|
|
||||||
} else {
|
} else {
|
||||||
write!(f, "{} to {}", self.0.start, self.0.end - 1)?;
|
write!(f, "{} to {}", self.0.start(), self.0.end())?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -76,10 +74,10 @@ mod tests {
|
|||||||
assert!(!(1..1).contains(&1));
|
assert!(!(1..1).contains(&1));
|
||||||
assert!((1..1).is_empty());
|
assert!((1..1).is_empty());
|
||||||
assert!((5..5).is_empty());
|
assert!((5..5).is_empty());
|
||||||
assert_eq!((1..1).display().to_string(), "0");
|
assert_eq!((0..=0).display().to_string(), "0");
|
||||||
assert_eq!((1..2).display().to_string(), "1");
|
assert_eq!((1..=1).display().to_string(), "1");
|
||||||
assert_eq!((5..6).display().to_string(), "5");
|
assert_eq!((5..=5).display().to_string(), "5");
|
||||||
assert_eq!((5..10).display().to_string(), "5 to 9");
|
assert_eq!((5..=9).display().to_string(), "5 to 9");
|
||||||
assert_eq!((1..usize::MAX).display().to_string(), "1 or more");
|
assert_eq!((1..=usize::MAX).display().to_string(), "1 or more");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1050,3 +1050,21 @@ fn is_dependency() {
|
|||||||
.stdout("beta false\ngamma true\n")
|
.stdout("beta false\ngamma true\n")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unary_argument_count_mismamatch_error_message() {
|
||||||
|
Test::new()
|
||||||
|
.justfile("x := datetime()")
|
||||||
|
.args(["--evaluate"])
|
||||||
|
.stderr(
|
||||||
|
"
|
||||||
|
error: Function `datetime` called with 0 arguments but takes 1
|
||||||
|
——▶ justfile:1:6
|
||||||
|
│
|
||||||
|
1 │ x := datetime()
|
||||||
|
│ ^^^^^^^^
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.status(EXIT_FAILURE)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user