[formatter] fix CompositeWhiteSpaceFormattingStrategy::check

GitOrigin-RevId: cdd4b80c1b5b4dda5fc188b998627246b7a2851b
This commit is contained in:
Vojtech Balik
2022-07-01 14:10:24 +00:00
committed by intellij-monorepo-bot
parent 0e30acbd73
commit 4be13e8463
2 changed files with 44 additions and 1 deletions
@@ -57,7 +57,7 @@ public class CompositeWhiteSpaceFormattingStrategy implements WhiteSpaceFormatti
}
}
if (offset == oldOffset) {
return start;
return offset;
}
}
return offset;
@@ -0,0 +1,43 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi.formatter
import org.junit.Assert
import org.junit.Before
import org.junit.Test
class CompositeWhiteSpaceStrategyTest {
private lateinit var myStrategy: CompositeWhiteSpaceFormattingStrategy
@Before
fun setUp() {
myStrategy = CompositeWhiteSpaceFormattingStrategy(listOf(
StaticSymbolWhiteSpaceDefinitionStrategy('a', 'c'),
StaticSymbolWhiteSpaceDefinitionStrategy('a', 'b')
))
}
@Test
fun failOnTheFirstSymbol() {
Assert.assertSame(0, myStrategy.check("daaaaa", 0, 2))
Assert.assertSame(1, myStrategy.check("adaaaa", 1, 2))
}
@Test
fun failInTheMiddle() {
Assert.assertSame(1, myStrategy.check("adbc", 0, 3))
Assert.assertSame(4, myStrategy.check("cabcdcb", 1, 5))
}
@Test
fun failOnTheLastSymbol() {
Assert.assertSame(2, myStrategy.check("aad", 0, 3))
Assert.assertSame(3, myStrategy.check("caadabd", 1, 4))
}
@Test
fun successfulMatch() {
Assert.assertSame(3, myStrategy.check("aca", 0, 3))
Assert.assertSame(4, myStrategy.check("babcbda", 1, 4))
}
}