1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-04-16 02:15:43 +02:00

Extract search highlighting related tests

This commit is contained in:
Matt Ellis 2024-11-30 13:28:57 +01:00 committed by Alex Pláte
parent 12ed60d88e
commit 970cfadaec
7 changed files with 1996 additions and 2014 deletions
src
test/java/org/jetbrains/plugins/ideavim/group
testFixtures/kotlin/org/jetbrains/plugins/ideavim

View File

@ -0,0 +1,247 @@
/*
* Copyright 2003-2024 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package org.jetbrains.plugins.ideavim.group.search
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
class IncsearchGlobalTest : VimTestCase() {
@Test
fun `test incsearch highlights for global command with range`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "%g/and")
assertSearchHighlights(
"and",
"""I found it in a legendary l‷and‴
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for global command in whole file with default range`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "g/and")
assertSearchHighlights(
"and",
"""I found it in a legendary l‷and‴
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for global-bang command`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "%g!/and")
assertSearchHighlights(
"and",
"""I found it in a legendary l‷and‴
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch only highlights for global command after valid argument`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
// E.g., don't remove highlights when trying to type :goto
enterSearch("and")
typeText(":g")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for global command only highlights in range`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "2,3g/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch for global command starts at beginning of range not caret position`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|${c}I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "2,8g/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
|I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for global command clears highlights on backspace`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "g/and", "<BS><BS><BS>")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for global command resets highlights on backspace`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and") // Moves the caret to "and" on the second line: (1, 10)
typeText(":", "g/roc", "<BS><BS><BS>")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
// Make sure the caret is reset too
assertPosition(1, 10)
}
@Test
fun `test cancelling incsearch highlights for global command shows previous highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and") // Moves the caret to "and" on the second line (1, 10)
typeText(":", "g/ass", "<Esc>")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
// Make sure the caret is reset too
assertPosition(1, 10)
}
}

View File

@ -0,0 +1,314 @@
/*
* Copyright 2003-2024 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package org.jetbrains.plugins.ideavim.group.search
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection")
class IncsearchSubstituteTest : VimTestCase() {
@Test
fun `test incsearch highlight with force sensitive case atom`() {
configureByText("lorem ipsum Lorem Ipsum lorem ipsum")
enterCommand("set hlsearch incsearch")
typeText("/", "\\Clorem")
assertSearchHighlights("\\Clorem", "«lorem» ipsum Lorem Ipsum ‷lorem‴ ipsum")
}
@Test
fun `test incsearch highlights for substitute command`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "%s/and")
assertSearchHighlights(
"and",
"""I found it in a legendary l‷and‴
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch only highlights for substitute command after valid argument`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
// E.g., don't remove highlights when trying to type :set
enterSearch("and")
typeText(":s")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for substitute command only highlights in range`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "2,3s/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for substitute command if range larger than file`() {
configureByText(
"""
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "1,300s/and")
assertSearchHighlights(
"and",
"""I found it in a legendary l‷and‴
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent «and» rush of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for substitute command with reversed range`() {
configureByText(
"""
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent and rush of a mountain pass.
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "8,2s/and")
assertSearchHighlights(
"and",
"""
|I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent «and» rush of a mountain pass.
|I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent «and» rush of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights nothing for substitute with range after end of file`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "100,300s/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for substitute command in current line with no range`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "s/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch for substitute command starts at beginning of range not caret position`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|${c}I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "2,8s/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
|I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for substitute command clears highlights on backspace`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "%s/and", "<BS><BS><BS>")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for substitute command resets highlights on backspace`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and") // Moves the caret to "and" on the second line: (1, 10)
typeText(":", "%s/roc", "<BS><BS><BS>")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
// Make sure the caret is reset too
assertPosition(1, 10)
}
@Test
fun `test cancelling incsearch highlights for substitute command shows previous highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and") // Moves the care to "and" on the second line: (1, 10)
typeText(":", "%s/ass", "<Esc>")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
// Make sure the caret is reset too
assertPosition(1, 10)
}
}

View File

@ -0,0 +1,608 @@
/*
* Copyright 2003-2024 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package org.jetbrains.plugins.ideavim.group.search
import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.SelectionType
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection")
class IncsearchTests : VimTestCase() {
@TestWithoutNeovim(SkipNeovimReason.OPTION)
@Test
fun `test incsearch moves caret to start of first match`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set incsearch")
typeText("/", "la")
assertPosition(1, 14)
}
@TestWithoutNeovim(SkipNeovimReason.OPTION)
@Test
fun `test incsearch + hlsearch moves caret to start of first match`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText("/", "la")
assertPosition(1, 14)
}
@Test
fun `test incsearch + hlsearch at bottom of file with wrapscan`() {
// Make sure the caret wraps during incsearch
configureByText(
"""
|Lorem ipsum dolor sit amet,
|consectetur adipiscing elit
|Sed in orci ${c}mauris.
|Cras id tellus in ex imperdiet egestas.
""".trimMargin()
)
enterCommand("set incsearch hlsearch wrapscan")
typeText("/it")
assertPosition(0, 19)
}
@Test
fun `test incsearch + hlsearch at bottom of file with nowrapscan`() {
// This will highlight the occurrences above/before the caret, but should not move the caret
configureByText(
"""
|Lorem ipsum dolor sit amet,
|consectetur adipiscing elit
|Sed in orci ${c}mauris.
|Cras id tellus in ex imperdiet egestas.
""".trimMargin()
)
enterCommand("set incsearch hlsearch nowrapscan")
typeText("/it")
assertPosition(2, 12)
}
@TestWithoutNeovim(SkipNeovimReason.OPTION)
@Test
fun `test incsearch + hlsearch moves caret to start of first match (backwards)`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText("?", "la")
assertPosition(0, 26)
}
@TestWithoutNeovim(SkipNeovimReason.OPTION)
@Test
fun `test incsearch moves caret to start of first match (backwards)`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set incsearch")
typeText("?", "la")
assertPosition(0, 26)
}
@Test
fun `test incsearch highlights with count`() {
configureByText(
"""
one
two
${c}one
two
one
two
one
two
one
two
""".trimIndent()
)
enterCommand("set hlsearch incsearch")
typeText("3", "/", "one") // No enter
assertSearchHighlights("one",
"""
«one»
two
«one»
two
«one»
two
«one»
two
one
two
""".trimIndent()
)
assertPosition(8, 0)
}
@Test
fun `test incsearch highlights with large count and wrapscan`() {
configureByText(
"""
one
two
${c}one
two
one
two
one
two
one
two
""".trimIndent()
)
enterCommand("set hlsearch incsearch")
typeText("12", "/", "one") // No enter
assertSearchHighlights("one",
"""
«one»
two
«one»
two
«one»
two
one
two
«one»
two
""".trimIndent()
)
assertPosition(6, 0)
}
@Test
fun `test incsearch highlights with large count and nowrapscan`() {
configureByText(
"""
one
two
${c}one
two
one
two
one
two
one
two
""".trimIndent()
)
enterCommand("set hlsearch incsearch nowrapscan")
typeText("12", "/", "one") // No enter
// No current match highlight
assertSearchHighlights("one",
"""
«one»
two
«one»
two
«one»
two
«one»
two
«one»
two
""".trimIndent()
)
// Back to the original location
assertPosition(2, 0)
}
@Test
fun `test incsearch highlights with count and operator count`() {
configureByText("lorem 1 ipsum lorem 2 ipsum lorem 3 ipsum lorem 4 ipsum lorem 5 ipsum lorem 6 ipsum lorem 7 ipsum")
enterCommand("set hlsearch incsearch")
typeText("2d", "3/ipsum") // No enter
assertSearchHighlights("ipsum",
"lorem 1 «ipsum» lorem 2 «ipsum» lorem 3 «ipsum» lorem 4 «ipsum» lorem 5 «ipsum» lorem 6 ‷ipsum‴ lorem 7 «ipsum»")
}
@Test
fun `test backwards incsearch with count`() {
configureByText(
"""
one
two
one
two
one
two
one
two
${c}one
two
""".trimIndent()
)
enterCommand("set hlsearch incsearch")
typeText("3", "?", "one") // No enter
assertSearchHighlights("one",
"""
«one»
two
one
two
«one»
two
«one»
two
«one»
two
""".trimIndent()
)
assertPosition(2, 0)
}
@Test
fun `test backwards incsearch highlights with large count and wrapscan`() {
configureByText(
"""
one
two
one
two
one
two
one
two
${c}one
two
""".trimIndent()
)
enterCommand("set hlsearch incsearch")
typeText("12", "?", "one") // No enter
assertSearchHighlights("one",
"""
«one»
two
«one»
two
one
two
«one»
two
«one»
two
""".trimIndent()
)
assertPosition(4, 0)
}
@Test
fun `test backwards incsearch highlights with large count and nowrapscan`() {
configureByText(
"""
one
two
one
two
one
two
one
two
${c}one
two
""".trimIndent()
)
enterCommand("set hlsearch incsearch nowrapscan")
typeText("12", "?", "one") // No enter
// No current match highlight
assertSearchHighlights("one",
"""
«one»
two
«one»
two
«one»
two
«one»
two
«one»
two
""".trimIndent()
)
// Back to the original location
assertPosition(8, 0)
}
@Test
fun `test backwards incsearch highlights with count and operator count`() {
configureByText("lorem 1 ipsum lorem 2 ipsum lorem 3 ipsum lorem 4 ipsum lorem 5 ipsum lorem 6 ipsum lorem 7 ipsu${c}m")
enterCommand("set hlsearch incsearch")
typeText("2d", "3?ipsum") // No enter
assertSearchHighlights("ipsum",
"lorem 1 «ipsum» lorem 2 ‷ipsum‴ lorem 3 «ipsum» lorem 4 «ipsum» lorem 5 «ipsum» lorem 6 «ipsum» lorem 7 «ipsum»")
}
@Test
fun `test incsearch removes all highlights if no match`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText("/", "and")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
typeText("zz")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch does not hide previous search until first character is typed`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and")
typeText("/")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
typeText("v")
assertSearchHighlights(
"v",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch does not show previous search highlights when text field is deleted`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and")
typeText("/", "grass", "<BS><BS><BS><BS><BS>")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test cancelling incsearch shows previous search highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and")
typeText("/", "grass", "<Esc>")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights only current match with nohlsearch`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set incsearch")
typeText("/", "and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights only current match with nohlsearch (backwards)`() {
configureByText(
"""I found it in a legendary land
|all rocks and lave${c}nder and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set incsearch")
typeText("?", "a")
assertSearchHighlights(
"a",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights all matches with hlsearch enabled`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText("/", "and")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test cancelling incsearch does not show previous search highlights after nohls command`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and")
enterCommand("nohlsearch")
typeText("/", "grass", "<Esc>")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlight with force sensitive case atom`() {
configureByText("lorem ipsum Lorem Ipsum lorem ipsum")
enterCommand("set hlsearch incsearch")
typeText("/", "\\Clorem")
assertSearchHighlights("\\Clorem", "«lorem» ipsum Lorem Ipsum ‷lorem‴ ipsum")
}
@Test
fun `test incsearch updates selection when started in Visual mode`() {
doTest(
listOf("ve", "/dolor"),
"""
|Lorem ipsum dolor sit amet,
|consectetur adipiscing elit
|Sed in orci mauris.
|Cras id tellus in ex imperdiet egestas.
""".trimMargin(),
"""
|${s}Lorem ipsum ${c}${se}dolor sit amet,
|consectetur adipiscing elit
|Sed in orci mauris.
|Cras id tellus in ex imperdiet egestas.
""".trimMargin(),
Mode.CMD_LINE(Mode.VISUAL(SelectionType.CHARACTER_WISE))
) {
enterCommand("set hlsearch incsearch")
}
}
@Test
fun `test incsearch updates block selection when started in Visual mode`() {
doTest(
listOf("ll", "<C-V>2j", "/mauris"),
"""
|Lorem ipsum dolor sit amet,
|consectetur adipiscing elit
|Sed in orci mauris.
|Cras id tellus in ex imperdiet egestas.
""".trimMargin(),
"""
|Lo${s}rem ipsum ${c}d${se}olor sit amet,
|co${s}nsectetur ${c}a${se}dipiscing elit
|Se${s}d in orci ${c}m${se}auris.
|Cras id tellus in ex imperdiet egestas.
""".trimMargin(),
Mode.CMD_LINE(Mode.VISUAL(SelectionType.BLOCK_WISE))
) {
enterCommand("set hlsearch incsearch")
}
}
}

View File

@ -0,0 +1,224 @@
/*
* Copyright 2003-2024 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package org.jetbrains.plugins.ideavim.group.search
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
class IncsearchVGlobalTest : VimTestCase() {
@Test
fun `test incsearch highlights for vglobal command with range`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "%v/and")
assertSearchHighlights(
"and",
"""I found it in a legendary l‷and‴
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for vglobal command in whole file with default range`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "v/and")
assertSearchHighlights(
"and",
"""I found it in a legendary l‷and‴
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch only highlights for vglobal command after valid argument`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
// E.g., don't remove highlights when trying to type :vmap
enterSearch("and")
typeText(":v")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for vglobal command only highlights in range`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|${c}hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "2,3v/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent and rush of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch for vglobal command starts at beginning of range not caret position`() {
configureByText(
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|${c}I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "2,8v/and")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
|I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
|I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for vglobal command clears highlights on backspace`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
typeText(":", "v/and", "<BS><BS><BS>")
assertSearchHighlights(
"and",
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test incsearch highlights for vglobal command resets highlights on backspace`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and") // Moves the caret to "and" on the second line: (1, 10)
typeText(":", "v/roc", "<BS><BS><BS>")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
// Make sure the caret is reset too
assertPosition(1, 10)
}
@Test
fun `test cancelling incsearch highlights for vglobal command shows previous highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
enterSearch("and") // Moves the caret to "and" on the second line: (1, 10)
typeText(":", "v/ass", "<Esc>")
assertSearchHighlights(
"and",
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
// Make sure the caret is reset too
assertPosition(1, 10)
}
}

View File

@ -0,0 +1,527 @@
/*
* Copyright 2003-2024 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package org.jetbrains.plugins.ideavim.group.search
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
class SearchHighlightsTest : VimTestCase() {
@Test
fun `test highlight search results`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test search removes previous search highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch("mountain")
enterSearch(pattern)
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test no highlights for unmatched search`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
enterSearch("zzzz")
assertNoSearchHighlights()
}
@Test
fun `test nohlsearch command removes highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
enterSearch("and")
enterCommand("nohlsearch")
assertNoSearchHighlights()
}
@Test
fun `test set 'hlsearch' option after nohlsearch command shows highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
enterCommand("nohlsearch")
enterCommand("set hlsearch")
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test find next after nohlsearch command shows highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
enterCommand("nohlsearch")
typeText("n")
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test nohlsearch correctly resets incsearch highlights after deleting last occurrence`() {
// Crazy edge case bug. With incsearch enabled, search for something with only one occurrence, delete it, call
// :nohlsearch, undo and search next - highlights don't work anymore
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch incsearch")
val pattern = "lavender"
enterSearch(pattern)
typeText("dd")
enterCommand("nohlsearch")
typeText("u", "n")
assertSearchHighlights(
pattern,
"""I found it in a legendary land
|all rocks and «lavender» and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test nohlsearch option hides search highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
enterSearch("and")
enterCommand("set nohlsearch")
assertNoSearchHighlights()
}
@Test
fun `test setting hlsearch option shows search highlights for last search`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
val pattern = "and"
enterSearch(pattern)
enterCommand("set hlsearch")
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test deleting text moves search highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("b", "dw") // deletes "rocks "
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test deleting match removes search highlight`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("dw") // deletes first "and " on line 2
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test deleting part of match removes search highlight`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("xx") // deletes "an" from first "and" on line 2
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks d lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test deleting part of match keeps highlight if pattern still matches`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = """\<s\w*d\>""" // Should match "settled" and "sand"
enterSearch(pattern)
typeText("l", "xxx") // Change "settled" to "sled"
assertSearchHighlights(
pattern,
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was «sled» on some sodden «sand»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test inserting text moves search highlights`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("h", "i", ", trees") // inserts ", trees" before first "and" on line 2
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks, trees «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test inserting text inside match removes search highlight`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("l", "i", "FOO") // inserts "FOO" inside first "and" - "aFOOnd"
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks aFOOnd lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test inserting text inside match keeps highlight if pattern still matches`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = """\<s\w*d\>""" // Should match "settled" and "sand"
enterSearch(pattern)
typeText("l", "i", "FOO", "<Esc>") // Change "settled" to "sFOOettled"
assertSearchHighlights(
pattern,
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was «sFOOettled» on some sodden «sand»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test inserting text shows highlight if it contains matches`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("o", "and then I saw a cat and a dog", "<Esc>")
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks «and» lavender «and» tufted grass,
|«and» then I saw a cat «and» a dog
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test replacing text moves search highlights`() {
val pattern = "and"
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
enterSearch(pattern)
typeText("b", "cw", "boulders", "<Esc>") // Replaces "rocks" with "boulders" on line 2
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all boulders «and» lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test replacing text inside match removes search highlight`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("l", "cw", "lso", "<Esc>") // replaces "nd" in first "and" with "lso" on line 2
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks also lavender «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test replacing text shows highlight if it contains matches`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = "and"
enterSearch(pattern)
typeText("w", "cw", "trees and boulders", "<Esc>")
assertSearchHighlights(
pattern,
"""I found it in a legendary l«and»
|all rocks «and» trees «and» boulders «and» tufted grass,
|where it was settled on some sodden s«and»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test replacing text inside match keeps highlight if pattern still matches`() {
configureByText(
"""I found it in a legendary land
|${c}all rocks and lavender and tufted grass,
|where it was settled on some sodden sand
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
enterCommand("set hlsearch")
val pattern = """\<s\w*d\>""" // Should match "settled" and "sand"
enterSearch(pattern)
typeText("l", "ctl", "huff", "<Esc>") // Change "settled" to "shuffled"
assertSearchHighlights(
pattern,
"""I found it in a legendary land
|all rocks and lavender and tufted grass,
|where it was «shuffled» on some sodden «sand»
|hard by the torrent of a mountain pass.
""".trimMargin(),
)
}
@Test
fun `test search highlight with tabs`() {
configureByText("\tfoo")
enterCommand("set hlsearch")
val pattern = "foo"
enterSearch(pattern)
assertSearchHighlights(pattern, "\t«foo»")
}
private fun assertNoSearchHighlights() {
assertEquals(0, fixture.editor.markupModel.allHighlighters.size)
}
}

View File

@ -22,6 +22,7 @@ import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.CaretVisualAttributes
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorSettings
@ -29,9 +30,11 @@ import com.intellij.openapi.editor.Inlay
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.VisualPosition
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.editor.markup.EffectType
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.fileTypes.PlainTextFileType
@ -769,6 +772,76 @@ abstract class VimNoWriteActionTestCase {
}
}
@Suppress("DEPRECATION", "SameParameterValue")
protected fun assertSearchHighlights(tooltip: String, expected: String) {
val allHighlighters = fixture.editor.markupModel.allHighlighters
thisLogger().debug("Current text: ${fixture.editor.document.text}")
val actual = StringBuilder(fixture.editor.document.text)
val inserts = mutableMapOf<Int, String>()
// Digraphs:
// <C-K>3" → ‷ + <C-K>3' → ‴ (current match)
// <C-K><< → « + <C-K>>> → » (normal match)
allHighlighters.forEach {
// TODO: This is not the nicest way to check for current match. Add something to the highlight's user data?
if (it.textAttributes?.effectType == EffectType.ROUNDED_BOX) {
inserts.compute(it.startOffset) { _, v -> if (v == null) "" else "$v" }
inserts.compute(it.endOffset) { _, v -> if (v == null) "" else "$v" }
} else {
inserts.compute(it.startOffset) { _, v -> if (v == null) "«" else "$v«" }
inserts.compute(it.endOffset) { _, v -> if (v == null) "»" else "$v»" }
}
}
var offset = 0
inserts.toSortedMap().forEach { (k, v) ->
actual.insert(k + offset, v)
offset += v.length
}
assertEquals(expected, actual.toString())
// Assert all highlighters have the correct tooltip and text attributes
val editorColorsScheme = EditorColorsManager.getInstance().globalScheme
val attributes = editorColorsScheme.getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES)
val caretColour = editorColorsScheme.getColor(EditorColors.CARET_COLOR)
allHighlighters.forEach {
val offsets = "(${it.startOffset}, ${it.endOffset})"
assertEquals(tooltip, it.errorStripeTooltip, "Incorrect tooltip for highlighter at $offsets")
assertEquals(
attributes.backgroundColor,
it.textAttributes?.backgroundColor,
"Incorrect background colour for highlighter at $offsets",
)
assertEquals(
attributes.foregroundColor,
it.textAttributes?.foregroundColor,
"Incorrect foreground colour for highlighter at $offsets",
)
// TODO: Find a better way to identify the current match
if (it.textAttributes?.effectType == EffectType.ROUNDED_BOX) {
assertEquals(
EffectType.ROUNDED_BOX,
it.textAttributes?.effectType,
"Incorrect effect type for highlighter at $offsets",
)
assertEquals(caretColour, it.textAttributes?.effectColor, "Incorrect effect colour for highlighter at $offsets")
} else {
assertEquals(
attributes.effectType,
it.textAttributes?.effectType,
"Incorrect effect type for highlighter at $offsets",
)
assertEquals(
attributes.effectColor,
it.textAttributes?.effectColor,
"Incorrect effect colour for highlighter at $offsets",
)
}
}
}
@JvmOverloads
fun doTest(
keys: List<String>,