diff --git a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt index 5a65f9b75bc4..2dc6e8704227 100644 --- a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt +++ b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt @@ -48,6 +48,11 @@ private fun T.appendRawLine(line: String): T = apply { addCommand(line) } +fun T.verifyFileEncoding(relativePath: String, + expectedCharsetName: String): T = apply { + addCommand("${CMD_PREFIX}assertEncodingFileCommand", relativePath, expectedCharsetName) +} + fun T.openFile(relativePath: String, timeoutInSeconds: Long = 0, suppressErrors: Boolean = false, @@ -740,7 +745,8 @@ fun T.stopNameSuggestionBenchmark(reportPath: String): T = ap } fun T.registerCompletionMockResponse(code: String, language: String): T = apply { - addCommand("${CMD_PREFIX}registerCompletionMockResponse -code ${code.replace(System.lineSeparator(), "")} | -language ${language}") + addCommand( + "${CMD_PREFIX}registerCompletionMockResponse -code ${code.replace(System.lineSeparator(), "")} | -language ${language}") } fun T.waitInlineCompletion(): T = apply { diff --git a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java index 49a49dbca17d..2d45f9447bca 100644 --- a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java +++ b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/BaseCommandProvider.java @@ -98,7 +98,8 @@ public final class BaseCommandProvider implements CommandProvider { Map.entry(MoveCaretCommand.PREFIX, MoveCaretCommand::new), Map.entry(TakeThreadDumpCommand.PREFIX, TakeThreadDumpCommand::new), Map.entry(CaptureMemoryMetricsCommand.PREFIX, CaptureMemoryMetricsCommand::new), - Map.entry(SleepCommand.PREFIX, SleepCommand::new) + Map.entry(SleepCommand.PREFIX, SleepCommand::new), + Map.entry(AssertEncodingFileCommand.PREFIX, AssertEncodingFileCommand::new) ); } } diff --git a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/AssertEncodingFileCommand.kt b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/AssertEncodingFileCommand.kt new file mode 100644 index 000000000000..18697b46c509 --- /dev/null +++ b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/AssertEncodingFileCommand.kt @@ -0,0 +1,32 @@ +package com.jetbrains.performancePlugin.commands + +import com.intellij.openapi.ui.playback.PlaybackContext +import com.intellij.openapi.ui.playback.commands.PlaybackCommandCoroutineAdapter +import com.intellij.openapi.vfs.encoding.EncodingProjectManager +import org.jetbrains.annotations.NonNls +import java.nio.charset.Charset + +/** + * Command checks file encoding. + * Example: %assertEncodingFileCommand filePath expectedCharsetName - verify that filePath encoded in expectedCharsetName format + */ +class AssertEncodingFileCommand(text: String, line: Int) : PlaybackCommandCoroutineAdapter(text, line) { + companion object { + const val PREFIX: @NonNls String = CMD_PREFIX + "assertEncodingFileCommand" + } + + override suspend fun doExecute(context: PlaybackContext) { + val project = context.project + val commandArgs = extractCommandArgument(PREFIX).split(" ") + val filePath = commandArgs[0] + val file = OpenFileCommand.findFile(filePath, project) + if (file == null) { + throw IllegalArgumentException("File not found: $filePath") + } + val expectedCharset = Charset.forName(commandArgs[1]) + val actualCharset = EncodingProjectManager.getInstance(project).getEncoding(file, true) + if (!expectedCharset.equals(actualCharset)) { + throw AssertionError("Expected $expectedCharset charset, but got $actualCharset") + } + } +} \ No newline at end of file