@Test
public void testParsePattern() throws Exception {

  System.setProperty("config.file", "src/test/resources/test.conf");
  ConfigFactory.invalidateCaches();
  final Config config = ConfigFactory.load();
  final String sessionId = "test";
  String regexp = "(?![cdCD]\\z|qu\\z|jusqu\\z).+'.+";
  TokenPattern tokenPattern = new TokenPattern(regexp, Tokeniser.getTokenSeparators(sessionId));
  List<Pattern> patterns = tokenPattern.getParsedPattern();
  Assert.assertEquals(3, patterns.size());
  int i = 0;
  for (Pattern pattern : patterns) {
    if (i == 0) {
      Assert.assertEquals("(?![cdCD]\\z|[qQ]u\\z|[jJ]usqu\\z).+", pattern.pattern());
    } else if (i == 1) {
      Assert.assertEquals("'", pattern.pattern());
    } else if (i == 2) {
      Assert.assertEquals(".+", pattern.pattern());
    }
    i++;
  }
  regexp = "être (de|d)";
  tokenPattern = new TokenPattern(regexp, Tokeniser.getTokenSeparators(sessionId));
  patterns = tokenPattern.getParsedPattern();
  Assert.assertEquals(3, patterns.size());
  i = 0;
  for (Pattern pattern : patterns) {
    if (i == 0) {
      Assert.assertEquals("[êÊE]tre", pattern.pattern());
    } else if (i == 1) {
      Assert.assertEquals(" ", pattern.pattern());
    } else if (i == 2) {
      Assert.assertEquals("(de|d)", pattern.pattern());
    }
    i++;
  }
  regexp = ".+\\.\\p";
  tokenPattern = new TokenPattern(regexp, Tokeniser.getTokenSeparators(sessionId));
  patterns = tokenPattern.getParsedPattern();
  Assert.assertEquals(3, patterns.size());
  i = 0;
  for (Pattern pattern : patterns) {
    if (i == 0) {
      Assert.assertEquals(".+", pattern.pattern());
    } else if (i == 1) {
      Assert.assertEquals("\\.", pattern.pattern());
    } else if (i == 2) {
      Assert.assertEquals(Tokeniser.getTokenSeparators(sessionId).pattern(), pattern.pattern());
    }
    i++;
  }
  regexp = ".+qu'";
  tokenPattern = new TokenPattern(regexp, Tokeniser.getTokenSeparators(sessionId));
  patterns = tokenPattern.getParsedPattern();
  Assert.assertEquals(2, patterns.size());
  i = 0;
  for (Pattern pattern : patterns) {
    if (i == 0) {
      Assert.assertEquals(".+qu", pattern.pattern());
    } else if (i == 1) {
      Assert.assertEquals("'", pattern.pattern());
    }
    i++;
  }
  regexp = "\\D+\\.a[ \\)]c[abc]";
  tokenPattern = new TokenPattern(regexp, Tokeniser.getTokenSeparators(sessionId));
  patterns = tokenPattern.getParsedPattern();
  LOG.debug(patterns.toString());
  Assert.assertEquals(5, patterns.size());
  i = 0;
  for (Pattern pattern : patterns) {
    if (i == 0) {
      Assert.assertEquals("\\D+", pattern.pattern());
    } else if (i == 1) {
      Assert.assertEquals("\\.", pattern.pattern());
    } else if (i == 2) {
      Assert.assertEquals("a", pattern.pattern());
    } else if (i == 3) {
      Assert.assertEquals("[ \\)]", pattern.pattern());
    } else if (i == 4) {
      Assert.assertEquals("c[abc]", pattern.pattern());
    }
    i++;
  }
}