### Question:
RegexParser implements OrgParser { public static Pattern getHeaderRestPattern() { final StringBuilder sb = new StringBuilder(); sb.append("^"); sb.append("\\s*(?:(:.+:))?"); 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 testHeaderRestPatternTitleAndTags() throws Exception { Pattern p = RegexParser.getHeaderRestPattern(); Matcher m = p.matcher(reverse(" title here :tag1:tag2: ")); assertTrue(m.matches()); assertEquals("wrong todo", " title here ", reverse(m.group(RegexParser.HEADER_REST_TITLE_GROUP))); assertEquals("wrong tags", ":tag1:tag2:", reverse(m.group(RegexParser.HEADER_REST_TAGS_GROUP))); }
@Test public void testHeaderRestPatternOnlyTitle() throws Exception { Pattern p = RegexParser.getHeaderRestPattern(); Matcher m = p.matcher("title"); assertTrue(m.matches()); assertEquals("wrong title", "title", m.group(RegexParser.HEADER_REST_TITLE_GROUP)); assertNull("wrong tags", m.group(RegexParser.HEADER_REST_TAGS_GROUP)); }
@Test public void testHeaderRestPatternOnlyTags() throws Exception { Pattern p = RegexParser.getHeaderRestPattern(); Matcher m = p.matcher(reverse(":ab:cd: ")); assertTrue(m.matches()); assertEquals("wrong title", "", m.group(RegexParser.HEADER_REST_TITLE_GROUP)); assertEquals("wrong tags", ":dc:ba:", m.group(RegexParser.HEADER_REST_TAGS_GROUP)); }