From 76f4cd23e34f19ab6547a13aabcf5ad2ff0ca8cb Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sat, 8 Mar 2014 17:30:30 +1100 Subject: [PATCH] string formatting because lolwindows --- .../InterfaceHasAdditionalMethodsException.cs | 5 ++++- .../InterfaceMethodsMismatchException.cs | 8 +++++++- .../InterfaceMissingMethodsException.cs | 3 ++- .../Octokit.Tests.Conventions.csproj | 1 + Octokit.Tests.Conventions/StringExtensions.cs | 16 ++++++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 Octokit.Tests.Conventions/StringExtensions.cs diff --git a/Octokit.Tests.Conventions/Exception/InterfaceHasAdditionalMethodsException.cs b/Octokit.Tests.Conventions/Exception/InterfaceHasAdditionalMethodsException.cs index 4bccc557..78ea2daa 100644 --- a/Octokit.Tests.Conventions/Exception/InterfaceHasAdditionalMethodsException.cs +++ b/Octokit.Tests.Conventions/Exception/InterfaceHasAdditionalMethodsException.cs @@ -19,7 +19,10 @@ namespace Octokit.Tests.Conventions static string CreateMessage(Type type, IEnumerable methods) { var methodsFormatted = String.Join("\r\n", methods.Select(m => String.Format(" - {0}", m))); - return String.Format("Methods found on type {0} which should be removed:\r\n{1}", type.Name, methodsFormatted); + return "Methods found on type {0} which should be removed:\r\n{1}" + .FormatWithNewLine( + type.Name, + methodsFormatted); } } } \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Exception/InterfaceMethodsMismatchException.cs b/Octokit.Tests.Conventions/Exception/InterfaceMethodsMismatchException.cs index dad28aee..7a422d49 100644 --- a/Octokit.Tests.Conventions/Exception/InterfaceMethodsMismatchException.cs +++ b/Octokit.Tests.Conventions/Exception/InterfaceMethodsMismatchException.cs @@ -36,7 +36,13 @@ namespace Octokit.Tests.Conventions var formattedMainMethods = String.Join("\r\n", mainMethods.Select(Format).Select(m => String.Format(" - {0}", m))); var formattedObservableMethods = String.Join("\r\n", observableMethods.Select(Format).Select(m => String.Format(" - {0}", m))); - return String.Format("There are some overloads which are confusing the convention tests. Check everything is okay in these types:\r\n{0}\r\n{2}\r\n{1}\r\n{3}", clientInterface.Name, observableInterface.Name, formattedMainMethods, formattedObservableMethods); + return + "There are some overloads which are confusing the convention tests. Check everything is okay in these types:\r\n{0}\r\n{1}\r\n{2}\r\n{3}" + .FormatWithNewLine( + clientInterface.Name, + formattedMainMethods, + observableInterface.Name, + formattedObservableMethods); } } } \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Exception/InterfaceMissingMethodsException.cs b/Octokit.Tests.Conventions/Exception/InterfaceMissingMethodsException.cs index 65fc8c76..4d16288a 100644 --- a/Octokit.Tests.Conventions/Exception/InterfaceMissingMethodsException.cs +++ b/Octokit.Tests.Conventions/Exception/InterfaceMissingMethodsException.cs @@ -19,7 +19,8 @@ namespace Octokit.Tests.Conventions static string CreateMessage(Type type, IEnumerable methods) { var methodsFormatted = String.Join("\r\n", methods.Select(m => String.Format(" - {0}", m))); - return String.Format("Methods not found on interface {0} which are required:\r\n{1}", type.Name, methodsFormatted); + return "Methods not found on interface {0} which are required:\r\n{1}" + .FormatWithNewLine(type.Name, methodsFormatted); } } } \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 096592b4..dd3aa159 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -58,6 +58,7 @@ + diff --git a/Octokit.Tests.Conventions/StringExtensions.cs b/Octokit.Tests.Conventions/StringExtensions.cs new file mode 100644 index 00000000..0fdc64a3 --- /dev/null +++ b/Octokit.Tests.Conventions/StringExtensions.cs @@ -0,0 +1,16 @@ +using System; + +namespace Octokit.Tests.Conventions +{ + internal static class StringExtensions + { + public static string FormatWithNewLine(this string s, params object[] args) + { + var template = Environment.NewLine == "\r\n" + ? s + : s.Replace("\r\n", Environment.NewLine); + + return String.Format(template, args); + } + } +}