From 20efda81ba1640264f2b2ebc616ef669f128576f Mon Sep 17 00:00:00 2001 From: Liudmila Kornilova Date: Mon, 21 Dec 2020 18:02:34 +0300 Subject: [PATCH] #92 Wrap all usages of File.readText() with StringUtil.convertLineSeparators to avoid test fails on Windows --- .../kornilova203/matlab/controlflow/ControlFlowTest.kt | 6 +++--- .../kornilova203/matlab/highlighting/HighlightingTest.kt | 3 ++- .../matlab/highlighting/ParenthHighlightingTest.kt | 3 ++- .../kornilova203/matlab/resolve/MultifileResolveTest.kt | 5 +++-- tests/com/github/kornilova203/matlab/resolve/ResolveTest.kt | 6 +++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/com/github/kornilova203/matlab/controlflow/ControlFlowTest.kt b/tests/com/github/kornilova203/matlab/controlflow/ControlFlowTest.kt index b58202d..b2d996f 100644 --- a/tests/com/github/kornilova203/matlab/controlflow/ControlFlowTest.kt +++ b/tests/com/github/kornilova203/matlab/controlflow/ControlFlowTest.kt @@ -6,12 +6,12 @@ import com.github.kornilova203.matlab.psi.MatlabExpr import com.intellij.codeInsight.controlflow.ConditionalInstruction import com.intellij.codeInsight.controlflow.ControlFlow import com.intellij.codeInsight.controlflow.Instruction +import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.util.elementType import com.intellij.testFramework.TestDataPath import com.intellij.testFramework.fixtures.BasePlatformTestCase import junit.framework.TestCase import java.io.File -import java.lang.StringBuilder @TestDataPath("controlflow") class ControlFlowTest : BasePlatformTestCase() { @@ -34,10 +34,10 @@ class ControlFlowTest : BasePlatformTestCase() { val controlFlow = MatlabControlFlowBuilder().buildControlFlow(file) val actual = printControlFlow(controlFlow!!) val expectedFile = File(testDataPath + "/" + getTestName(false) + ".txt") - val expected = expectedFile.readText() + val expected = StringUtil.convertLineSeparators(expectedFile.readText()) TestCase.assertEquals(expected, actual) val actualGraph = drawGraph(controlFlow) - val expectedGraph = File(testDataPath + "/" + getTestName(false) + "_graph.txt").readText() + val expectedGraph = StringUtil.convertLineSeparators(File(testDataPath + "/" + getTestName(false) + "_graph.txt").readText()) TestCase.assertEquals(expectedGraph, actualGraph) } diff --git a/tests/com/github/kornilova203/matlab/highlighting/HighlightingTest.kt b/tests/com/github/kornilova203/matlab/highlighting/HighlightingTest.kt index 7a93739..85d7774 100644 --- a/tests/com/github/kornilova203/matlab/highlighting/HighlightingTest.kt +++ b/tests/com/github/kornilova203/matlab/highlighting/HighlightingTest.kt @@ -1,6 +1,7 @@ package com.github.kornilova203.matlab.highlighting import com.github.kornilova203.matlab.getTestDataRoot +import com.intellij.openapi.util.text.StringUtil import com.intellij.testFramework.TestDataPath import com.intellij.testFramework.fixtures.BasePlatformTestCase import java.io.File @@ -16,7 +17,7 @@ class HighlightingTest : BasePlatformTestCase() { private fun doTest() { val testFile = File(testDataPath, getTestName(true) + ".m") - myFixture.configureByText(testFile.name, testFile.readText()) + myFixture.configureByText(testFile.name, StringUtil.convertLineSeparators(testFile.readText())) myFixture.testHighlighting() } diff --git a/tests/com/github/kornilova203/matlab/highlighting/ParenthHighlightingTest.kt b/tests/com/github/kornilova203/matlab/highlighting/ParenthHighlightingTest.kt index 5076a49..1e0707e 100644 --- a/tests/com/github/kornilova203/matlab/highlighting/ParenthHighlightingTest.kt +++ b/tests/com/github/kornilova203/matlab/highlighting/ParenthHighlightingTest.kt @@ -3,6 +3,7 @@ package com.github.kornilova203.matlab.highlighting import com.github.kornilova203.matlab.getTestDataRoot import com.intellij.codeInsight.highlighting.BraceMatchingUtil import com.intellij.openapi.command.WriteCommandAction +import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiDocumentManager import com.intellij.testFramework.TestDataPath import com.intellij.testFramework.fixtures.BasePlatformTestCase @@ -23,7 +24,7 @@ class ParenthHighlightingTest : BasePlatformTestCase() { private fun doTest() { val testFile = File(testDataPath, getTestName(true) + ".m") - myFixture.configureByText(testFile.name, testFile.readText()) + myFixture.configureByText(testFile.name, StringUtil.convertLineSeparators(testFile.readText())) val pairOffset = myFixture.file.text.indexOf(PAIR_MARKER) diff --git a/tests/com/github/kornilova203/matlab/resolve/MultifileResolveTest.kt b/tests/com/github/kornilova203/matlab/resolve/MultifileResolveTest.kt index bff533b..91ba86f 100644 --- a/tests/com/github/kornilova203/matlab/resolve/MultifileResolveTest.kt +++ b/tests/com/github/kornilova203/matlab/resolve/MultifileResolveTest.kt @@ -2,6 +2,7 @@ package com.github.kornilova203.matlab.resolve import com.github.kornilova203.matlab.MatlabReference import com.github.kornilova203.matlab.psi.MatlabDeclaration +import com.intellij.openapi.util.text.StringUtil import com.intellij.testFramework.fixtures.BasePlatformTestCase import junit.framework.TestCase import java.io.File @@ -65,8 +66,8 @@ class MultifileResolveTest : BasePlatformTestCase() { } private fun getExpectedDeclaration(refFileOriginal: File, declFileOriginal: File): Pair { - val refFileText = refFileOriginal.readText() - val declFileText = declFileOriginal.readText() + val refFileText = StringUtil.convertLineSeparators(refFileOriginal.readText()) + val declFileText = StringUtil.convertLineSeparators(declFileOriginal.readText()) val refOffset = refFileText.indexOf(REF_MARKER) val declOffset = declFileText.indexOf(DECL_MARKER) val refClearText = refFileText.cutOut(refOffset, REF_MARKER.length) diff --git a/tests/com/github/kornilova203/matlab/resolve/ResolveTest.kt b/tests/com/github/kornilova203/matlab/resolve/ResolveTest.kt index 1d6319a..84b01be 100644 --- a/tests/com/github/kornilova203/matlab/resolve/ResolveTest.kt +++ b/tests/com/github/kornilova203/matlab/resolve/ResolveTest.kt @@ -2,6 +2,7 @@ package com.github.kornilova203.matlab.resolve import com.github.kornilova203.matlab.MatlabReference import com.github.kornilova203.matlab.psi.MatlabDeclaration +import com.intellij.openapi.util.text.StringUtil import com.intellij.testFramework.fixtures.BasePlatformTestCase import java.io.File @@ -40,7 +41,7 @@ class ResolveTest : BasePlatformTestCase() { private fun doTest(name: String, shouldBeResolved: Boolean = true) { val file = File(testDataPath + getTestName(false) + ".m") - val (ref, decl) = getExpectedDeclaration(file.readText()) + val (ref, decl) = getExpectedDeclaration(StringUtil.convertLineSeparators(file.readText())) val resolvedDecl = ref.resolve() if (shouldBeResolved) { assertNotNull("Declaration not found", resolvedDecl) @@ -54,8 +55,7 @@ class ResolveTest : BasePlatformTestCase() { private fun doTestUnresolved() = doTest(name, false) - private fun getExpectedDeclaration(fileTex: String): Pair { - val fileText = fileTex.replace("\r", "") + private fun getExpectedDeclaration(fileText: String): Pair { var declOffset = fileText.indexOf(DECL_MARKER) var refOffset = fileText.indexOf(REF_MARKER) val clearText: String = when {