Exemplo n.º 1
0
 @Test
 public void testParamsOnly() {
   QuotedCSV values = new QuotedCSV(false);
   values.addValue("for=192.0.2.43, for=\"[2001:db8:cafe::17]\", for=unknown");
   assertThat(
       values, Matchers.contains("for=192.0.2.43", "for=[2001:db8:cafe::17]", "for=unknown"));
 }
Exemplo n.º 2
0
  @Test
  public void testMutation() {
    QuotedCSV values =
        new QuotedCSV(false) {

          @Override
          protected void parsedValue(StringBuffer buffer) {
            if (buffer.toString().contains("DELETE")) {
              String s = buffer.toString().replace("DELETE", "");
              buffer.setLength(0);
              buffer.append(s);
            }
            if (buffer.toString().contains("APPEND")) {
              String s = buffer.toString().replace("APPEND", "Append") + "!";
              buffer.setLength(0);
              buffer.append(s);
            }
          }

          @Override
          protected void parsedParam(
              StringBuffer buffer, int valueLength, int paramName, int paramValue) {
            String name =
                paramValue > 0
                    ? buffer.substring(paramName, paramValue - 1)
                    : buffer.substring(paramName);
            if ("IGNORE".equals(name)) buffer.setLength(paramName - 1);
          }
        };

    values.addValue("normal;param=val, testAPPENDandDELETEvalue ; n=v; IGNORE = this; x=y ");
    assertThat(values, Matchers.contains("normal;param=val", "testAppendandvalue!;n=v;x=y"));
  }
Exemplo n.º 3
0
 @Test
 public void testOWS() {
   QuotedCSV values = new QuotedCSV();
   values.addValue("  value 0.5  ;  pqy = vwz  ;  q =0.5  ,  value 1.0 ,  other ; param ");
   Assert.assertThat(
       values, Matchers.contains("value 0.5;pqy=vwz;q=0.5", "value 1.0", "other;param"));
 }
Exemplo n.º 4
0
 @Test
 public void testUnQuote() {
   assertThat(QuotedCSV.unquote(""), is(""));
   assertThat(QuotedCSV.unquote("\"\""), is(""));
   assertThat(QuotedCSV.unquote("foo"), is("foo"));
   assertThat(QuotedCSV.unquote("\"foo\""), is("foo"));
   assertThat(QuotedCSV.unquote("f\"o\"o"), is("foo"));
   assertThat(QuotedCSV.unquote("\"\\\"foo\""), is("\"foo"));
   assertThat(QuotedCSV.unquote("\\foo"), is("\\foo"));
 }
Exemplo n.º 5
0
 @Test
 public void testOpenQuoteNoQuotes() {
   QuotedCSV values = new QuotedCSV(false);
   values.addValue("value;p=\"v");
   assertThat(values, Matchers.contains("value;p=v"));
 }
Exemplo n.º 6
0
 @Test
 public void testQuotedNoQuotes() {
   QuotedCSV values = new QuotedCSV(false);
   values.addValue("A;p=\"v\",B,\"C, D\"");
   Assert.assertThat(values, Matchers.contains("A;p=v", "B", "C, D"));
 }
Exemplo n.º 7
0
 @Test
 public void testOpenQuote() {
   QuotedCSV values = new QuotedCSV();
   values.addValue("value;p=\"v");
   Assert.assertThat(values, Matchers.contains("value;p=\"v"));
 }
Exemplo n.º 8
0
 @Test
 public void testEmpty() {
   QuotedCSV values = new QuotedCSV();
   values.addValue(",aaaa,  , bbbb ,,cccc,");
   Assert.assertThat(values, Matchers.contains("aaaa", "bbbb", "cccc"));
 }