Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package it.unimi.dsi.util;
/*
* DSI utilities
*
* Copyright (C) 2010-2017 Sebastiano Vigna
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see .
*
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import it.unimi.dsi.fastutil.chars.CharArrayList;
import org.junit.Test;
public class TextPatternTest {
@Test
public void testSingleCharacterSearch() {
byte[] b = new byte[] { 1, (byte)'A', 2 };
String s = " A ";
TextPattern pattern = new TextPattern("A");
assertEquals(-1, pattern.search(b, 0, 1));
assertEquals(-1, pattern.search(s, 0, 1));
assertEquals(-1, pattern.search(s.toCharArray(), 0, 1));
assertEquals(-1, pattern.search(CharArrayList.wrap(s.toCharArray()), 0, 1));
assertEquals(1, pattern.search(b));
assertEquals(1, pattern.search(s));
assertEquals(1, pattern.search(s.toCharArray()));
assertEquals(1, pattern.search(CharArrayList.wrap(s.toCharArray())));
}
@Test
public void testSearch() {
byte[] b = new byte[] { 1, (byte)'A', 'B', 2 };
String s = " AB ";
TextPattern pattern = new TextPattern("AB");
assertEquals(-1, pattern.search(b, 0, 2));
assertEquals(-1, pattern.search(s, 0, 2));
assertEquals(-1, pattern.search(s.toCharArray(), 0, 2));
assertEquals(-1, pattern.search(CharArrayList.wrap(s.toCharArray()), 0, 2));
assertEquals(1, pattern.search(b));
assertEquals(1, pattern.search(s));
assertEquals(1, pattern.search(s.toCharArray()));
assertEquals(1, pattern.search(CharArrayList.wrap(s.toCharArray())));
TextPattern patternMeta = new TextPattern("\n" +
"\n" +
"\n" +
"\n" +
"" +
"" +
"Sebastiano Vigna\n" +
"\n" +
"\n" +
"
:::Sebastiano Vigna
" +
"
\n" +
"
" +
" Bye bye baby\n" +
" and not this one\n" +
"\n\n even whitespace counts \n\n" +
"The frame source counts\n" +
"\n" +
"\n" +
"";
}