Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 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);
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }