/**
* Test parsing of comma separated variables.
*/
public void testCommaSeparatedVariableParser()
{
CommaSeparatedVariableParser parser = new CommaSeparatedVariableParser("a,b,c");
assertTrue(parser.matches());
assertEquals(3, parser.getValues().size());
assertEquals("a", parser.getValues().get(0));
assertEquals("b", parser.getValues().get(1));
assertEquals("c", parser.getValues().get(2));
// no whitespaces will be removed
parser = new CommaSeparatedVariableParser(" a ,b, c , d ");
assertTrue(parser.matches());
assertEquals(4, parser.getValues().size());
assertEquals(" a ", parser.getValues().get(0));
assertEquals("b", parser.getValues().get(1));
assertEquals(" c ", parser.getValues().get(2));
assertEquals(" d ", parser.getValues().get(3));
// It'll care for "" and '' but it'll not remove them
parser = new CommaSeparatedVariableParser("'a ',\" b\",'c,d'");
assertTrue(parser.matches());
assertEquals(3, parser.getValues().size());
assertEquals("'a '", parser.getValues().get(0));
assertEquals("\" b\"", parser.getValues().get(1));
assertEquals("'c,d'", parser.getValues().get(2));
// But no escapes. Because no separator is following the 2nd "'",
// it'll stop parsing the string.
parser = new CommaSeparatedVariableParser("'a\'b, c");
assertTrue(parser.matches());
assertEquals(1, parser.getValues().size());
assertEquals("'a'", parser.getValues().get(0));
parser = new CommaSeparatedVariableParser("a");
assertTrue(parser.matches());
assertEquals(1, parser.getValues().size());
assertEquals("a", parser.getValues().get(0));
// Empty elements are not supported
parser = new CommaSeparatedVariableParser("a,,");
assertTrue(parser.matches());
assertEquals(1, parser.getValues().size());
assertEquals("a", parser.getValues().get(0));
}