mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git tests: simplify comparing content
This commit is contained in:
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package git4idea.branch
|
||||
|
||||
import com.intellij.dvcs.repo.Repository
|
||||
@@ -29,7 +15,6 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.runInEdtAndWait
|
||||
import com.intellij.util.LineSeparator
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.text.CharArrayUtil
|
||||
import git4idea.GitCommit
|
||||
import git4idea.branch.GitBranchUiHandler.DeleteRemoteBranchDecision
|
||||
import git4idea.branch.GitBranchUtil.getTrackInfoForBranch
|
||||
@@ -44,7 +29,6 @@ import git4idea.test.*
|
||||
import git4idea.test.GitScenarios.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.regex.Matcher
|
||||
|
||||
class GitBranchWorkerTest : GitPlatformTest() {
|
||||
|
||||
@@ -1058,8 +1042,8 @@ class GitBranchWorkerTest : GitPlatformTest() {
|
||||
}
|
||||
|
||||
private fun assertCurrentRevision(repository: GitRepository, reference: String) {
|
||||
val expectedRef = repository.git("rev-parse " + "HEAD")
|
||||
val currentRef = repository.git("rev-parse " + reference)
|
||||
val expectedRef = repository.git("rev-parse HEAD")
|
||||
val currentRef = repository.git("rev-parse $reference")
|
||||
|
||||
assertEquals("Current revision is incorrect in ${repository}", expectedRef, currentRef)
|
||||
}
|
||||
@@ -1077,31 +1061,8 @@ class GitBranchWorkerTest : GitPlatformTest() {
|
||||
assertEquals("Content doesn't match", content, cat(path))
|
||||
}
|
||||
|
||||
private fun assertContent(expectedContent: String, actual: String) {
|
||||
var expected = expectedContent
|
||||
var actual = actual
|
||||
expected = StringUtil.convertLineSeparators(expected, detectLineSeparators(actual).separatorString).trim()
|
||||
actual = actual.trim()
|
||||
assertEquals(String.format("Content doesn't match.%nExpected:%n%s%nActual:%n%s%n",
|
||||
substWhitespaces(expected), substWhitespaces(actual)), expected, actual)
|
||||
}
|
||||
|
||||
private fun detectLineSeparators(actual: String): LineSeparator {
|
||||
val chars = CharArrayUtil.fromSequence(actual)
|
||||
for (c in chars) {
|
||||
if (c == '\r') {
|
||||
return LineSeparator.CRLF
|
||||
}
|
||||
else if (c == '\n') { // if we are here, there was no \r before
|
||||
return LineSeparator.LF
|
||||
}
|
||||
}
|
||||
return LineSeparator.LF
|
||||
}
|
||||
|
||||
private fun substWhitespaces(s: String): String {
|
||||
return s.replace(("\r").toRegex(), Matcher.quoteReplacement("\\r")).replace(("\n").toRegex(),
|
||||
Matcher.quoteReplacement("\\n")).replace((" ").toRegex(),
|
||||
"_")
|
||||
private fun assertContent(expected: String, actual: String) {
|
||||
val expectedContent = StringUtil.convertLineSeparators(expected, LineSeparator.getSystemLineSeparator().separatorString)
|
||||
assertEquals("Content is incorrect", expectedContent.trim(), actual.trim())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user