public void TestDontTrimJustSpaceBeforeAfterInTemplate() { string templates = "a(x) ::= << foo >>\n"; TemplateGroupString group = new TemplateGroupString(templates); Template st = group.GetInstanceOf("a"); string expected = " foo "; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestEmptyNoNewlineTemplate() { string template = "t(x) ::= <%%>" + newline; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = ""; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestIgnoreIndent() { string template = "t(x) ::= <%" + newline + " foo" + newline + " <x>" + newline + "%>" + newline; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = "foo99"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestEvalExprEventForSpecialCharacter() { string templates = "t() ::= <<[<\\n>]>>\n"; // 012 345 TemplateGroupString g = new TemplateGroupString(templates); Template st = g.GetInstanceOf("t"); st.impl.Dump(); StringWriter writer = new StringWriter(); List<InterpEvent> events = st.GetEvents(new AutoIndentWriter(writer, "\n")); string expected = "[EvalExprEvent{self=/t(), expr='[', source=[0..1), output=[0..1)}, " + "EvalExprEvent{self=/t(), expr='\\n', source=[2..4), output=[1..2)}, " + "EvalExprEvent{self=/t(), expr=']', source=[5..6), output=[2..3)}, " + "EvalTemplateEvent{self=/t(), output=[0..3)}]"; string result = events.ToListString(); Assert.AreEqual(expected, result); }
public void TestComplicatedIndirectTemplateApplication() { string templates = "group Java;" + newline + "" + newline + "file(variables) ::= <<" + "<variables:{ v | <v.decl:(v.format)()>}; separator=\"\\n\">" + newline + ">>" + newline + "intdecl(decl) ::= \"int <decl.name> = 0;\"" + newline + "intarray(decl) ::= \"int[] <decl.name> = null;\"" + newline ; TemplateGroup group = new TemplateGroupString(templates); Template f = group.GetInstanceOf("file"); f.AddMany("variables.{ decl,format }", new Decl("i", "int"), "intdecl"); f.AddMany("variables.{decl , format}", new Decl("a", "int-array"), "intarray"); //System.out.println("f='"+f+"'"); string expecting = "int i = 0;" + newline + "int[] a = null;"; Assert.AreEqual(expecting, f.Render()); }
CodeGenerationResult Generate(ITaskDefinitionSymbol taskDefinition) { // TODO Diagnostic check var result = new CodeGenerationResult(taskDefinition); if (_options.GenerateIBeginWfsInterface) { var model = new BeginWfsCodeModel(taskDefinition); var group = new TemplateGroupString(Resources.IBeginWFS); var st = group.GetInstanceOf("IBeginWFS"); st.Add("model", model); // TODO Add Context? result.BeginWfsInterface = st.Render(); } return result; }
public void TestPassThruWithDefaultValueThatLacksDefinitionAbove() { string templates = "a(x) ::= \"<b(...)>\"\n" + // should not set y when it sees "no definition" from above "b(x,y={99}) ::= \"<x><y>\"\n"; TemplateGroup group = new TemplateGroupString(templates); Template a = group.GetInstanceOf("a"); a.Add("x", "x"); string expected = "x99"; string result = a.Render(); Assert.AreEqual(expected, result); }
public void TestPassThruPartialArgs() { string templates = "a(x,y) ::= \"<b(y={99},...)>\"\n" + "b(x,y) ::= \"<x><y>\"\n"; TemplateGroup group = new TemplateGroupString(templates); Template a = group.GetInstanceOf("a"); a.Add("x", "x"); a.Add("y", "y"); string expected = "x99"; string result = a.Render(); Assert.AreEqual(expected, result); }
public void TestDelimitersClauseInGroupString() { string templates = "delimiters \"$\", \"$\"" + newline + "method(name) ::= <<" + newline + "$stat(name)$" + newline + ">>" + newline + "stat(name,value=\"99\") ::= \"x=$value$; // $name$\"" + newline ; TemplateGroup group = new TemplateGroupString(templates); Template b = group.GetInstanceOf("method"); b.Add("name", "foo"); string expecting = "x=99; // foo"; string result = b.Render(); Assert.AreEqual(expecting, result); }
public void TestRegion() { string template = "t(x) ::= <%\n" + "<@r>\n" + " Ignore\n" + " newlines and indents\n" + "<x>\n\n\n" + "<@end>\n" + "%>\n"; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = "Ignorenewlines and indents99"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestNoNewlineTemplate() { string template = "t(x) ::= <%" + newline + "[ <if(!x)>" + "<else>" + "<x>" + newline + "<endif>" + "" + newline + "" + newline + "]" + newline + "" + newline + "%>" + newline; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = "[ 99]"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestKeepWS() { string template = "t(x) ::= <%" + newline + " <x> <x> hi" + newline + "%>" + newline; TemplateGroup g = new TemplateGroupString(template); Template st = g.GetInstanceOf("t"); st.Add("x", 99); string expected = "99 99 hi"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestTrimmedNewlinesBeforeAfterInTemplate() { string templates = "a(x) ::= <<" + newline + "foo" + newline + ">>" + newline; TemplateGroupString group = new TemplateGroupString(templates); Template st = group.GetInstanceOf("a"); string expected = "foo"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestRegionOverrideRefSuperRegion2Levels() { string g = "a() ::= \"X<@r()>Y\"\n" + "@a.r() ::= \"foo\"\n"; TemplateGroup group = new TemplateGroupString(g); string sub = "@a.r() ::= \"<@super.r()>2\"\n"; TemplateGroup subGroup = new TemplateGroupString(sub); subGroup.ImportTemplates(group); Template st = subGroup.GetInstanceOf("a"); string result = st.Render(); string expecting = "Xfoo2Y"; Assert.AreEqual(expecting, result); }
public void TestSimpleGroupFromString() { string g = "a(x) ::= <<foo>>\n" + "b() ::= <<bar>>\n"; TemplateGroup group = new TemplateGroupString(g); Template st = group.GetInstanceOf("a"); string expected = "foo"; string result = st.Render(); Assert.AreEqual(expected, result); }
public void TestEarlyEvalOfDefaultArgs() { string templates = "s(x,y={<(x)>}) ::= \"<x><y>\"\n"; // should see x in def arg TemplateGroup group = new TemplateGroupString(templates); Template b = group.GetInstanceOf("s"); b.Add("x", "a"); string expecting = "aa"; string result = b.Render(); Assert.AreEqual(expecting, result); }