Skip to content

Commit

Permalink
Better annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
lippfi committed Aug 11, 2023
1 parent 5d4996c commit c2ebacd
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestOptionConstants
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.annotations.TestWithoutPrimaryClipboard
import org.jetbrains.plugins.ideavim.impl.OptionTest
import org.jetbrains.plugins.ideavim.impl.TraceOptions
import org.jetbrains.plugins.ideavim.impl.VimOption
import org.jetbrains.plugins.ideavim.rangeOf
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS
import java.awt.datatransfer.StringSelection
import java.util.*

Expand Down Expand Up @@ -121,7 +120,7 @@ class PutViaIdeaTest : VimTestCase() {
}

@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
@OptionTest(VimOption(TestOptionConstants.clipboard, limitedValues = [OptionConstants.clipboard_ideaput]))
fun `test insert block w1ith newline primary selection`() {
val before = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.annotations.TestWithoutPrimaryClipboard
import org.jetbrains.plugins.ideavim.rangeOf
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS

/**
* @author Alex Plate
Expand Down Expand Up @@ -107,8 +106,7 @@ class PutVisualTextActionTest : VimTestCase() {
}

@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text multicaret`() {
val before = "${c}I found ${c}it in a ${c}legendary land"
configureByText(before)
Expand Down Expand Up @@ -256,8 +254,7 @@ class PutVisualTextActionTest : VimTestCase() {
}

@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text linewise multicaret`() {
val before = """
A Discovery
Expand Down Expand Up @@ -319,8 +316,7 @@ class PutVisualTextActionTest : VimTestCase() {
}

@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text linewise multicaret on same line`() {
val before = """
A Discovery
Expand Down Expand Up @@ -378,8 +374,7 @@ class PutVisualTextActionTest : VimTestCase() {
}

@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text linewise multicaret on same line twice`() {
val before = """
A Discovery
Expand Down Expand Up @@ -555,8 +550,7 @@ class PutVisualTextActionTest : VimTestCase() {
}

@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text blockwise multicaret`() {
val before = """
A Discovery
Expand Down Expand Up @@ -734,8 +728,7 @@ class PutVisualTextActionTest : VimTestCase() {
""",
)
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text character to line multicaret`() {
val before = """
A Discovery
Expand Down Expand Up @@ -807,8 +800,7 @@ class PutVisualTextActionTest : VimTestCase() {
""",
)
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text character to line multicaret on same line`() {
val before = """
A Discovery
Expand Down Expand Up @@ -972,8 +964,7 @@ class PutVisualTextActionTest : VimTestCase() {
""",
)
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text line to line multicaret`() {
val before = """
A Discovery
Expand Down Expand Up @@ -1045,8 +1036,7 @@ class PutVisualTextActionTest : VimTestCase() {
""",
)
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text line to line multicaret on same line`() {
val before = """
A Discovery
Expand Down Expand Up @@ -1286,8 +1276,7 @@ class PutVisualTextActionTest : VimTestCase() {
""",
)
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text blockwise multicaret to line`() {
val before = """
A Discovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.annotations.TestWithoutPrimaryClipboard
import org.junit.Ignore
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS

/**
* @author Alex Plate
Expand Down Expand Up @@ -208,8 +207,7 @@ class PutVisualTextMoveCursorActionTest : VimTestCase() {

// Legacy tests
@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test put visual text linewise multicaret`() {
val before = """
q${c}werty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.options.OptionConstants
import org.jetbrains.plugins.ideavim.TestOptionConstants
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.annotations.TestWithoutPrimaryClipboard
import org.jetbrains.plugins.ideavim.impl.OptionTest
import org.jetbrains.plugins.ideavim.impl.TraceOptions
import org.jetbrains.plugins.ideavim.impl.VimOption
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS

@TraceOptions(TestOptionConstants.clipboard)
class YankAndPutTest : VimTestCase() {
Expand All @@ -43,7 +42,7 @@ class YankAndPutTest : VimTestCase() {
}

@OptionTest(VimOption(TestOptionConstants.clipboard, limitedValues = [OptionConstants.clipboard_unnamedplus]))
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test yank to number register with unnamedplus`() {
val before = """
I ${c}found it in a legendary land
Expand Down Expand Up @@ -88,7 +87,7 @@ class YankAndPutTest : VimTestCase() {
}

@OptionTest(VimOption(TestOptionConstants.clipboard, limitedValues = [OptionConstants.clipboard_unnamed + "," + OptionConstants.clipboard_ideaput]))
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test yank to number register with unnamed and ideaput`() {
val before = """
I ${c}found it in a legendary land
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS

/**
* Runs test only if the primary clipboard is supported by the OS.
* This is important for proper testing of both unnamed and unnamedplus registers.
*/
@Test
@EnabledOnOs(OS.LINUX)
@EnabledIfEnvironmentVariable(named = "DISPLAY", matches = ".*", disabledReason = "X11 DISPLAY variable is not present")
annotation class TestForLinux
annotation class TestWithPrimaryClipboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2003-2023 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.annotations

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable

/**
* Runs test only if the primary clipboard is not supported by the OS.
* This is important for proper testing of both unnamed and unnamedplus registers.
*/
@Test
@DisabledIfEnvironmentVariable(named = "DISPLAY", matches = ".*", disabledReason = "X11 DISPLAY variable is present")
annotation class TestWithoutPrimaryClipboard
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.SelectionType
import com.maddyhome.idea.vim.register.Register
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.annotations.TestForLinux
import org.jetbrains.plugins.ideavim.annotations.TestWithPrimaryClipboard
import org.jetbrains.plugins.ideavim.annotations.TestWithoutPrimaryClipboard
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS

class RegistersCommandTest : VimTestCase() {
@Test
@EnabledOnOs(OS.WINDOWS, OS.MAC)
@TestWithoutPrimaryClipboard
fun `test list empty registers`() {
configureByText("")
enterCommand("registers")
Expand Down Expand Up @@ -100,8 +98,7 @@ class RegistersCommandTest : VimTestCase() {
)
}

@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test correctly encodes non printable characters`() {
configureByText("")

Expand Down Expand Up @@ -134,8 +131,7 @@ class RegistersCommandTest : VimTestCase() {
)
}

@Test
@EnabledOnOs(OS.MAC, OS.WINDOWS)
@TestWithoutPrimaryClipboard
fun `test list all registers in correct order`() {
configureByText(
""""<caret>line 0
Expand Down Expand Up @@ -231,8 +227,7 @@ class RegistersCommandTest : VimTestCase() {
)
}

@Test
@EnabledOnOs(OS.WINDOWS, OS.MAC)
@TestWithoutPrimaryClipboard
fun `test clipboard registers are not duplicated`() {
configureByText("<caret>line 0 ")

Expand All @@ -248,8 +243,7 @@ class RegistersCommandTest : VimTestCase() {
)
}

@Test
@EnabledOnOs(OS.WINDOWS, OS.MAC)
@TestWithoutPrimaryClipboard
fun `test registers after yank with unnamed and unnamedplus`() {
configureByText("<caret>line 0 ")
enterCommand("set clipboard=unnamed,unnamedplus")
Expand All @@ -268,8 +262,7 @@ class RegistersCommandTest : VimTestCase() {
enterCommand("set clipboard&")
}

@Test
@EnabledOnOs(OS.WINDOWS, OS.MAC)
@TestWithoutPrimaryClipboard
fun `test registers after delete with unnamed and unnamedplus`() {
configureByText("<caret>line 0 ")
enterCommand("set clipboard=unnamed,unnamedplus")
Expand All @@ -288,8 +281,7 @@ class RegistersCommandTest : VimTestCase() {
enterCommand("set clipboard&")
}

@Test
@EnabledOnOs(OS.WINDOWS, OS.MAC)
@TestWithoutPrimaryClipboard
fun `test registers for nonlinux with unnamedplus`() {
configureByText("<caret>line 0 ")
enterCommand("set clipboard=unnamedplus")
Expand All @@ -308,14 +300,14 @@ class RegistersCommandTest : VimTestCase() {
enterCommand("set clipboard&")
}

@TestForLinux
@TestWithPrimaryClipboard
fun `test list empty registers linux`() {
configureByText("")
enterCommand("registers")
assertExOutput("Type Name Content\n c \"+ ")
}

@TestForLinux
@TestWithPrimaryClipboard
fun `test correctly encodes non printable characters linux`() {
configureByText("")

Expand All @@ -330,7 +322,7 @@ class RegistersCommandTest : VimTestCase() {
)
}

@TestForLinux
@TestWithPrimaryClipboard
fun `test list all registers in correct order linux`() {
configureByText(
""""<caret>line 0
Expand Down Expand Up @@ -428,7 +420,7 @@ class RegistersCommandTest : VimTestCase() {
)
}

@TestForLinux
@TestWithPrimaryClipboard
fun `test clipboard registers are not duplicated linux`() {
configureByText("<caret>line 0 ")

Expand All @@ -445,7 +437,7 @@ class RegistersCommandTest : VimTestCase() {
)
}

@TestForLinux
@TestWithPrimaryClipboard
fun `test registers after yank with unnamed and unnamedplus linux`() {
configureByText("<caret>line 0 ")
enterCommand("set clipboard=unnamed,unnamedplus")
Expand All @@ -465,7 +457,7 @@ class RegistersCommandTest : VimTestCase() {
enterCommand("set clipboard&")
}

@TestForLinux
@TestWithPrimaryClipboard
fun `test registers after delete with unnamed and unnamedplus linux`() {
configureByText("<caret>line 0 ")
enterCommand("set clipboard=unnamed,unnamedplus")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.register.RegisterConstants.UNNAMED_REGISTER
import org.jetbrains.plugins.ideavim.VimTestCase
import org.jetbrains.plugins.ideavim.annotations.TestForLinux
import org.jetbrains.plugins.ideavim.annotations.TestWithPrimaryClipboard
import org.jetbrains.plugins.ideavim.rangeOf
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -550,7 +550,7 @@ class ReplaceWithRegisterTest : VimTestCase() {
enterCommand("set clipboard&")
}

@TestForLinux
@TestWithPrimaryClipboard
fun `test replace in visual with clipboard unnamedplus linux`() {
VimPlugin.getRegister().resetRegisters()

Expand Down

0 comments on commit c2ebacd

Please sign in to comment.