Exemplo n.º 1
0
 public TemplateMessage(ErrorType error, Template template, Exception source, object arg1, object arg2)
 {
     this.ErrorType = error;
     this.Template = template;
     this.Source = source;
     this.Argument1 = arg1;
     this.Argument2 = arg2;
 }
 public void TestEarlyEval()
 {
     String template = "<(name)>";
     ST st = new ST(template);
     st.Add("name", "Ter");
     String expected = "Ter";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 3
0
 public void TestAndNot()
 {
     string template = "<if(name&&!notThere)>works<else>fail<endif>";
     Template st = new Template(template);
     st.Add("name", "Ter");
     string expected = "works";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 4
0
 public void TestEmptyExprAsFirstLineGetsNoOutput()
 {
     ST t = new ST(
         "<users>\n" +
         "end\n");
     String expecting = "end" + newline;
     String result = t.Render();
     Assert.AreEqual(expecting, result);
 }
Exemplo n.º 5
0
 public void TestAttr()
 {
     string template = "hi <name>!";
     Template st = new Template(template);
     st.Add("name", "Ter");
     string expected = "hi Ter!";
     string result = st.Render();
     st.code.Dump();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 6
0
 public void TestIFElseExpr()
 {
     ST t = new ST(
         "begin\n" +
         "<if(users)><else><endif>\n" +
         "end\n");
     String expecting = "begin" + newline + "end" + newline;
     String result = t.Render();
     Assert.AreEqual(expecting, result);
 }
Exemplo n.º 7
0
 public void TestEmptyLineWithIndent()
 {
     ST t = new ST(
         "begin\n" +
         "    \n" +
         "end\n");
     String expecting = "begin" + newline + newline + "end" + newline;
     String result = t.Render();
     Assert.AreEqual(expecting, result);
 }
 public void TestIndirectProp()
 {
     String template = "<u.(propname)>: <u.name>";
     ST st = new ST(template);
     st.Add("u", new TestCoreBasics.User(1, "parrt"));
     st.Add("propname", "id");
     String expected = "1: parrt";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 9
0
 public void TestAttrIsArray()
 {
     string template = "hi <name>!";
     Template st = new Template(template);
     string[] names = new string[] { "Ter", "Tom" };
     st.Add("name", names);
     st.Add("name", "Sumana"); // shouldn't alter my version of names list!
     string expected =
         "hi TerTomSumana!";  // ST sees 3 names
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 10
0
 public void TestCatListAndSingleAttribute()
 {
     // replace first of yours with first of mine
     Template e = new Template(
             "<[mine,yours]; separator=\", \">"
         );
     e.Add("mine", "1");
     e.Add("mine", "2");
     e.Add("mine", "3");
     e.Add("yours", "a");
     string expecting = "1, 2, 3, a";
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 11
0
        public void TestAttrIsList()
        {
            string template = "hi <name>!";
            Template st = new Template(template);
            var names = new ArrayList() { "Ter", "Tom" };
            st.Add("name", names);
            st.Add("name", "Sumana"); // shouldn't alter my version of names list!
            string expected =
                "hi TerTomSumana!";  // ST sees 3 names
            string result = st.Render();
            Assert.AreEqual(expected, result);

            Assert.IsTrue(names.Count == 2); // my names list is still just 2
        }
Exemplo n.º 12
0
 public void TestParallelAttributeIteration()
 {
     ST e = new ST(
             "<names,phones,salaries:{n,p,s | <n>@<p>: <s>\n}>"
         );
     e.Add("names", "Ter");
     e.Add("names", "Tom");
     e.Add("phones", "1");
     e.Add("phones", "2");
     e.Add("salaries", "big");
     e.Add("salaries", "huge");
     String expecting = "Ter@1: big" + newline + "Tom@2: huge" + newline;
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 13
0
 public void TestIFWithIndentAndExprOnMultipleLines()
 {
     Template t = new Template(
         "begin" + newline +
         "   <if(x)>" + newline +
         "   <x>" + newline +
         "   <else>" + newline +
         "   <y>" + newline +
         "   <endif>" + newline +
         "end" + newline);
     t.Add("y", "y");
     String expecting = "begin" + newline + "   y" + newline + "end" + newline;
     String result = t.Render();
     Assert.AreEqual(expecting, result);
 }
Exemplo n.º 14
0
 public void TestIFInSubtemplate()
 {
     Template t = new Template(
         "<names:{n |" + newline +
         "   <if(x)>" + newline +
         "   <x>" + newline +
         "   <else>" + newline +
         "   <y>" + newline +
         "   <endif>" + newline +
         "}>" + newline);
     t.Add("names", "Ter");
     t.Add("y", "y");
     String expecting = "   y" + newline + newline;
     String result = t.Render();
     Assert.AreEqual(expecting, result);
 }
Exemplo n.º 15
0
 public void TestCatListAndEmptyAttributes()
 {
     // + is overloaded to be cat strings and cat lists so the
     // two operands (from left to right) determine which way it
     // goes.  In this case, x+mine is a list so everything from their
     // to the right becomes list cat.
     Template e = new Template(
             "<[x,mine,y,yours,z]; separator=\", \">"
         );
     e.Add("mine", "1");
     e.Add("mine", "2");
     e.Add("mine", "3");
     e.Add("yours", "a");
     string expecting = "1, 2, 3, a";
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 16
0
 public void TestParallelAttributeIterationWithSingletons()
 {
     ST e = new ST(
             "<names,phones,salaries:{n,p,s | <n>@<p>: <s>}; separator=\", \">"
         );
     e.Add("names", "Ter");
     e.Add("phones", "1");
     e.Add("salaries", "big");
     String expecting = "Ter@1: big";
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 17
0
 public void TestParallelAttributeIterationWithNullValue()
 {
     ST e = new ST(
         "<names,phones,salaries:{n,p,s | <n>@<p>: <s>\n}>"
     );
     e.Add("names", "Ter");
     e.Add("names", "Tom");
     e.Add("names", "Sriram");
     e.Add("phones", new object[] { "1", null, "3" });
     e.Add("salaries", "big");
     e.Add("salaries", "huge");
     e.Add("salaries", "enormous");
     String expecting = "Ter@1: big"+newline+
                    "Tom@: huge"+newline+
                    "Sriram@3: enormous"+newline;
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 18
0
 public void TestParallelAttributeIterationWithDifferentSizes()
 {
     ST e = new ST(
             "<names,phones,salaries:{n,p,s | <n>@<p>: <s>}; separator=\", \">"
         );
     e.Add("names", "Ter");
     e.Add("names", "Tom");
     e.Add("names", "Sriram");
     e.Add("phones", "1");
     e.Add("phones", "2");
     e.Add("salaries", "big");
     String expecting = "Ter@1: big, Tom@2: , Sriram@: ";
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 19
0
 public void TestCombinedOp()
 {
     // replace first of yours with first of mine
     Template e = new Template(
             "<[first(mine),rest(yours)]; separator=\", \">"
         );
     e.Add("mine", "1");
     e.Add("mine", "2");
     e.Add("mine", "3");
     e.Add("yours", "a");
     e.Add("yours", "b");
     string expecting = "1, b";
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 20
0
 public void TestParallelAttributeIterationWithMissingArgs()
 {
     ErrorBuffer errors = new ErrorBuffer();
     ErrorManager.ErrorListener = errors;
     Template e = new Template(
             "<names,phones,salaries:{<n>@<p>}; separator=\", \">"
         );
     e.Add("names", "Tom");
     e.Add("phones", "2");
     e.Add("salaries", "big");
     e.Render(); // generate the error
     string errorExpecting = "context [anonymous] 1:1 missing argument definitions" + newline;
     Assert.AreEqual(errorExpecting, errors.ToString());
 }
Exemplo n.º 21
0
 public TemplateMessage(ErrorType error, Template template, Exception source)
     : this(error, template, source, null, null)
 {
 }
Exemplo n.º 22
0
 public TemplateMessage(ErrorType error, Template template)
     : this(error, template, null, null, null)
 {
 }
Exemplo n.º 23
0
 public void TestTruncOp()
 {
     Template e = new Template(
             "<trunc(names); separator=\", \">"
         );
     e.Add("names", "Ter");
     e.Add("names", "Tom");
     e.Add("names", "Sriram");
     string expecting = "Ter, Tom";
     Assert.AreEqual(expecting, e.Render());
 }
 public void TestNonStringDictLookup()
 {
     String template = "<m.(intkey)>";
     ST st = new ST(template);
     IDictionary<int, string> m = new Dictionary<int, String>();
     m[36] = "foo";
     st.Add("m", m);
     st.Add("intkey", 36);
     String expected = "foo";
     String result = st.Render();
     Assert.AreEqual(expected, result);
 }
        private void Test()
        {
            string master = "{tb:(subject,subject,subject)}<br><center><a>{tb:(author,author,username)}</a></center>";
            Template st = new Template(master);

            Dictionary<string, object> e = new Dictionary<string, object>();
            e.Add("", "{tbStart} Name='{id}_{$1}' {class:{$2}}{tbClose}{{$3}}{tbEnd}");
            st.parameters.Add("tb", e);

            Dictionary<string, object> c = new Dictionary<string, object>();
            c.Add("subject", "FontSize='20' FontFamily='Tahoma'");
            c.Add("author", "FontSize='11' FontFamily='Verdana'");
            st.parameters.Add("class", c);

            Dictionary<string, object> g = new Dictionary<string, object>();
            g.Add("id", "root");
            g.Add("subject", "this is the root");
            g.Add("username", "mr rooty root");
            g.Add("tbStart", "<TextBlock Canvas.Top='300' Canvas.Left='300' Width='300' Height='100'");
            g.Add("tbClose", ">");
            g.Add("tbEnd", "</TextBlock>");
            st.parameters.Add("", g);

            BlockLoader.Load(st, this, new Point(300, 300));
        }
Exemplo n.º 26
0
 public virtual Template GetEmbeddedInstanceOf(Template enclosingInstance, int ip, TemplateName name)
 {
     Template st = GetInstanceOf(name);
     if (st == null)
     {
         ErrorManager.RuntimeError(enclosingInstance, ip, ErrorType.NoSuchTemplate, name.Name);
         return Template.Blank;
     }
     st.enclosingInstance = enclosingInstance;
     return st;
 }
Exemplo n.º 27
0
 public void TestParallelAttributeIterationWithMismatchArgListSizes()
 {
     ErrorBuffer errors = new ErrorBuffer();
     ErrorManager.ErrorListener = errors;
     Template e = new Template(
             "<names,phones,salaries:{n,p | <n>@<p>}; separator=\", \">"
         );
     e.Add("names", "Ter");
     e.Add("names", "Tom");
     e.Add("phones", "1");
     e.Add("phones", "2");
     e.Add("salaries", "big");
     e.Render();
     string errorExpecting = "context [anonymous] 1:1 iterating through 3 arguments but parallel map has 2 formal arguments" + newline;
     Assert.AreEqual(errorExpecting, errors.ToString());
     string expecting = "Ter@1, Tom@2";
     Assert.AreEqual(expecting, e.Render());
 }
Exemplo n.º 28
0
 public TemplateMessage(ErrorType error, Template template, Exception source, object arg)
     : this(error, template, source, arg, null)
 {
 }
Exemplo n.º 29
0
 public void TestStringTypeMismatch2()
 {
     ErrorBuffer errors = new ErrorBuffer();
     ErrorManager.ErrorListener = errors;
     ST e = new ST("<strlen(s)>");
     e.Add("s", 34);
     e.Render(); // generate the error
     String errorExpecting = "context [anonymous] 1:1 function strlen expects a string not System.Int32" + newline;
     Assert.AreEqual(errorExpecting, errors.ToString());
 }
Exemplo n.º 30
0
 public TemplateMessage(ErrorType error, Template template, Exception source, IToken token, object arg)
     : this(error, template, source, arg, null)
 {
     this.Token = token;
 }