Skip to content

Commit

Permalink
#92 Wrap all usages of File.readText() with StringUtil.convertLineSep…
Browse files Browse the repository at this point in the history
…arators to avoid test fails on Windows
  • Loading branch information
kornilova203 committed Dec 21, 2020
1 parent a3ed42d commit 20efda8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,8 +66,8 @@ class MultifileResolveTest : BasePlatformTestCase() {
}

private fun getExpectedDeclaration(refFileOriginal: File, declFileOriginal: File): Pair<MatlabReference, MatlabDeclaration?> {
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)
Expand Down
6 changes: 3 additions & 3 deletions tests/com/github/kornilova203/matlab/resolve/ResolveTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -54,8 +55,7 @@ class ResolveTest : BasePlatformTestCase() {

private fun doTestUnresolved() = doTest(name, false)

private fun getExpectedDeclaration(fileTex: String): Pair<MatlabReference, MatlabDeclaration?> {
val fileText = fileTex.replace("\r", "")
private fun getExpectedDeclaration(fileText: String): Pair<MatlabReference, MatlabDeclaration?> {
var declOffset = fileText.indexOf(DECL_MARKER)
var refOffset = fileText.indexOf(REF_MARKER)
val clearText: String = when {
Expand Down

0 comments on commit 20efda8

Please sign in to comment.