void (@NotNull String text, @NotNull String expected, @Nullable ArrangementSettings arrangementSettings, @Nullable List<TextRange> ranges) { Info info = parse(text); if (!isEmpty(ranges) && !isEmpty(info.ranges)) { fail("Duplicate ranges set: explicit: " + ranges + ", " + "derived: " + info.ranges + ", text:\n" + text); } if (isEmpty(info.ranges)) { info.ranges = !isEmpty(ranges) ? ranges : Collections.singletonList(TextRange.from(0, text.length())); } myFixture.configureByText(fileType, info.text); final FoldingModel foldingModel = myFixture.getEditor().getFoldingModel(); for (final FoldingInfo foldingInfo : info.foldings) { foldingModel.runBatchFoldingOperation(() -> { FoldRegion region = foldingModel.addFoldRegion(foldingInfo.start(), foldingInfo.end(), foldingInfo.placeholder()); if (region != null) region.setExpanded(false); }); } if (arrangementSettings != null) { CommonCodeStyleSettings settings = CodeStyle.getSettings(myFixture.getProject()).getCommonSettings(language); settings.setArrangementSettings(arrangementSettings); } ArrangementEngine engine = ArrangementEngine.getInstance(); CommandProcessor.getInstance().executeCommand(getProject(), ()-> engine.arrange(myFixture.getEditor(), myFixture.getFile(), info.ranges), null, null); // Check expectation. Info after = parse(expected); assertEquals(after.text, myFixture.getEditor().getDocument().getText()); for (FoldingInfo it : after.foldings) { FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(it.start()); assertNotNull("Expected to find fold region at offset " + it.start(), foldRegion); assertEquals(it.end(), foldRegion.getEndOffset()); } }