mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-30 22:41:13 +00:00
Add regression test for *
/&
operators in functions/methods arguments
This commit is contained in:
parent
0f9c5a0281
commit
8ba1e16f3e
@ -1965,8 +1965,8 @@ impl<'a> Generator<'a> {
|
|||||||
ctx: &Context<'_>,
|
ctx: &Context<'_>,
|
||||||
buf: &mut Buffer,
|
buf: &mut Buffer,
|
||||||
arg: &WithSpan<'_, Expr<'_>>,
|
arg: &WithSpan<'_, Expr<'_>>,
|
||||||
// This variable is needed because `Expr::Unary` is not copyable but since we might
|
// This parameter is needed because even though Expr::Unary is not copyable, we might still
|
||||||
// skip a few levels.
|
// be able to skip a few levels.
|
||||||
need_borrow: bool,
|
need_borrow: bool,
|
||||||
) -> Result<(), CompileError> {
|
) -> Result<(), CompileError> {
|
||||||
if let Expr::Unary(expr @ ("*" | "&"), ref arg) = **arg {
|
if let Expr::Unary(expr @ ("*" | "&"), ref arg) = **arg {
|
||||||
|
@ -170,3 +170,46 @@ struct NotMethod;
|
|||||||
fn test_not_method() {
|
fn test_not_method() {
|
||||||
assert_eq!(NotMethod.render().unwrap(), "a6");
|
assert_eq!(NotMethod.render().unwrap(), "a6");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(
|
||||||
|
source = "
|
||||||
|
{{- bar(x) -}}
|
||||||
|
{{- bar(&*x) -}}
|
||||||
|
{{- foo(*x) -}}
|
||||||
|
{{- foo(*&*x) -}}
|
||||||
|
{# #} {{+ extra_fn::bar(x) -}}
|
||||||
|
{{- extra_fn::bar(&*x) -}}
|
||||||
|
{{- extra_fn::foo(*x) -}}
|
||||||
|
{{- extra_fn::foo(*&*x) -}}
|
||||||
|
",
|
||||||
|
ext = "txt"
|
||||||
|
)]
|
||||||
|
struct DerefMethodArg {
|
||||||
|
x: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
mod extra_fn {
|
||||||
|
pub fn bar(x: &u32) -> u32 {
|
||||||
|
*x + 4
|
||||||
|
}
|
||||||
|
pub fn foo(x: u32) -> u32 {
|
||||||
|
x + 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMethodArg {
|
||||||
|
fn bar(&self, x: &u32) -> u32 {
|
||||||
|
*x + 1
|
||||||
|
}
|
||||||
|
fn foo(&self, x: u32) -> u32 {
|
||||||
|
x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test ensures that the `*`/`&` operators are correctly placed on method/function arguments.
|
||||||
|
#[test]
|
||||||
|
fn test_deref_method_arg() {
|
||||||
|
let x = DerefMethodArg { x: 2 };
|
||||||
|
assert_eq!(x.render().unwrap(), "3322 6677");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user