public void TestNumberRendererWithPrintfFormat() { string templates = "foo(x,y) ::= << <x; format=\"F0\"> <y; format=\"0.000\"> >>\n"; WriteFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.RegisterRenderer(typeof(int), new NumberRenderer()); group.RegisterRenderer(typeof(double), new NumberRenderer()); Template st = group.GetInstanceOf("foo"); st.Add("x", -2100); st.Add("y", 3.14159); string expecting = " -2100 3.142 "; string result = st.Render(); Assert.AreEqual(expecting, result); }
public void TestLocaleWithNumberRenderer() { string templates = "foo(x,y) ::= << <x; format=\"N0\"> <y; format=\"0.000\"> >>\n"; WriteFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.RegisterRenderer(typeof(int), new NumberRenderer()); group.RegisterRenderer(typeof(double), new NumberRenderer()); Template st = group.GetInstanceOf("foo"); st.Add("x", -2100); st.Add("y", 3.14159); // Polish uses ' ' for ',' and ',' for '.' string expecting = " -2 100 3,142 "; string result = st.Render(CultureInfo.GetCultureInfo("pl-PL")); Assert.AreEqual(expecting, result); }
public void TestRendererForGroup() { string templates = "dateThing(created) ::= \"datetime: <created>\"\n"; WriteFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.RegisterRenderer(typeof(DateTime), new DateTimeRenderer()); Template st = group.GetInstanceOf("dateThing"); st.Add("created", new DateTime(2005, 7, 5)); string expecting = "datetime: 7/5/2005 12:00 AM"; string result = st.Render(); Assert.AreEqual(expecting, result); }
public void TestStringRendererWithPrintfFormat() { string templates = "foo(x) ::= << <x; format=\"%6s\"> >>\n"; WriteFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.RegisterRenderer(typeof(string), new StringRenderer()); Template st = group.GetInstanceOf("foo"); st.Add("x", "hi"); string expecting = " hi "; string result = st.Render(); Assert.AreEqual(expecting, result); }
public void TestRendererWithPredefinedFormat4() { string templates = "dateThing(created) ::= << time: <created; format=\"time:medium\"> >>\n"; WriteFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); group.RegisterRenderer(typeof(DateTime), new DateTimeRenderer()); Template st = group.GetInstanceOf("dateThing"); st.Add("created", new DateTime(2005, 7, 5)); string expecting = " time: 12:00:00 AM "; string result = st.Render(); Assert.AreEqual(expecting, result); }