[perform_tests]AT-251. Implemented new test. Added command to verify file encoding

GitOrigin-RevId: 705317b1b756dba68925ab8749a4a721fbc66c0d
This commit is contained in:
Nikita Barkov
2023-11-28 20:17:34 +00:00
committed by intellij-monorepo-bot
parent 4509b7e17b
commit aeafb19a35
3 changed files with 41 additions and 2 deletions
@@ -48,6 +48,11 @@ private fun <T : CommandChain> T.appendRawLine(line: String): T = apply {
addCommand(line)
}
fun <T : CommandChain> T.verifyFileEncoding(relativePath: String,
expectedCharsetName: String): T = apply {
addCommand("${CMD_PREFIX}assertEncodingFileCommand", relativePath, expectedCharsetName)
}
fun <T : CommandChain> T.openFile(relativePath: String,
timeoutInSeconds: Long = 0,
suppressErrors: Boolean = false,
@@ -740,7 +745,8 @@ fun <T : CommandChain> T.stopNameSuggestionBenchmark(reportPath: String): T = ap
}
fun <T : CommandChain> T.registerCompletionMockResponse(code: String, language: String): T = apply {
addCommand("${CMD_PREFIX}registerCompletionMockResponse -code ${code.replace(System.lineSeparator(), "<newLine>")} | -language ${language}")
addCommand(
"${CMD_PREFIX}registerCompletionMockResponse -code ${code.replace(System.lineSeparator(), "<newLine>")} | -language ${language}")
}
fun <T : CommandChain> T.waitInlineCompletion(): T = apply {
@@ -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)
);
}
}
@@ -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")
}
}
}