From f5668d5358df8fb3560e51eaff4e767487dd630b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 4 Jan 2019 18:58:58 +0300 Subject: [PATCH] git tests: simplify comparing content --- .../git4idea/branch/GitBranchWorkerTest.kt | 51 +++---------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.kt b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.kt index ba87d279e082..6ea199ce0ee0 100644 --- a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.kt +++ b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.kt @@ -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()) } }