Skip to content

Commit

Permalink
Merge pull request #115 from jsnyders/FixIssue114
Browse files Browse the repository at this point in the history
fix issue 114
  • Loading branch information
parrt committed Dec 3, 2015
2 parents cb00ede + f33b69a commit be4287f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ CONTRIBUTORS:
YYYY/MM/DD, github id, Full name, email
2012/07/12, parrt, Terence Parr, parrt@antlr.org
2012/08/13, pgelinas, Pascal Gélinas, pascal.gelinas@polymtl.ca
2015/05/28, jsnyders, John Snyders, jjsnyders at rcn.com
2 changes: 1 addition & 1 deletion src/org/stringtemplate/v4/STGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected ST getEmbeddedInstanceOf(Interpreter interp,
/** Create singleton template for use with dictionary values. */
public ST createSingleton(Token templateToken) {
String template;
if ( templateToken.getType()==GroupParser.BIGSTRING ) {
if ( templateToken.getType()==GroupParser.BIGSTRING || templateToken.getType()==GroupParser.BIGSTRING_NO_NL ) {
template = Misc.strip(templateToken.getText(),2);
}
else {
Expand Down
25 changes: 25 additions & 0 deletions test/org/stringtemplate/v4/test/TestDictionaries.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,29 @@ public void testDictionaryBehaviorEmptyList() throws Exception {
assertEquals(expected, result);
}

/**
* This is a regression test for antlr/stringtemplate4#114.
* "dictionary value using <% %> is broken"
* Before the fix the following test would return %hi%
* https://github.com/antlr/stringtemplate4/issues/114
*/
@Test
public void testDictionaryBehaviorNoNewlineTemplate() throws Exception {
String templates =
"d ::= [\n" +
" \"x\" : <%hi%>\n" +
"]\n" +
"\n" +
"t() ::= <<\n" +
"<d.x>\n" +
">>\n";

writeFile(tmpdir, "t.stg", templates);
STGroup group = new STGroupFile(tmpdir + File.separatorChar + "t.stg");
ST st = group.getInstanceOf("t");
String expected = "hi";
String result = st.render();
assertEquals(expected, result);
}

}

0 comments on commit be4287f

Please sign in to comment.