Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jinja compability: Functions with a trailing comma #92

Closed
joshuataylor opened this issue Sep 3, 2022 · 0 comments 路 Fixed by #95
Closed

Jinja compability: Functions with a trailing comma #92

joshuataylor opened this issue Sep 3, 2022 · 0 comments 路 Fixed by #95

Comments

@joshuataylor
Copy link
Sponsor Contributor

Description

The following should be supported 馃槩 馃槵 :

        {{basic_function('hello', 'world') }}
        {{basic_function('hello',
        'world') }}
        {{basic_function(
        'hello',
        'world') }}
        {{basic_function('hello',  'world',) }}
        {{basic_function('hello', 'world') }}
        {{basic_function('hello',
        'world') }}
        {{basic_function(
        'hello',
        'world') }}
        {{basic_function('hello',  'world',) }}"#,

Test Replication:

fn basic_function(_state: &State, arg_one: String, arg_two: String) -> Result<Value, Error> {
    Ok(Value::from(format!("{} {}", arg_one, arg_two)))
}

#[test]
fn test_functions() {
    let mut env = Environment::new();
    env.add_function("basic_function", basic_function);
    env.add_template(
        "demo.html",
        r#"
        {{basic_function('hello', 'world') }}
        {{basic_function('hello',
        'world') }}
        {{basic_function(
        'hello',
        'world') }}
        {{basic_function('hello',  'world',) }}"#,
    )
        .unwrap();

    let tmpl = env.get_template("demo.html").unwrap();
    insta::assert_debug_snapshot!(tmpl.render(&()).unwrap());
}

Right now it throws this:

thread 'test_functions' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: SyntaxError, detail: Some("unexpected `)`"), name: Some("demo.html"), lineno: 8, source: None }

Not sure if it should be supported for backwards compatibility or not..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant