[stringtemplate-interest] (c#) problem with separator clause

GDN gdn at poczta.onet.pl
Fri Jun 22 05:58:33 PDT 2007


Hi,
 
I have recently started play with String Template and of course I have found
many problems :-). First of them is issue with separator clause if data is
more complicated type. For example this test is not successful:
 
        [TestMethod]

        public void SeparatorCustomersListTest()

        {

            List<OneCustomer> rows = new List<OneCustomer>();

            rows.Add(new OneCustomer("Martha"));

            rows.Add(new OneCustomer("Agnes"));

            rows.Add(new OneCustomer("Margaret"));

 

            string template = @"$Customers:{" +

                "$it.CustomerName; separator=\"|\"$}$";

 

            StringTemplate translate = new StringTemplate(template);

            translate.SetAttribute("Customers", rows);

            string actual = translate.ToString();

 

            string expected = "Martha|Agnes|Margaret";

            Assert.AreEqual<string>(expected, actual);

        }

 

Actual is "MarthaAgnesMargaret" - separator is missed.

 

Where Customer type definition is:
 
    public class OneCustomer

    {

        string customerName;

        public OneCustomer(string customerName)

        {

            this.customerName = customerName;

        }

 

        public string CustomerName

        {

            get { return this.customerName; }

        }

    }

 
If I used List<string> (instead of List<OneCustomer>) result data was so as
I expected, example:
 

        [TestMethod]

        public void SeperatorCustomersStringList()

        {

            List<string> rows = new List<string>();

            rows.Add("Martha");

            rows.Add("Agnes");

            rows.Add("Margaret");

 

            string template = "$Customers; separator=\"|\"$";

 

            StringTemplate translate = new StringTemplate(template);

            translate.SetAttribute("Customers", rows);

            string actual = translate.ToString();

 

            string expected = "Martha|Agnes|Margaret";

            Assert.AreEqual<string>(expected, actual);

        }

 

In this test separator exists properly.
 
Is it problem or feature?
 
Regards,
Gregory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20070622/3d30d246/attachment.html 


More information about the stringtemplate-interest mailing list