示例#1
0
  @Test
  public void testSplitterGenerator() throws IOException {
    RegexSplitGenerator splitter = new RegexSplitGenerator(new Fields("word"), "\\s+");
    Tuple arguments = new Tuple("foo\t  bar");
    Fields resultFields = new Fields("field");

    TupleListCollector collector = invokeFunction(splitter, arguments, resultFields);

    assertEquals("wrong size", 2, collector.size());

    Iterator<Tuple> iterator = collector.iterator();

    assertEquals("not equal: iterator.next().get(0)", "foo", iterator.next().getObject(0));
    assertEquals("not equal: iterator.next().get(0)", "bar", iterator.next().getObject(0));
  }
示例#2
0
  @Test
  public void testReplace() throws IOException {
    RegexReplace splitter = new RegexReplace(new Fields("words"), "\\s+", "-", true);
    Tuple arguments = new Tuple("foo\t bar");
    Fields resultFields = Fields.UNKNOWN;

    TupleListCollector collector = invokeFunction(splitter, arguments, resultFields);

    assertEquals("wrong size", 1, collector.size());

    Iterator<Tuple> iterator = collector.iterator();

    Tuple tuple = iterator.next();

    assertEquals("not equal: tuple.get(0)", "foo-bar", tuple.getObject(0));
  }
示例#3
0
  @Test
  public void testParserDeclared6() throws IOException {
    RegexParser splitter = new RegexParser(new Fields("lhs"), "(\\S+)\\s+\\S+", new int[] {1});
    Tuple arguments = new Tuple("foo\tbar");
    Fields resultFields = Fields.size(1);

    TupleListCollector collector = invokeFunction(splitter, arguments, resultFields);

    assertEquals("wrong size", 1, collector.size());

    Iterator<Tuple> iterator = collector.iterator();

    Tuple tuple = iterator.next();

    assertEquals("wrong tupel size", 1, tuple.size());
    assertEquals("not equal: tuple.get(0)", "foo", tuple.getObject(0));
  }
示例#4
0
  @Test
  public void testSplitter() throws IOException {
    RegexSplitter splitter = new RegexSplitter("\t");
    Tuple arguments = new Tuple("foo\tbar");
    Fields resultFields = Fields.UNKNOWN;

    TupleListCollector collector = invokeFunction(splitter, arguments, resultFields);

    assertEquals("wrong size", 1, collector.size());

    Iterator<Tuple> iterator = collector.iterator();

    Tuple tuple = iterator.next();

    assertEquals("not equal: tuple.get(0)", "foo", tuple.getObject(0));
    assertEquals("not equal: tuple.get(1)", "bar", tuple.getObject(1));
  }
示例#5
0
  /** Contributed by gicode */
  @Test
  public void testParserDeclared5() throws IOException {
    RegexParser splitter = new RegexParser(new Fields("bar"), "^GET /foo\\?bar=([^\\&]+)&");
    Tuple arguments = new Tuple("GET /foo?bar=z123&baz=2");
    Fields resultFields = Fields.size(1);

    TupleListCollector collector = invokeFunction(splitter, arguments, resultFields);

    assertEquals("wrong size", 1, collector.size());

    Iterator<Tuple> iterator = collector.iterator();

    Tuple tuple = iterator.next();

    assertEquals("wrong tuple size", 1, tuple.size());
    assertEquals("not equal: tuple.get(0)", "z123", tuple.getObject(0));
  }