### Question:
WikiTextUtils { public static List<MathTag> findMathTags(String text) { List<MathTag> results = new ArrayList<>(); Matcher matcher = MATH_TAG_PATTERN.matcher(text); while (matcher.find()) { String tag = matcher.group(); MathMarkUpType markUp = guessMarkupType(tag); if (markUp == MathMarkUpType.LATEX) { tag = tag.replaceAll("<math>", "").replaceAll("</math>", ""); } results.add(new MathTag(matcher.start(), tag, markUp)); } return results; }  static List<MathTag> findMathTags(String text); static String replaceAllFormulas(String text, List<MathTag> mathTags); static String renderAllFormulae(String text); static String subsup(String markup); static String extractPlainText(String wikiMarkup); static String deLinkify(Word word, ParsedWikiDocument doc); static final Pattern MATH_TAG_PATTERN; }### Answer:
@Test public void findMathTags() { String input = "Text text <math>V = V_0</math> text text <math>V = V_1</math> text. " + "Text <math>V = V_2</math>."; List<MathTag> actual = WikiTextUtils.findMathTags(input); List<MathTag> expected = Arrays.asList( new MathTag(10, "V = V_0", MathMarkUpType.LATEX), new MathTag(41, "V = V_1", MathMarkUpType.LATEX), new MathTag(73, "V = V_2", MathMarkUpType.LATEX)); assertEquals(expected, actual); }
@Test public void findMathTags_first() { String input = "<math>V = V_0</math> text text."; List<MathTag> actual = WikiTextUtils.findMathTags(input); List<MathTag> expected = Collections.singletonList(new MathTag(0, "V = V_0", MathMarkUpType.LATEX)); assertEquals((List) expected, (List) actual); }
@Test public void guessMarkupType_normalMathTag_isLatex() { String text = "<math>E_{rot} = \\frac{l(l+1) \\hbar^2}{2 \\mu r_{0}^2}</math>"; MathTag tag = WikiTextUtils.findMathTags(text).get(0); assertEquals(MathMarkUpType.LATEX, tag.getMarkUpType()); }
@Test public void guessMarkupType_weirdMathTag_isLatex() { String text = "<math style>E_{rot} = \\frac{l(l+1) \\hbar^2}{2 \\mu r_{0}^2} l=0,1,2,... </math>"; MathTag tag = WikiTextUtils.findMathTags(text).get(0); assertEquals(MathMarkUpType.LATEX, tag.getMarkUpType()); }
@Test public void findFormulaFromWikiText() throws Exception { String text = getTestResource("com/formulasearchengine/mathosphere/mlp/gold/eval_dataset_sample.xml"); text = TextExtractorMapper.unescape(text); WikiTextUtils.findMathTags(text); }
@Test public void guessMarkupType_isMathML() { String text = "<math><mi>x</mi></math>"; MathTag tag = WikiTextUtils.findMathTags(text).get(0); assertEquals(MathMarkUpType.MATHML, tag.getMarkUpType()); }