void (int wrapWidth, String text) { List<MyFoldRegion> foldRegions = new ArrayList<>(); List<Integer> wrapPositions = new ArrayList<>(); int foldInsertPosition = 0; int pos = 0; int docPos = 0; Matcher matcher = Pattern.compile(TAGS_PATTERN).matcher(text); StringBuilder cleanedText = new StringBuilder(); while(matcher.find()) { cleanedText.append(text, pos, matcher.start()); docPos += matcher.start() - pos; pos = matcher.end(); if (matcher.group(1) != null) { // <fold> foldRegions.add(foldInsertPosition++, new MyFoldRegion(docPos, matcher.group(3), matcher.group(2) != null)); } else if (matcher.group(4) != null) { // </fold> assertTrue("Misplaced closing fold marker tag: " + text, foldInsertPosition > 0); foldRegions.get(--foldInsertPosition).endPos = docPos; } else { // <wrap> wrapPositions.add(docPos); } } assertTrue("Missing closing fold marker tag: " + text, foldInsertPosition == 0); cleanedText.append(text.substring(pos)); init(cleanedText.toString(), PlainTextFileType.INSTANCE); for (MyFoldRegion region : foldRegions) { FoldRegion r = addFoldRegion(region.startPos, region.endPos, region.placeholder); if (region.collapse) { toggleFoldRegionState(r, false); } } EditorTestUtil.configureSoftWraps(getEditor(), wrapWidth); List<Integer> actualWrapPositions = new ArrayList<>(); for (SoftWrap wrap : getEditor().getSoftWrapModel().getSoftWrapsForRange(0, getEditor().getDocument().getTextLength())) { actualWrapPositions.add(wrap.getStart()); } assertEquals("Wrong wrap positions", wrapPositions, actualWrapPositions); }