void () { String text = """ public class Hello { // @start region=main public static void main(String[] args) { code: // @replace regex='code:' replacement="" // @highlight substring="Hello World" System.out.println("Hello World"); // @highlight region substring="idx" for(int idx=0; idx<10; idx++) { System.out.println(idx); } // @end } // @end } """; testParsing(text, """ PlainText[range=(0,21), content=public class Hello { ] StartRegion[range=(26,44), region=main] PlainText[range=(45,45), content=] PlainText[range=(45,88), content= public static void main(String[] args) { ] Replace[range=(101,138), selector=Regex[pattern=code:], region=null, replacement=] PlainText[range=(88,98), content= code:\s ] Highlight[range=(146,180), selector=Substring[substring=Hello World], region=null, type=HIGHLIGHTED] PlainText[range=(181,181), content=] PlainText[range=(181,220), content= System.out.println("Hello World"); ] Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED] PlainText[range=(261,261), content=] PlainText[range=(261,297), content= for(int idx=0; idx<10; idx++) { ] PlainText[range=(297,328), content= System.out.println(idx); ] PlainText[range=(328,334), content= } ] EndRegion[range=(341,345), region=null] PlainText[range=(346,346), content=] PlainText[range=(346,350), content= } ] EndRegion[range=(355,359), region=null] PlainText[range=(360,360), content=] PlainText[range=(360,362), content=} ] PlainText[range=(362,362), content=]"""); testVisitor(text, null, false, """ public class Hello { public static void main(String[] args) { // [Replace[range=(101,138), selector=Regex[pattern=code:], region=null, replacement=]] code:\s System.out.println("Hello World"); // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] for(int idx=0; idx<10; idx++) { // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] System.out.println(idx); // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] } } } """); testVisitor(text, "main", false, """ public static void main(String[] args) { // [Replace[range=(101,138), selector=Regex[pattern=code:], region=null, replacement=]] code:\s System.out.println("Hello World"); // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] for(int idx=0; idx<10; idx++) { // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] System.out.println(idx); // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] } } """); testVisitor(text, "main", true, """ public static void main(String[] args) { \s System.out.println("Hello World"); // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] for(int idx=0; idx<10; idx++) { // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] System.out.println(idx); // [Highlight[range=(227,260), selector=Substring[substring=idx], region=, type=HIGHLIGHTED]] } } """); SnippetMarkup markup = SnippetMarkup.parse(text); assertEquals(0, markup.getCommonIndent(null)); assertEquals(2, markup.getCommonIndent("main")); assertEquals(""" public static void main(String[] args) { code:\s System.out.println("Hello World"); for(int idx=0; idx<10; idx++) { System.out.println(idx); } } """, markup.getTextWithoutMarkup("main")); }