### Question:
RegexParser implements OrgParser { public static Pattern getHeaderPattern(final String... todoKeys) { final StringBuilder sb = new StringBuilder(); sb.append("^(\\*+)"); sb.append("(?:\\s+(TODO|DONE"); for (final String key : todoKeys) { if (key.isEmpty()) continue; sb.append("|").append(key.toUpperCase()); } sb.append("))?"); sb.append("(?:\\s(.*))?"); sb.append("$"); return Pattern.compile(sb.toString()); } RegexParser(final String... todoKeys); static Pattern getHeaderPattern(final String... todoKeys); static Pattern getHeaderRestPattern(); static Pattern getTimestampPattern(); static Pattern getTimestampRangePattern(); static Pattern getCommentPrefix(); static String[] parseTags(final String tagString); @Override boolean isHeaderLine(String line); @Override OrgNode createFromHeader(String line); @Override boolean isCommentLine(String line); @Override boolean isTimestampLine(String line); @Override boolean isTimestampRangeLine(String line); @Override OrgTimestamp getTimestamp(String line); @Override OrgTimestampRange getTimestampRange(String line); static final int HEADER_STARS_GROUP; static final int HEADER_TODO_GROUP; static final int HEADER_REST_GROUP; static final int HEADER_REST_TAGS_GROUP; static final int HEADER_REST_TITLE_GROUP; static final int TIMESTAMP_TYPE_GROUP; static final int TIMESTAMP_ACTIVE_GROUP; static final int TIMESTAMP_DATE_GROUP; static final int TIMESTAMP_DAY_GROUP; static final int TIMESTAMP_TIME_GROUP; static final int TIMESTAMP_TIMEEND_GROUP; static final int TIMESTAMP_REPEAT_GROUP; static final int TIMESTAMP_WARNING_GROUP; static final int TIMESTAMPRANGE_STARTDATE_GROUP; static final int TIMESTAMPRANGE_STARTDAY_GROUP; static final int TIMESTAMPRANGE_STARTTIME_GROUP; static final int TIMESTAMPRANGE_ENDDATE_GROUP; static final int TIMESTAMPRANGE_ENDDAY_GROUP; static final int TIMESTAMPRANGE_ENDTIME_GROUP; }### Answer:
@Test public void testHeaderPatternOnlyStar() throws Exception { Pattern p = RegexParser.getHeaderPattern(); Matcher m = p.matcher("*"); assertTrue(m.matches()); assertEquals("wrong level", "*", m.group(RegexParser.HEADER_STARS_GROUP)); assertNull("wrong todo", m.group(RegexParser.HEADER_TODO_GROUP)); assertNull("wrong rest", m.group(RegexParser.HEADER_REST_GROUP)); }
@Test public void testHeaderPatternOnlyTodo() throws Exception { Pattern p = RegexParser.getHeaderPattern("BOB"); Matcher m = p.matcher("* BOB"); assertTrue(m.matches()); assertEquals("wrong level", "*", m.group(RegexParser.HEADER_STARS_GROUP)); assertEquals("wrong todo", "BOB", m.group(RegexParser.HEADER_TODO_GROUP)); assertNull("wrong rest", m.group(RegexParser.HEADER_REST_GROUP)); }
@Test public void testHeaderPatternOnlyTodoWithSpace() throws Exception { Pattern p = RegexParser.getHeaderPattern("BOB"); Matcher m = p.matcher("* BOB "); assertTrue(m.matches()); assertEquals("wrong level", "*", m.group(RegexParser.HEADER_STARS_GROUP)); assertEquals("wrong todo", "BOB", m.group(RegexParser.HEADER_TODO_GROUP)); assertEquals("wrong rest", "", m.group(RegexParser.HEADER_REST_GROUP)); }
@Test public void testHeaderPatternOnlyTodoAndSomething() throws Exception { Pattern p = RegexParser.getHeaderPattern("BOB"); Matcher m = p.matcher("* BOB title :tag1:tag2:"); assertTrue(m.matches()); assertEquals("wrong level", "*", m.group(RegexParser.HEADER_STARS_GROUP)); assertEquals("wrong todo", "BOB", m.group(RegexParser.HEADER_TODO_GROUP)); assertEquals("wrong rest", "title :tag1:tag2:", m.group(RegexParser.HEADER_REST_GROUP)); }