[stringtemplate-interest] stripping newlines in attributes..

Kay Roepke kroepke at classdump.org
Sat Oct 14 13:16:14 PDT 2006


On 14. Oct 2006, at 21:52 Uhr, Robert Hill wrote:

> Once again, thanks bud!

Don't thank me too soon ;)

I just wrote this test:
	public void testStripOpOfListOfListsWithNulls() throws Exception {
		StringTemplate e = new StringTemplate(
				"$strip(data):{list | $strip(list)$}; separator=\",\"$"
			);
		e = e.getInstanceOf();
		List data = new ArrayList();
		List dataOne = new ArrayList();
		dataOne.add("Hi");
		dataOne.add(null);
		dataOne.add("mom");
		data.add(dataOne);
		data.add(null);
		List dataTwo = new ArrayList();
		dataTwo.add("Hi");
		dataTwo.add(null);
		dataTwo.add("dad");
		dataTwo.add(null);
		data.add(dataTwo);
		e.setAttribute("data", data);
		String expecting = "Himom,HiDad"; // nulls are skipped
		assertEqual(e.toString(), expecting);
	}

and it fails:
TEST: testStripOpOfListOfListsWithNulls
testStripOpOfListOfListsWithNulls failed: expecting "Himom,HiDad";  
found "Hi"

successes: 0
failures: 1

It appears that everything past the first null is truncated. This  
doesn't happen with flat lists, there are test cases for that which  
pass.
The inner strip makes it trip. Weird. Could this be related to  
Iterator sharing in nested ArrayLists? Can't imagine, but it surely  
is weird.
Smells like a bug...I don't have time to investigate right now, but  
I'll add the test to the testsuite and to the wiki.

I'm CC'ing the list so people can find this.

-k





More information about the stringtemplate-interest mailing list