Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Merge pull request #106 from RemcovandenBerg/master
Browse files Browse the repository at this point in the history
deduplication of code in the testbase classes
  • Loading branch information
Rpinski committed Sep 15, 2015
2 parents 0f74be5 + 03a65de commit de40bb7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
19 changes: 2 additions & 17 deletions Tests/Common/CodeFixTestBase.cs
@@ -1,6 +1,7 @@
using NUnit.Framework;
using System.Text;
using Microsoft.CodeAnalysis.Text;
using RefactoringEssentials.Tests.Common;

namespace RefactoringEssentials.Tests
{
Expand All @@ -13,23 +14,7 @@ public virtual void SetUp()

internal static string HomogenizeEol(string str)
{
var sb = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
var ch = str[i];
var possibleNewline = NewLine.GetDelimiterLength(ch, i + 1 < str.Length ? str[i + 1] : '\0');
if (possibleNewline > 0)
{
sb.AppendLine();
if (possibleNewline == 2)
i++;
}
else
{
sb.Append(ch);
}
}
return sb.ToString();
return Utils.HomogenizeEol(str);
}

protected static string ParseText(string input, out TextSpan selectedSpan)
Expand Down
19 changes: 2 additions & 17 deletions Tests/Common/CodeRefactoringTestBase.cs
@@ -1,6 +1,7 @@
using NUnit.Framework;
using System.Text;
using Microsoft.CodeAnalysis.Text;
using RefactoringEssentials.Tests.Common;

namespace RefactoringEssentials.Tests
{
Expand All @@ -13,23 +14,7 @@ public virtual void SetUp()

internal static string HomogenizeEol(string str)
{
var sb = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
var ch = str[i];
var possibleNewline = NewLine.GetDelimiterLength(ch, i + 1 < str.Length ? str[i + 1] : '\0');
if (possibleNewline > 0)
{
sb.AppendLine();
if (possibleNewline == 2)
i++;
}
else
{
sb.Append(ch);
}
}
return sb.ToString();
return Utils.HomogenizeEol(str);
}

protected static string ParseText(string input, out TextSpan selectedSpan, out TextSpan markedSpan)
Expand Down
10 changes: 5 additions & 5 deletions Tests/Common/DiagnosticTestBase.cs
Expand Up @@ -7,10 +7,10 @@
using System.Threading;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Host.Mef;
using System.Text;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.CodeActions;
using RefactoringEssentials.Tests.Common;

namespace RefactoringEssentials.Tests
{
Expand Down Expand Up @@ -292,8 +292,8 @@ protected static void Analyze<T>(Func<string, SyntaxTree> parseTextFunc, Func<Sy
}

var txt = workspace.CurrentSolution.GetProject(projectId).GetDocument(documentId).GetTextAsync().Result.ToString();
output = CodeFixTestBase.HomogenizeEol(output);
txt = CodeFixTestBase.HomogenizeEol(txt);
output = Utils.HomogenizeEol(output);
txt = Utils.HomogenizeEol(txt);
if (output != txt)
{
Console.WriteLine("expected:");
Expand Down Expand Up @@ -408,8 +408,8 @@ protected static void AnalyzeWithRule<T>(Func<string, SyntaxTree> parseTextFunc,
}

var txt = workspace.CurrentSolution.GetProject(projectId).GetDocument(documentId).GetTextAsync().Result.ToString();
txt = CodeFixTestBase.HomogenizeEol(txt);
output = CodeFixTestBase.HomogenizeEol(output);
txt = Utils.HomogenizeEol(txt);
output = Utils.HomogenizeEol(output);
if (output != txt)
{
Console.WriteLine("expected:");
Expand Down
32 changes: 32 additions & 0 deletions Tests/Common/Utils.cs
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RefactoringEssentials.Tests.Common
{
static class Utils
{
internal static string HomogenizeEol(string str)
{
var sb = new StringBuilder();
for (int i = 0; i < str.Length; i++)
{
var ch = str[i];
var possibleNewline = NewLine.GetDelimiterLength(ch, i + 1 < str.Length ? str[i + 1] : '\0');
if (possibleNewline > 0)
{
sb.AppendLine();
if (possibleNewline == 2)
i++;
}
else
{
sb.Append(ch);
}
}
return sb.ToString();
}
}
}

0 comments on commit de40bb7

Please sign in to comment.