From 119bc9b56431a7f88dd00b661dcc4510c87c66a3 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 8 Dec 2011 17:02:34 +0100 Subject: [PATCH] Fix formatting tests on Windows with git autocrlf enabled. --- .../FormattingTests/TestFormattingBugs.cs | 2 +- .../FormattingTests/TestSpacingVisitor.cs | 24 +++++++++---------- .../FormattingTests/TextEditorTestAdapter.cs | 8 +++++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs b/ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs index ea509e221a..db507125a7 100644 --- a/ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs +++ b/ICSharpCode.NRefactory.Tests/FormattingTests/TestFormattingBugs.cs @@ -133,7 +133,7 @@ using (IDisposable b = null) { int start = result.GetOffset (5, 1); int end = result.GetOffset (result.LineCount - 1, 1); string text = result.GetText (start, end - start).Trim (); - expectedOutput = expectedOutput.Replace ("\n", "\n\t\t"); + expectedOutput = NormalizeNewlines(expectedOutput).Replace ("\n", "\n\t\t"); Assert.AreEqual (expectedOutput, text); } diff --git a/ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs b/ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs index 3f0c236024..5383c20acb 100644 --- a/ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs +++ b/ICSharpCode.NRefactory.Tests/FormattingTests/TestSpacingVisitor.cs @@ -1100,12 +1100,12 @@ return (Test)null; } }"); - Assert.AreEqual (@"class Test + Assert.AreEqual (NormalizeNewlines(@"class Test { Test () { } -}", result.Text); +}"), result.Text); } [Test()] @@ -1290,13 +1290,13 @@ return (Test)null; } }"); - Assert.AreEqual (@"class FooBar + Assert.AreEqual (NormalizeNewlines(@"class FooBar { public void Foo () { Test (); } -}", result.Text); +}"), result.Text); } [Test()] @@ -1403,14 +1403,14 @@ return (Test)null; } } }"); - Assert.AreEqual (@"class FooBar + Assert.AreEqual (NormalizeNewlines(@"class FooBar { public int this [int a, int b] { get { return a + b; } } -}", result.Text); +}"), result.Text); } [Test()] @@ -1489,13 +1489,13 @@ return (Test)null; this[0] = 5; } }"); - Assert.AreEqual (@"class Test + Assert.AreEqual (NormalizeNewlines(@"class Test { void TestMe () { this[ 0 ] = 5; } -}", result.Text); +}"), result.Text); } @@ -1513,13 +1513,13 @@ return (Test)null; this[0] = 5; } }"); - Assert.AreEqual (@"class Test + Assert.AreEqual (NormalizeNewlines(@"class Test { void TestMe () { this [0] = 5; } -}", result.Text); +}"), result.Text); } @@ -1574,11 +1574,11 @@ return (Test)null; int[][] b; }"); - Assert.AreEqual (@"class Test + Assert.AreEqual (NormalizeNewlines(@"class Test { int [] a; int [][] b; -}", result.Text); +}"), result.Text); } diff --git a/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs b/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs index 0a08781a69..bcd68826f5 100644 --- a/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs +++ b/ICSharpCode.NRefactory.Tests/FormattingTests/TextEditorTestAdapter.cs @@ -51,6 +51,7 @@ namespace ICSharpCode.NRefactory.FormattingTests protected static IDocument GetResult (CSharpFormattingOptions policy, string input) { + input = NormalizeNewlines(input); var adapter = new ReadOnlyDocument (input); var visitor = new AstFormattingVisitor (policy, adapter, factory); visitor.EolMarker = "\n"; @@ -62,6 +63,7 @@ namespace ICSharpCode.NRefactory.FormattingTests protected static IDocument Test (CSharpFormattingOptions policy, string input, string expectedOutput) { + expectedOutput = NormalizeNewlines(expectedOutput); IDocument doc = GetResult(policy, input); if (expectedOutput != doc.Text) { Console.WriteLine (doc.Text); @@ -69,9 +71,15 @@ namespace ICSharpCode.NRefactory.FormattingTests Assert.AreEqual (expectedOutput, doc.Text); return doc; } + + protected static string NormalizeNewlines(string input) + { + return input.Replace("\r\n", "\n"); + } protected static void Continue (CSharpFormattingOptions policy, IDocument document, string expectedOutput) { + expectedOutput = NormalizeNewlines(expectedOutput); var visitior = new AstFormattingVisitor (policy, document, factory); visitior.EolMarker = "\n"; var compilationUnit = new CSharpParser ().Parse (new StringReader (document.Text), "test.cs");