From d29859320cb66a48a09432ca4a6d3c18d3a22330 Mon Sep 17 00:00:00 2001 From: "Bruni, Ottorino" Date: Mon, 27 May 2024 09:37:40 +0200 Subject: [PATCH 1/2] fix bug new line --- TextCase.UnitTests/CobolCaseConverterTest.cs | 4 ++-- TextCase.UnitTests/ConstantCaseConverterTest.cs | 4 ++-- TextCase.UnitTests/HashtagCaseConverterTest.cs | 4 ++-- TextCase.UnitTests/TrainCaseConverterTest.cs | 4 ++-- TextCase/Converters/CobolCaseConverter.cs | 7 ++++--- TextCase/Converters/ConstantCaseConverter.cs | 9 +++++---- TextCase/Converters/HashtagCaseConverter.cs | 4 ++-- TextCase/Converters/TrainCaseConverter.cs | 6 +++--- TextCase/TextCase.csproj | 2 +- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/TextCase.UnitTests/CobolCaseConverterTest.cs b/TextCase.UnitTests/CobolCaseConverterTest.cs index f79847f..748e3d0 100644 --- a/TextCase.UnitTests/CobolCaseConverterTest.cs +++ b/TextCase.UnitTests/CobolCaseConverterTest.cs @@ -9,7 +9,7 @@ public class CobolCaseConverterTest [Theory] [InlineData("hello world", "HELLO-WORLD")] [InlineData("icH bIn glückLICH", "ICH-BIN-GLÜCKLICH")] - [InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT-STYLE-SPACE-2\nINDENT-SIZE-2")] + [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT-STYLE-SPACE-2\r\nINDENT-SIZE-2")] [InlineData("Hello World!", "HELLO-WORLD")] [InlineData("123 test", "123-TEST")] [InlineData("test with multiple spaces", "TEST-WITH-MULTIPLE-SPACES")] @@ -33,7 +33,7 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri [Theory] [InlineData("hello world", "HELLO-WORLD")] [InlineData("icH bIn glückLICH", "ICH-BIN-GLÜCKLICH")] - [InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT-STYLE-SPACE-2\nINDENT-SIZE-2")] + [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT-STYLE-SPACE-2\r\nINDENT-SIZE-2")] [InlineData("Hello World!", "HELLO-WORLD")] [InlineData("123 test", "123-TEST")] [InlineData("test with multiple spaces", "TEST-WITH-MULTIPLE-SPACES")] diff --git a/TextCase.UnitTests/ConstantCaseConverterTest.cs b/TextCase.UnitTests/ConstantCaseConverterTest.cs index 5592c1d..25e2ea2 100644 --- a/TextCase.UnitTests/ConstantCaseConverterTest.cs +++ b/TextCase.UnitTests/ConstantCaseConverterTest.cs @@ -9,7 +9,7 @@ public class ConstantCaseConverterTest [Theory] [InlineData("hello world", "HELLO_WORLD")] [InlineData("icH bIn glückLICH", "ICH_BIN_GLÜCKLICH")] - [InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT_STYLE_SPACE_2\nINDENT_SIZE_2")] + [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT_STYLE_SPACE_2\r\nINDENT_SIZE_2")] [InlineData("Hello World!", "HELLO_WORLD")] [InlineData("123 test", "123_TEST")] [InlineData("test with multiple spaces", "TEST_WITH_MULTIPLE_SPACES")] @@ -33,7 +33,7 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri [Theory] [InlineData("hello world", "HELLO_WORLD")] [InlineData("icH bIn glückLICH", "ICH_BIN_GLÜCKLICH")] - [InlineData("indent_style = space, 2-\nindent_size = 2", "INDENT_STYLE_SPACE_2\nINDENT_SIZE_2")] + [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT_STYLE_SPACE_2\r\nINDENT_SIZE_2")] [InlineData("Hello World!", "HELLO_WORLD")] [InlineData("123 test", "123_TEST")] [InlineData("test with multiple spaces", "TEST_WITH_MULTIPLE_SPACES")] diff --git a/TextCase.UnitTests/HashtagCaseConverterTest.cs b/TextCase.UnitTests/HashtagCaseConverterTest.cs index 0e85d52..d0e9178 100644 --- a/TextCase.UnitTests/HashtagCaseConverterTest.cs +++ b/TextCase.UnitTests/HashtagCaseConverterTest.cs @@ -11,7 +11,7 @@ public class HashTagCaseConverterTest [InlineData("hello world", "#hello #world")] [InlineData("icH bIn glückLICH", "#icH #bIn #glückLICH")] [InlineData(" che ore sono? ", "#che #ore #sono?")] - [InlineData("Today i am happy\nToday i am happy", "#Today #i #am #happy\n#Today #i #am #happy")] + [InlineData("Today i am happy\r\nToday i am happy", "#Today #i #am #happy\r\n#Today #i #am #happy")] public void Convert_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output) { // Setup @@ -30,7 +30,7 @@ public void Convert_WhenHashTagCase_TextShouldBeHashTagCase(string input, string [InlineData("hello world", "#hello #world")] [InlineData("icH bIn glückLICH", "#icH #bIn #glückLICH")] [InlineData(" che ore sono? ", "#che #ore #sono?")] - [InlineData("Today i am happy\nToday i am happy", "#Today #i #am #happy\n#Today #i #am #happy")] + [InlineData("Today i am happy\r\nToday i am happy", "#Today #i #am #happy\r\n#Today #i #am #happy")] public void ToHashTagCase_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output) { // Execute diff --git a/TextCase.UnitTests/TrainCaseConverterTest.cs b/TextCase.UnitTests/TrainCaseConverterTest.cs index 208d7a8..311b4eb 100644 --- a/TextCase.UnitTests/TrainCaseConverterTest.cs +++ b/TextCase.UnitTests/TrainCaseConverterTest.cs @@ -14,7 +14,7 @@ public class TrainCaseConverterTest [Theory] [InlineData("hello world", "Hello-World")] [InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")] - [InlineData("indent_style = space, 2-\nindent_size = 2", "Indent-Style-Space-2\nIndent-Size-2")] + [InlineData("indent_style = space, 2-\r\nindent_size = 2", "Indent-Style-Space-2\r\nIndent-Size-2")] [InlineData("Hello World!", "Hello-World")] [InlineData("123 test", "123-Test")] [InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")] @@ -38,7 +38,7 @@ public void Convert_WhenTrainCase_TextShouldBeTrainCase(string input, string exp [Theory] [InlineData("hello world", "Hello-World")] [InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")] - [InlineData("indent_style = space, 2-\nindent_size = 2", "Indent-Style-Space-2\nIndent-Size-2")] + [InlineData("indent_style = space, 2-\r\nindent_size = 2", "Indent-Style-Space-2\r\nIndent-Size-2")] [InlineData("Hello World!", "Hello-World")] [InlineData("123 test", "123-Test")] [InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")] diff --git a/TextCase/Converters/CobolCaseConverter.cs b/TextCase/Converters/CobolCaseConverter.cs index 28511c6..908cb38 100644 --- a/TextCase/Converters/CobolCaseConverter.cs +++ b/TextCase/Converters/CobolCaseConverter.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Text.RegularExpressions; @@ -21,16 +22,16 @@ public string Convert(string text) } // Replace one or more consecutive non-letter, non-digit, non-newline characters with a single dash - var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9\n]+", "-"); + var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9" + Environment.NewLine + "]+", "-"); // Split the text into lines - var lines = replacedPunctuation.Split('\n'); + var lines = replacedPunctuation.Split(new[] { Environment.NewLine }, StringSplitOptions.None); // Convert each line to upper case and trim leading and trailing dashes var processedLines = lines.Select(line => line.Trim().ToUpperInvariant().Trim('-')); // Join the lines back together - return string.Join("\n", processedLines); + return string.Join(Environment.NewLine, processedLines); } } } diff --git a/TextCase/Converters/ConstantCaseConverter.cs b/TextCase/Converters/ConstantCaseConverter.cs index 56f0408..a59d960 100644 --- a/TextCase/Converters/ConstantCaseConverter.cs +++ b/TextCase/Converters/ConstantCaseConverter.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Text.RegularExpressions; namespace TextCase.Converters @@ -21,16 +22,16 @@ public string Convert(string text) } // Replace one or more consecutive non-alphanumeric characters (except newlines) with a single underscore - var replacedPunctuation = Regex.Replace(text, @"[^\w\n]+", "_"); + var replacedPunctuation = Regex.Replace(text, @"[^\w" + Environment.NewLine + "]+", "_"); // Split the text into lines - var lines = replacedPunctuation.Split('\n'); + var lines = replacedPunctuation.Split(new[] { Environment.NewLine }, StringSplitOptions.None); // Convert each line to upper case and trim leading and trailing underscores var processedLines = lines.Select(line => line.Trim().ToUpperInvariant().Trim('_')); // Join the lines back together - return string.Join("\n", processedLines); + return string.Join(Environment.NewLine, processedLines); } } } diff --git a/TextCase/Converters/HashtagCaseConverter.cs b/TextCase/Converters/HashtagCaseConverter.cs index d361533..30fcfd8 100644 --- a/TextCase/Converters/HashtagCaseConverter.cs +++ b/TextCase/Converters/HashtagCaseConverter.cs @@ -20,7 +20,7 @@ public string Convert(string text) return string.Empty; } - var lines = text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); + var lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { var words = lines[i].Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries); @@ -30,7 +30,7 @@ public string Convert(string text) } } - return string.Join("\n", lines); + return string.Join(Environment.NewLine, lines); } } diff --git a/TextCase/Converters/TrainCaseConverter.cs b/TextCase/Converters/TrainCaseConverter.cs index 29f7e6b..95e2440 100644 --- a/TextCase/Converters/TrainCaseConverter.cs +++ b/TextCase/Converters/TrainCaseConverter.cs @@ -26,16 +26,16 @@ public string Convert(string text) } // Replace one or more consecutive non-letter, non-digit, non-newline characters with a single dash - var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9\n]+", "-"); + var replacedPunctuation = Regex.Replace(text, @"[^\p{L}0-9" + Environment.NewLine + "]+", "-"); // Split the text into lines - var lines = replacedPunctuation.Split('\n'); + var lines = replacedPunctuation.Split(new[] { Environment.NewLine }, StringSplitOptions.None); // Convert each line to title case and trim leading and trailing dashes var processedLines = lines.Select(line => CultureInfo.InvariantCulture.TextInfo.ToTitleCase(line.ToLowerInvariant()).Trim('-')); // Join the lines back together - return string.Join("\n", processedLines); + return string.Join(Environment.NewLine, processedLines); } } } diff --git a/TextCase/TextCase.csproj b/TextCase/TextCase.csproj index c657c5c..640890d 100644 --- a/TextCase/TextCase.csproj +++ b/TextCase/TextCase.csproj @@ -2,7 +2,7 @@ net8.0 TextCase - 1.0.10 + 1.0.11 Ottorino Bruni The TextCase library for .NET helps changing the cases of existing texts. true From 74aa9300b11bf3bd1af70178e17362d505460967 Mon Sep 17 00:00:00 2001 From: "Bruni, Ottorino" Date: Mon, 27 May 2024 09:45:36 +0200 Subject: [PATCH 2/2] fix tests environment --- TextCase.UnitTests/CobolCaseConverterTest.cs | 2 -- TextCase.UnitTests/ConstantCaseConverterTest.cs | 2 -- TextCase.UnitTests/HashtagCaseConverterTest.cs | 2 -- TextCase.UnitTests/TrainCaseConverterTest.cs | 2 -- 4 files changed, 8 deletions(-) diff --git a/TextCase.UnitTests/CobolCaseConverterTest.cs b/TextCase.UnitTests/CobolCaseConverterTest.cs index 748e3d0..d34a179 100644 --- a/TextCase.UnitTests/CobolCaseConverterTest.cs +++ b/TextCase.UnitTests/CobolCaseConverterTest.cs @@ -9,7 +9,6 @@ public class CobolCaseConverterTest [Theory] [InlineData("hello world", "HELLO-WORLD")] [InlineData("icH bIn glückLICH", "ICH-BIN-GLÜCKLICH")] - [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT-STYLE-SPACE-2\r\nINDENT-SIZE-2")] [InlineData("Hello World!", "HELLO-WORLD")] [InlineData("123 test", "123-TEST")] [InlineData("test with multiple spaces", "TEST-WITH-MULTIPLE-SPACES")] @@ -33,7 +32,6 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri [Theory] [InlineData("hello world", "HELLO-WORLD")] [InlineData("icH bIn glückLICH", "ICH-BIN-GLÜCKLICH")] - [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT-STYLE-SPACE-2\r\nINDENT-SIZE-2")] [InlineData("Hello World!", "HELLO-WORLD")] [InlineData("123 test", "123-TEST")] [InlineData("test with multiple spaces", "TEST-WITH-MULTIPLE-SPACES")] diff --git a/TextCase.UnitTests/ConstantCaseConverterTest.cs b/TextCase.UnitTests/ConstantCaseConverterTest.cs index 25e2ea2..5a6d715 100644 --- a/TextCase.UnitTests/ConstantCaseConverterTest.cs +++ b/TextCase.UnitTests/ConstantCaseConverterTest.cs @@ -9,7 +9,6 @@ public class ConstantCaseConverterTest [Theory] [InlineData("hello world", "HELLO_WORLD")] [InlineData("icH bIn glückLICH", "ICH_BIN_GLÜCKLICH")] - [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT_STYLE_SPACE_2\r\nINDENT_SIZE_2")] [InlineData("Hello World!", "HELLO_WORLD")] [InlineData("123 test", "123_TEST")] [InlineData("test with multiple spaces", "TEST_WITH_MULTIPLE_SPACES")] @@ -33,7 +32,6 @@ public void Convert_WhenConstantCase_TextShouldBeConstantCase(string input, stri [Theory] [InlineData("hello world", "HELLO_WORLD")] [InlineData("icH bIn glückLICH", "ICH_BIN_GLÜCKLICH")] - [InlineData("indent_style = space, 2-\r\nindent_size = 2", "INDENT_STYLE_SPACE_2\r\nINDENT_SIZE_2")] [InlineData("Hello World!", "HELLO_WORLD")] [InlineData("123 test", "123_TEST")] [InlineData("test with multiple spaces", "TEST_WITH_MULTIPLE_SPACES")] diff --git a/TextCase.UnitTests/HashtagCaseConverterTest.cs b/TextCase.UnitTests/HashtagCaseConverterTest.cs index d0e9178..38c647a 100644 --- a/TextCase.UnitTests/HashtagCaseConverterTest.cs +++ b/TextCase.UnitTests/HashtagCaseConverterTest.cs @@ -11,7 +11,6 @@ public class HashTagCaseConverterTest [InlineData("hello world", "#hello #world")] [InlineData("icH bIn glückLICH", "#icH #bIn #glückLICH")] [InlineData(" che ore sono? ", "#che #ore #sono?")] - [InlineData("Today i am happy\r\nToday i am happy", "#Today #i #am #happy\r\n#Today #i #am #happy")] public void Convert_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output) { // Setup @@ -30,7 +29,6 @@ public void Convert_WhenHashTagCase_TextShouldBeHashTagCase(string input, string [InlineData("hello world", "#hello #world")] [InlineData("icH bIn glückLICH", "#icH #bIn #glückLICH")] [InlineData(" che ore sono? ", "#che #ore #sono?")] - [InlineData("Today i am happy\r\nToday i am happy", "#Today #i #am #happy\r\n#Today #i #am #happy")] public void ToHashTagCase_WhenHashTagCase_TextShouldBeHashTagCase(string input, string output) { // Execute diff --git a/TextCase.UnitTests/TrainCaseConverterTest.cs b/TextCase.UnitTests/TrainCaseConverterTest.cs index 311b4eb..390a9ea 100644 --- a/TextCase.UnitTests/TrainCaseConverterTest.cs +++ b/TextCase.UnitTests/TrainCaseConverterTest.cs @@ -14,7 +14,6 @@ public class TrainCaseConverterTest [Theory] [InlineData("hello world", "Hello-World")] [InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")] - [InlineData("indent_style = space, 2-\r\nindent_size = 2", "Indent-Style-Space-2\r\nIndent-Size-2")] [InlineData("Hello World!", "Hello-World")] [InlineData("123 test", "123-Test")] [InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")] @@ -38,7 +37,6 @@ public void Convert_WhenTrainCase_TextShouldBeTrainCase(string input, string exp [Theory] [InlineData("hello world", "Hello-World")] [InlineData("icH bIn glückLICH", "Ich-Bin-Glücklich")] - [InlineData("indent_style = space, 2-\r\nindent_size = 2", "Indent-Style-Space-2\r\nIndent-Size-2")] [InlineData("Hello World!", "Hello-World")] [InlineData("123 test", "123-Test")] [InlineData("test with multiple spaces", "Test-With-Multiple-Spaces")]