[stringtemplate-interest] more unit tests for format

Terence Parr parrt at cs.usfca.edu
Mon Dec 11 10:18:34 PST 2006


	public void testRendererWithFormatAndSeparator() throws Exception {
		StringTemplate st =new StringTemplate(
				"The names: <names; separator=\" and \", format=\"upper\">",
				AngleBracketTemplateLexer.class);
		st.setAttribute("names", "ter");
		st.setAttribute("names", "tom");
		st.setAttribute("names", "sriram");
		st.registerRenderer(String.class, new StringRenderer());
		String expecting = "The names: TER and TOM and SRIRAM";
		String result = st.toString();
		assertEqual(result, expecting);
	}

	public void testRendererWithFormatAndSeparatorAndNull() throws  
Exception {
		StringTemplate st =new StringTemplate(
				"The names: <names; separator=\" and \", null=\"n/a\", format= 
\"upper\">",
				AngleBracketTemplateLexer.class);
		List names = new ArrayList();
		names.add("ter");
		names.add(null);
		names.add("sriram");
		st.setAttribute("names", names);
		st.registerRenderer(String.class, new StringRenderer());
		String expecting = "The names: TER and N/A and SRIRAM";
		String result = st.toString();
		assertEqual(result, expecting);
	}




More information about the stringtemplate-interest mailing list