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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recurrence of specified parameters in Template paramter list #99

Closed
hartmut27 opened this issue Feb 10, 2015 · 1 comment
Closed

Recurrence of specified parameters in Template paramter list #99

hartmut27 opened this issue Feb 10, 2015 · 1 comment
Assignees
Milestone

Comments

@hartmut27
Copy link

I am using ST04 with great pleasure :)
Today I found a behaviour, where ST4.0.8 renders output, which I can't explain. Is it intended to do so?
I would expect an deffensive error message, saying that parameter "a" has beend specified twice.
(Sure, this error does not occur, when I don't repeat the parameter literals in the list of parameters. It's more a question of robustness, fail safety, etc.)

My example:

package de.hartmutpfarr.bmj.test;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupString;

public class StringTemplateTest {

    @Test
    public void testName() throws Exception {

        // intention has been:
        // main(a,b,c)
        // by mistake, human failure, etc., specify parameter "a" twice:
        // main(a,b,a,c)
        String templ = "main(a,b,a,c) ::= <<START <a>, <b>, <c> END>>";
        STGroup group = new STGroupString(templ);
        ST st = group.getInstanceOf("main");
        st.add("a", "A");
        st.add("b", "B");
        st.add("c", "C");
        assertThat(st.render()).isEqualTo("START A, B, C END");

        // org.junit.ComparisonFailure:
        // expected: <"START A, B, C END">
        // but was: <"START AC, B, AC END">

    }
}

Kind regards!

@sharwell sharwell added this to the 4.0.9 milestone Feb 11, 2015
@sharwell
Copy link
Member

Hi @hartmut27,

Welcome to the project, and thanks for taking the time to report this (and even include sample code) ✨

This should definitely not be allowed. We'll have to think about the specific way we want to handle this, and also examine related issues regarding like manual definition of templates and signature mismatches that may occur when importing templates.

StringTemplate is moving on a pretty slow release cycle, mostly due to an absence of bug reports (not a bad thing when you think about it). I've marked this for inclusion in the next patch release. If we don't get it out the door fast enough and it continues to bother you, please don't hesitate to post a reminder here. 👍

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

No branches or pull requests

2 participants