AsciidocReferenceExistingTextCalculator { public String resolveReferenceTextOrNull(String fullSource, int posBeforeCtrlSpace) { int index = posBeforeCtrlSpace-1; if (fullSource.length()<=index) { index = fullSource.length()-1; } StringBuilder sb = new StringBuilder(); while (index>=0) { char c= fullSource.charAt(index--); if (Character.isWhitespace(c)) { break; } sb.insert(0, c); } String inspected = sb.toString(); if (inspected.startsWith(getPrefix())) { return inspected; } return null; } AsciidocReferenceExistingTextCalculator(String prefix); String resolveReferenceTextOrNull(String fullSource, int posBeforeCtrlSpace); String getPrefix();  }
@Test public void include_only() { String text = "include::"; int index = text.length(); String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::", result); }
@Test public void include_subfolder1() { String text = "include::subfolder1/"; int index = text.length(); String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::subfolder1/", result); }
@Test public void include_subfolder2_subfolder_3() { String text = "include::subfolder2/subfolder3"; int index = text.length(); String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::subfolder2/subfolder3", result); }
@Test public void include_subfolder2_subfolder_3_but_index_behind2() { String text = "include::subfolder2"; int index = text.length(); text+="/subfolder3"; String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::subfolder2", result); }
@Test public void include_subfolder2_subfolder_3_but_index_behind2_slash() { String text = "include::subfolder2/"; int index = text.length(); text+="subfolder3"; String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::subfolder2/", result); }
@Test public void include_file1() { String text = "include::file1"; int index = text.length(); String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::file1", result); }
@Test public void include_file1_pos_before_one() { String text = "include::file1"; int index = text.length()-1; String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::file", result); }
@Test public void text_before_then_include_file1() { String text = "== Headline\ninclude::file1"; int index = text.length(); String result = toTest.resolveReferenceTextOrNull(text, index); assertEquals("include::file1", result); }