void () { // 0123456 assertRanges("a {b{c}", 5, 6); } public void testFilterOneNestedRange() { // 01234567 assertRanges("a {b{c}}", "{", "}", false, true, 3, 7); } public void testFilterTwoLevelNestedRange() { // 0123456789 assertRanges("a {b{{c}}}", "{", "}", false, true, 3, 9); } public void testTwoTopLevelRangesWithNested() { // IDEA-246585 assertRanges("a {b{c}p}/{d}", 5, 6, 3, 8, 11, 12); assertRanges("a {b{c}}/{d}", 5, 6, 3, 7, 10, 11); assertRanges("a {b}/{d{c}}", "{", "}", false, true, 3, 4, 7, 11); } public void testDeepNestedBraces() { assertRanges("{{{}{}}}", 3, 3, 5, 5, 2, 6, 1, 7); } private static void assertRanges(String text, int... rangeOffsets) { assertRanges(text, "{", "}", false, false, rangeOffsets); } private static void assertRanges(String text, String prefix, String suffix, boolean useFullTextRange, boolean filterNested, int... rangeOffsets) { assertEquals("start/end offsets not balanced", 0, rangeOffsets.length % 2); int expectedRangeCount = rangeOffsets.length / 2; List<TextRange> expectedRanges = new ArrayList<>(expectedRangeCount); for (int i = 0; i < expectedRangeCount; i++) { expectedRanges.add(new TextRange(rangeOffsets[i * 2], rangeOffsets[i * 2 + 1])); } Set<TextRange> ranges = PlaceholderTextRanges.getPlaceholderRanges(text, prefix, suffix, useFullTextRange, filterNested); assertOrderedEquals(ranges, expectedRanges); } }