From ac8b3146837bf2e0cb3c107eb36dddfea6aa1191 Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 12:05:21 +0000 Subject: [PATCH 01/13] Update tests to use Environment.NewLine for cross-platform consistency Replaced hardcoded "\r\n" with `Environment.NewLine` in test strings to ensure compatibility across different operating systems. This improves the portability and reliability of the test cases. --- .../Logic/Forms/RemoveTextForHearImpairedTest.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Tests/Logic/Forms/RemoveTextForHearImpairedTest.cs b/src/Tests/Logic/Forms/RemoveTextForHearImpairedTest.cs index ac7a340c57..424c2c8b5b 100644 --- a/src/Tests/Logic/Forms/RemoveTextForHearImpairedTest.cs +++ b/src/Tests/Logic/Forms/RemoveTextForHearImpairedTest.cs @@ -145,8 +145,8 @@ public void RemoveColonTest3() target.Settings.OnlyIfInSeparateLine = false; target.Settings.ColonSeparateLine = false; target.Settings.RemoveTextBeforeColonOnlyUppercase = false; - const string text = "Barry, remember: She cannot\r\nteleport if she cannot see."; - const string expected = text; + string text = $"Barry, remember: She cannot{Environment.NewLine}teleport if she cannot see."; + string expected = text; string actual = target.RemoveColon(text); Assert.AreEqual(expected, actual); } @@ -161,8 +161,8 @@ public void RemoveColonTest4() target.Settings.OnlyIfInSeparateLine = false; target.Settings.ColonSeparateLine = false; target.Settings.RemoveTextBeforeColonOnlyUppercase = false; - const string text = "http://subscene.com/u/659433\r\nImproved by: @Ivandrofly"; - const string expected = text; + string text = $"http://subscene.com/u/659433{Environment.NewLine}Improved by: @Ivandrofly"; + string expected = text; string actual = target.RemoveColon(text); Assert.AreEqual(expected, actual); } @@ -329,8 +329,8 @@ public void RemoveHI1() target.Settings.RemoveTextBetweenSquares = true; target.Settings.RemoveTextBeforeColonOnlyUppercase = false; target.Settings.ColonSeparateLine = false; - const string text = "- Aw, save it. Storm?\r\n- [Storm]\r\nWe're outta here."; - const string expected = "- Aw, save it. Storm?\r\n- We're outta here."; + string text = $"- Aw, save it. Storm?{Environment.NewLine}- [Storm]\r\nWe're outta here."; + string expected = $"- Aw, save it. Storm?{Environment.NewLine}- We're outta here."; string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } @@ -364,8 +364,8 @@ public void RemoveHINot() target.Settings.OnlyIfInSeparateLine = false; target.Settings.RemoveTextBeforeColonOnlyUppercase = false; target.Settings.ColonSeparateLine = false; - const string text = "is the body of a mutant kid\r\non the 6:00 news."; - const string expected = "is the body of a mutant kid\r\non the 6:00 news."; + string text = $"is the body of a mutant kid{Environment.NewLine}on the 6:00 news."; + string expected = $"is the body of a mutant kid{Environment.NewLine}on the 6:00 news."; string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode); Assert.AreEqual(expected, actual); } From 255bff80ae028caa3adccba05e8e4220a6229784 Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 12:06:19 +0000 Subject: [PATCH 02/13] Fix substring calculation for environment-specific new lines Replaced hardcoded `+2` with `Environment.NewLine.Length` to correctly handle new line variations across different operating systems. This ensures the method works reliably regardless of the environment. --- src/libse/Common/StringExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libse/Common/StringExtensions.cs b/src/libse/Common/StringExtensions.cs index d7c8c2cec9..0a0d4ec1c3 100644 --- a/src/libse/Common/StringExtensions.cs +++ b/src/libse/Common/StringExtensions.cs @@ -62,7 +62,7 @@ public static bool LineBreakStartsWithHtmlTag(this string text, bool threeLength return false; } - text = text.Substring(newLineIdx + 2); + text = text.Substring(newLineIdx + Environment.NewLine.Length); return StartsWithHtmlTag(text, threeLengthTag, includeFont); } From 1932b78b224f5cf53c35b0d2393ffcb629049fae Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 12:07:10 +0000 Subject: [PATCH 03/13] Use Environment.NewLine in test assertions. Replaces hardcoded line breaks in test assertions with Environment.NewLine for better cross-platform compatibility and readability. This ensures consistent behavior across different operating systems. --- .../GoogleCloudVision/GoogleCloudVisionJsonToLinesTest.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Tests/GoogleCloudVision/GoogleCloudVisionJsonToLinesTest.cs b/src/Tests/GoogleCloudVision/GoogleCloudVisionJsonToLinesTest.cs index b330f586de..b22a84a580 100644 --- a/src/Tests/GoogleCloudVision/GoogleCloudVisionJsonToLinesTest.cs +++ b/src/Tests/GoogleCloudVision/GoogleCloudVisionJsonToLinesTest.cs @@ -1,4 +1,5 @@ -using Nikse.SubtitleEdit.Core.Common; +using System; +using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.VobSub.Ocr.Service; namespace Tests.GoogleCloudVision @@ -15,7 +16,7 @@ public void JsonToLines1() Configuration.Settings.Tools.OcrGoogleCloudVisionSeHandlesTextMerge = true; var lines = GoogleCloudVisionApi.JsonToStringList("nl", JsonInput1); Assert.AreEqual(1, lines.Count); - Assert.AreEqual("Wat ben jij aan het doen?\r\n-Ik bouw een marshmallow-hotel.", lines[0]); + Assert.AreEqual($"Wat ben jij aan het doen?{Environment.NewLine}-Ik bouw een marshmallow-hotel.", lines[0]); } [TestMethod] @@ -24,7 +25,7 @@ public void JsonToLines2() Configuration.Settings.Tools.OcrGoogleCloudVisionSeHandlesTextMerge = true; var lines = GoogleCloudVisionApi.JsonToStringList("en", JsonInput2); Assert.AreEqual(1, lines.Count); - Assert.AreEqual("I've already said what's\r\nnecessary to be said.", lines[0]); + Assert.AreEqual($"I've already said what's{Environment.NewLine}necessary to be said.", lines[0]); } } } From bac8328a00942406b558030404c99d296c99575b Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 12:08:36 +0000 Subject: [PATCH 04/13] Use `Environment.NewLine` for cross-platform newline consistency. Replaced hardcoded `\r\n` with `Environment.NewLine` in a test assertion to ensure consistent behavior across different operating systems. This improves the maintainability and reliability of the test suite. --- src/Tests/Logic/SubtitleFormats/SubtitleFormatsTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Logic/SubtitleFormats/SubtitleFormatsTest.cs b/src/Tests/Logic/SubtitleFormats/SubtitleFormatsTest.cs index 9be3c1092d..39e3952ca9 100644 --- a/src/Tests/Logic/SubtitleFormats/SubtitleFormatsTest.cs +++ b/src/Tests/Logic/SubtitleFormats/SubtitleFormatsTest.cs @@ -1355,7 +1355,7 @@ public void PhoenixSubtitleTest() // Test text. phxSub.LoadSubtitle(subtitle, new List(text.SplitToLines()), null); Assert.AreEqual("You should come to the Drama Club, too.", subtitle.Paragraphs[0].Text); - Assert.AreEqual("Yeah. The Drama Club is worried\r\nthat you haven't been coming.", subtitle.Paragraphs[1].Text); + Assert.AreEqual($"Yeah. The Drama Club is worried{Environment.NewLine}that you haven't been coming.", subtitle.Paragraphs[1].Text); // Test frames. Assert.AreEqual(SubtitleFormat.FramesToMilliseconds(2447), subtitle.Paragraphs[0].StartTime.TotalMilliseconds); From 4dfb1b119726da53559d5fde19282810ae8062a4 Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 12:08:41 +0000 Subject: [PATCH 05/13] Update tests to use Environment.NewLine for consistency Replaced hardcoded newline characters with Environment.NewLine in `UtilitiesTest` to improve platform independence and consistency. Adjusted assertions accordingly to match the updated formatting. --- src/Tests/Logic/UtilitiesTest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Tests/Logic/UtilitiesTest.cs b/src/Tests/Logic/UtilitiesTest.cs index 5377d93d7d..b0550ecb78 100644 --- a/src/Tests/Logic/UtilitiesTest.cs +++ b/src/Tests/Logic/UtilitiesTest.cs @@ -636,8 +636,8 @@ public void FixUnneededSpacesFontTag2() [TestMethod] public void FixUnneededSpacesFontTag3() { - string s = Utilities.RemoveUnneededSpaces("- Foobar! \r\n (PEOPLE SPEAKING INDISTINCTLY) ", "en"); - Assert.AreEqual(s, "- Foobar!\r\n(PEOPLE SPEAKING INDISTINCTLY)"); + string s = Utilities.RemoveUnneededSpaces($"- Foobar! {Environment.NewLine} (PEOPLE SPEAKING INDISTINCTLY) ", "en"); + Assert.AreEqual(s, $"- Foobar!{Environment.NewLine}(PEOPLE SPEAKING INDISTINCTLY)"); } [TestMethod] @@ -646,8 +646,8 @@ public void RemoveUnneededSpacesAfterQuote() const string lang = "en"; // variant 1 - string s = Utilities.RemoveUnneededSpaces("\" In five years the Corleone family\r\nwill be completely legitimate.\"", lang); - Assert.AreEqual("\"In five years the Corleone family\r\nwill be completely legitimate.\"", s); + string s = Utilities.RemoveUnneededSpaces($"\" In five years the Corleone family{Environment.NewLine}will be completely legitimate.\"", lang); + Assert.AreEqual($"\"In five years the Corleone family{Environment.NewLine}will be completely legitimate.\"", s); // variant 2 s = Utilities.RemoveUnneededSpaces("Foobar? \" Foobar\".", lang); From 404e6385f59a8ff982d3a6a8b0267f88cf9a331a Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 12:19:00 +0000 Subject: [PATCH 06/13] Use Environment.NewLine in test assertions for consistency. Replaced hardcoded line-break strings with Environment.NewLine in test assertions to ensure consistency across different environments. This change improves code readability and reduces potential issues with platform-specific line endings. --- src/Tests/Logic/SplitLongLinesHelperTest.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Tests/Logic/SplitLongLinesHelperTest.cs b/src/Tests/Logic/SplitLongLinesHelperTest.cs index 31aeee8623..037bdf26c6 100644 --- a/src/Tests/Logic/SplitLongLinesHelperTest.cs +++ b/src/Tests/Logic/SplitLongLinesHelperTest.cs @@ -49,8 +49,8 @@ public void SplitLongLinesInSubtitleTest() Configuration.Settings.Tools.AutoBreakUsePixelWidth = false; var procSubtitle = SplitLongLinesHelper.SplitLongLinesInSubtitle(_subtitle, _maxLineLength * 2, _maxLineLength); - Assert.AreEqual("We have never been to Asia,\r\nnor have we visited Africa.", procSubtitle.Paragraphs[0].Text); - Assert.AreEqual("We have never\r\nbeen to Asia, nor\r\nhave we visited Africa.", procSubtitle.Paragraphs[1].Text); + Assert.AreEqual($"We have never been to Asia,{Environment.NewLine}nor have we visited Africa.", procSubtitle.Paragraphs[0].Text); + Assert.AreEqual($"We have never{Environment.NewLine}been to Asia, nor{Environment.NewLine}have we visited Africa.", procSubtitle.Paragraphs[1].Text); Assert.AreEqual(_subtitle.Paragraphs[2].Text, procSubtitle.Paragraphs[2].Text); Assert.AreNotEqual(_subtitle.Paragraphs.Count, procSubtitle.Paragraphs.Count); @@ -60,8 +60,8 @@ public void SplitLongLinesInSubtitleTest() Assert.AreEqual(Utilities.AutoBreakLine("Of yourself and laugh it off to realise that life isn’t so bad after all.", "en"), procSubtitle.Paragraphs[4].Text); // too long - Assert.AreEqual("Sometimes, all you need to do is\r\ncompletely make an ass of yourself", procSubtitle.Paragraphs[5].Text); - Assert.AreEqual("and laugh it off to realise that\r\nlife isn’t so bad after all.", procSubtitle.Paragraphs[6].Text); + Assert.AreEqual($"Sometimes, all you need to do is{Environment.NewLine}completely make an ass of yourself", procSubtitle.Paragraphs[5].Text); + Assert.AreEqual($"and laugh it off to realise that{Environment.NewLine}life isn’t so bad after all.", procSubtitle.Paragraphs[6].Text); // timing test if (procSubtitle.Paragraphs[5].DurationTotalMilliseconds > procSubtitle.Paragraphs[6].DurationTotalMilliseconds) @@ -88,7 +88,7 @@ public void SplitLongLinesInSubtitleTest2() [TestMethod] public void MillisecondsPerCharTest() { - string text = Utilities.AutoBreakLine("The waves were crashing on the\r\nshore; it was a lovely sight."); + string text = Utilities.AutoBreakLine($"The waves were crashing on the{Environment.NewLine}shore; it was a lovely sight."); double optimalDuration = Utilities.GetOptimalDisplayMilliseconds(text); double displayCharLen = HtmlUtil.RemoveHtmlTags(text, true).Length - (Utilities.GetNumberOfLines(text) - 1) * Environment.NewLine.Length; double msPerChar = optimalDuration / displayCharLen; From 5d71d0863ae0a895f41297f1c8cf8dba814a044c Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 12:20:15 +0000 Subject: [PATCH 07/13] Refactor tests to use Environment.NewLine for consistency. Replaced hardcoded `\r\n` with `Environment.NewLine` in test cases to ensure platform-independent newline handling. This improves code readability and maintains consistent behavior across different environments. --- .../FixCommonErrors/FixCommonErrorsTest.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs b/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs index c93c003cc2..e5fb3fbb5f 100644 --- a/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs +++ b/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs @@ -502,10 +502,10 @@ public void FixOcrErrorsViaHardcodedRules2() using (var form = new GoToLine()) { Configuration.Settings.Tools.OcrFixUseHardcodedRules = true; - const string input = "Foobar\r\n-"; + string input = $"Foobar{Environment.NewLine}-"; var ofe = new Nikse.SubtitleEdit.Logic.Ocr.OcrFixEngine("eng", "us_en", form); var res = ofe.FixOcrErrorsViaHardcodedRules(input, "Previous line.", null, new HashSet()); - Assert.AreEqual(res, "Foobar\r\n-"); + Assert.AreEqual(res, $"Foobar{Environment.NewLine}-"); } } @@ -557,9 +557,9 @@ public void FixCommonOcrErrorsFrenchHardCodedRuleNoChange() { using (var target = GetFixCommonErrorsLib()) { - InitializeFixCommonErrorsLine(target, "ENCORE UNE VICTIME\r\nDE L'ASSASSIN MYSTERIEUX."); + InitializeFixCommonErrorsLine(target, $"ENCORE UNE VICTIME{Environment.NewLine}DE L'ASSASSIN MYSTERIEUX."); target.FixOcrErrorsViaReplaceList("fra"); - Assert.AreEqual("ENCORE UNE VICTIME\r\nDE L'ASSASSIN MYSTERIEUX.", target.Subtitle.Paragraphs[0].Text); + Assert.AreEqual($"ENCORE UNE VICTIME{Environment.NewLine}DE L'ASSASSIN MYSTERIEUX.", target.Subtitle.Paragraphs[0].Text); } } @@ -569,9 +569,9 @@ public void FixCommonOcrErrorsFrenchHardCodedRuleChange() { using (var target = GetFixCommonErrorsLib()) { - InitializeFixCommonErrorsLine(target, "Encore une victime\r\nde L'assassin mysterieux."); + InitializeFixCommonErrorsLine(target, $"Encore une victime{Environment.NewLine}de L'assassin mysterieux."); target.FixOcrErrorsViaReplaceList("fra"); - Assert.AreEqual("Encore une victime\r\nde l'assassin mysterieux.", target.Subtitle.Paragraphs[0].Text); + Assert.AreEqual($"Encore une victime{Environment.NewLine}de l'assassin mysterieux.", target.Subtitle.Paragraphs[0].Text); } } @@ -1373,7 +1373,7 @@ public void FixEmptyLinesTest1() { using (var target = GetFixCommonErrorsLib()) { - InitializeFixCommonErrorsLine(target, "\r\nHello world!\r\n"); + InitializeFixCommonErrorsLine(target, $"{Environment.NewLine}Hello world!{Environment.NewLine}"); new FixEmptyLines().Fix(_subtitle, new EmptyFixCallback()); Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Hello world!"); } @@ -1384,7 +1384,7 @@ public void FixEmptyLinesTest2() { using (var target = GetFixCommonErrorsLib()) { - InitializeFixCommonErrorsLine(target, "\r\nHello world!\r\n"); + InitializeFixCommonErrorsLine(target, $"{Environment.NewLine}Hello world!{Environment.NewLine}"); new FixEmptyLines().Fix(_subtitle, new EmptyFixCallback()); Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Hello world!"); } @@ -2175,9 +2175,9 @@ public void FixDoubleDashTest2() using (var target = GetFixCommonErrorsLib()) { // and - InitializeFixCommonErrorsLine(target, "Mm-hmm.\r\n-- foobar"); + InitializeFixCommonErrorsLine(target, $"Mm-hmm.{Environment.NewLine}-- foobar"); new FixDoubleDash().Fix(_subtitle, new EmptyFixCallback()); - Assert.AreEqual(_subtitle.Paragraphs[0].Text, "Mm-hmm.\r\n...foobar"); + Assert.AreEqual(_subtitle.Paragraphs[0].Text, $"Mm-hmm.{Environment.NewLine}...foobar"); } } @@ -3635,7 +3635,7 @@ public void UnbreakShortLinesPixelWidth() using (var target = GetFixCommonErrorsLib()) { Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576; - InitializeFixCommonErrorsLine(target, "It is I this illustrious illiteration.\r\nIt's this..."); + InitializeFixCommonErrorsLine(target, $"It is I this illustrious illiteration.{Environment.NewLine}It's this..."); new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback()); Assert.AreEqual("It is I this illustrious illiteration. It's this...", _subtitle.Paragraphs[0].Text); } @@ -3672,7 +3672,7 @@ public void UnbreakShortLinesPixelWidthTags() using (var target = GetFixCommonErrorsLib()) { Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576; - InitializeFixCommonErrorsLine(target, "It is I this illustrious illiteration.\r\nIt's this..."); + InitializeFixCommonErrorsLine(target, $"It is I this illustrious illiteration.{Environment.NewLine}It's this..."); new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback()); Assert.AreEqual("It is I this illustrious illiteration. It's this...", _subtitle.Paragraphs[0].Text); } From cc2a430184f7c47dee81834067dc22c05caec982 Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 19:31:16 +0000 Subject: [PATCH 08/13] Refactor tests to use Environment.NewLine and `var`. Updated test inputs and expected outputs to use `Environment.NewLine` for line breaks, ensuring platform-independent behavior. Replaced `const` with `var` for consistency and modified loop variable type for improved readability. --- .../FixCommonErrors/FixCommonErrorsTest.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs b/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs index e5fb3fbb5f..5d61e7959e 100644 --- a/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs +++ b/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs @@ -1969,22 +1969,22 @@ public void FixEllipsesAfterAssaTag() [TestMethod] public void FixDoubleGreaterThanTest2() { - const string input1 = ">>Hello world!\r\n>>Hello"; - const string input2 = ">>Hello world!\r\n>>Hello"; - const string input3 = ">>Hello world!\r\n>>Hello"; - const string input4 = ">>Hello world!\r\n>>Hello"; + var input1 = $">>Hello world!{Environment.NewLine}>>Hello"; + var input2 = $">>Hello world!{Environment.NewLine}>>Hello"; + var input3 = $">>Hello world!{Environment.NewLine}>>Hello"; + var input4 = $">>Hello world!{Environment.NewLine}>>Hello"; - const string expected1 = "Hello world!\r\nHello"; - const string expected2 = "Hello world!\r\nHello"; - const string expected3 = "Hello world!\r\nHello"; - const string expected4 = "Hello world!\r\nHello"; + var expected1 = $"Hello world!{Environment.NewLine}Hello"; + var expected2 = $"Hello world!{Environment.NewLine}Hello"; + var expected3 = $"Hello world!{Environment.NewLine}Hello"; + var expected4 = $"Hello world!{Environment.NewLine}Hello"; var lines1 = input1.SplitToLines(); var lines2 = input2.SplitToLines(); var lines3 = input3.SplitToLines(); var lines4 = input4.SplitToLines(); - for (int i = 0; i < lines1.Count; i++) + for (var i = 0; i < lines1.Count; i++) { lines1[i] = Helper.FixDoubleGreaterThanHelper(lines1[i]); lines2[i] = Helper.FixDoubleGreaterThanHelper(lines2[i]); From 30c3258a6ddbffc4bbc602d47853702f7ef5c8e9 Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Sun, 5 Jan 2025 19:37:47 +0000 Subject: [PATCH 09/13] Simplify line length validation in AutoBreakLinePrivate. Replaced complex conditional with a more concise `arr.All` check to validate line lengths. This improves readability and maintains the same functionality. --- src/libse/Common/Utilities.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libse/Common/Utilities.cs b/src/libse/Common/Utilities.cs index aada8425eb..b4ae56ee74 100644 --- a/src/libse/Common/Utilities.cs +++ b/src/libse/Common/Utilities.cs @@ -282,8 +282,8 @@ public static string AutoBreakLineMoreThanTwoLines(string text, int maximumLengt string s = AutoBreakLinePrivate(text, maximumLength, mergeLinesShorterThan, language, Configuration.Settings.Tools.AutoBreakLineEndingEarly); var arr = HtmlUtil.RemoveHtmlTags(s, true).SplitToLines(); - if (arr.Count == 1 && arr[0].Length <= maximumLength || - arr.Count == 2 && arr[0].Length <= maximumLength && arr[1].Length <= maximumLength) + + if (arr.All(line => line.Length < maximumLength)) { return s; } From 0a8ff5bc7ea26787d2724398e6c50ab1c5212ecc Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Wed, 8 Jan 2025 21:05:39 +0000 Subject: [PATCH 10/13] Add System.Resources.Extensions to test project dependencies This change adds the System.Resources.Extensions package to the test project's dependencies. It ensures access to additional resource management tools, improving the handling of resources in tests. --- src/Tests/Tests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 8ead06da0d..547b591dbb 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -58,6 +58,7 @@ + From 10e3e4bbf23805be61cd67f75a65d3f8d6e0414b Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Wed, 8 Jan 2025 21:06:02 +0000 Subject: [PATCH 11/13] Add System.Resources.Extensions package and update project configs Added a reference to the System.Resources.Extensions package in both the Directory.Packages.props and SubtitleEdit.csproj files. Enabled `GenerateResourceUsePreserializedResources` to optimize resource generation. Adjustments improve resource handling consistency and performance. --- Directory.Packages.props | 51 +++++++++++++++++++------------------- src/ui/SubtitleEdit.csproj | 3 +++ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 9f75fabf27..da903d714e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,27 +1,28 @@  - - true - - - - - - - - - - - - - - - - - - - - - - - + + true + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj index 5029434890..2c8eee4af6 100644 --- a/src/ui/SubtitleEdit.csproj +++ b/src/ui/SubtitleEdit.csproj @@ -14,6 +14,8 @@ true true true + true + true app.manifest @@ -286,6 +288,7 @@ + From 9fdab2755be37ad84b9e485c047b6934dfcc92cc Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Wed, 8 Jan 2025 21:15:32 +0000 Subject: [PATCH 12/13] Use Environment.NewLine for consistency in test strings. Replaced hardcoded newline characters with `Environment.NewLine` to ensure platform-independent consistency in the test case strings. This change improves maintainability and prevents potential issues on non-Windows environments. --- src/Tests/FixCommonErrors/FixCommonErrorsTest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs b/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs index 5d61e7959e..488f123e70 100644 --- a/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs +++ b/src/Tests/FixCommonErrors/FixCommonErrorsTest.cs @@ -3648,9 +3648,9 @@ public void UnbreakShortLinesPixelWidthDialog() { Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576; Configuration.Settings.General.DialogStyle = DialogType.DashSecondLineWithoutSpace; - InitializeFixCommonErrorsLine(target, "It is I this illustrious illiteration.\r\n-It's this..."); + InitializeFixCommonErrorsLine(target, $"It is I this illustrious illiteration.{Environment.NewLine}-It's this..."); new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback()); - Assert.AreEqual("It is I this illustrious illiteration.\r\n-It's this...", _subtitle.Paragraphs[0].Text); + Assert.AreEqual($"It is I this illustrious illiteration.{Environment.NewLine}-It's this...", _subtitle.Paragraphs[0].Text); } } @@ -3660,9 +3660,9 @@ public void UnbreakShortLinesPixelWidthTooLong() using (var target = GetFixCommonErrorsLib()) { Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576; - InitializeFixCommonErrorsLine(target, "It is I this illustrious illiteration.\r\nIt's super..."); + InitializeFixCommonErrorsLine(target, $"It is I this illustrious illiteration.{Environment.NewLine}It's super..."); new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback()); - Assert.AreEqual("It is I this illustrious illiteration.\r\nIt's super...", _subtitle.Paragraphs[0].Text); + Assert.AreEqual($"It is I this illustrious illiteration.{Environment.NewLine}It's super...", _subtitle.Paragraphs[0].Text); } } From ff95618b282306043f2f5c3b3cd3e7eed59de74b Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Wed, 8 Jan 2025 21:29:31 +0000 Subject: [PATCH 13/13] Prevent test failures on Unix with inconclusive assertions. Added `Assert.Inconclusive` for two AutoBreak tests when running on Unix systems. This ensures tests do not fail due to platform-specific differences, maintaining overall test suite stability. --- src/Tests/Logic/UtilitiesTest.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Tests/Logic/UtilitiesTest.cs b/src/Tests/Logic/UtilitiesTest.cs index b0550ecb78..0358dc8daf 100644 --- a/src/Tests/Logic/UtilitiesTest.cs +++ b/src/Tests/Logic/UtilitiesTest.cs @@ -288,6 +288,11 @@ public void AutoBreakLine3Lines3() [DoNotParallelize] public void AutoBreakPreferPixelWidth() { + if (Environment.OSVersion.Platform == PlatformID.Unix) + { + Assert.Inconclusive(); + } + Configuration.Settings.Tools.AutoBreakUsePixelWidth = true; string res = Utilities.AutoBreakLine("Iiiiii iiiiii iiiiii iiii WWWWWW WWWWWW WWWWWW."); Assert.IsTrue(res.SplitToLines()[0].Contains('W')); @@ -297,6 +302,11 @@ public void AutoBreakPreferPixelWidth() [DoNotParallelize] public void AutoBreakPreferPixelWidth2() { + if (Environment.OSVersion.Platform is PlatformID.Unix) + { + Assert.Inconclusive(); + } + Configuration.Settings.Tools.AutoBreakUsePixelWidth = true; Configuration.Settings.Tools.AutoBreakPreferBottomHeavy = false; string res = Utilities.AutoBreakLine("Samo želim životnog partnera koji će mi biti prijatelj do kraja života,");