mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Added unit tests for FixEllipsesStart
This commit is contained in:
parent
2534c3b073
commit
f60aa36e81
@ -129,7 +129,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
else if (e.Shift && e.Control && e.Alt && e.KeyCode == Keys.C)
|
||||
{
|
||||
XmlDeserializerGenerator.GenerateCSharpXmlDeserializerForLanguageStructure();
|
||||
LanguageDeserializerGenerator.GenerateCSharpXmlDeserializerForLanguage();
|
||||
}
|
||||
else if (e.KeyCode == Keys.F1)
|
||||
{
|
||||
|
@ -9,6 +9,7 @@ using System.Windows.Forms;
|
||||
using Nikse.SubtitleEdit.Logic;
|
||||
using Nikse.SubtitleEdit.Logic.OCR;
|
||||
using Nikse.SubtitleEdit.Logic.SubtitleFormats;
|
||||
using Nikse.SubtitleEdit.Logic.Forms;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
@ -3435,38 +3436,38 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
Paragraph p = _subtitle.Paragraphs[i];
|
||||
var text = p.Text;
|
||||
if (!text.Contains("..") || !AllowFix(p, fixAction))
|
||||
continue;
|
||||
|
||||
var oldText = text;
|
||||
if (!text.Contains(Environment.NewLine))
|
||||
if (text.Contains("..") && AllowFix(p, fixAction))
|
||||
{
|
||||
text = FixEllipsesStartHelper(text);
|
||||
if(oldText != text)
|
||||
var oldText = text;
|
||||
if (!text.Contains(Environment.NewLine))
|
||||
{
|
||||
p.Text = text;
|
||||
fixCount++;
|
||||
_totalErrors++;
|
||||
AddFixToListView(p, fixAction, oldText, text);
|
||||
text = FixCommonErrorsHelper.FixEllipsesStartHelper(text);
|
||||
if (oldText != text)
|
||||
{
|
||||
p.Text = text;
|
||||
fixCount++;
|
||||
_totalErrors++;
|
||||
AddFixToListView(p, fixAction, oldText, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
var fixedParagraph = string.Empty;
|
||||
for (int k = 0; k < lines.Length; k++)
|
||||
else
|
||||
{
|
||||
var line = lines[k];
|
||||
fixedParagraph += Environment.NewLine + FixEllipsesStartHelper(line);
|
||||
fixedParagraph = fixedParagraph.Trim();
|
||||
}
|
||||
var lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
var fixedParagraph = string.Empty;
|
||||
for (int k = 0; k < lines.Length; k++)
|
||||
{
|
||||
var line = lines[k];
|
||||
fixedParagraph += Environment.NewLine + FixCommonErrorsHelper.FixEllipsesStartHelper(line);
|
||||
fixedParagraph = fixedParagraph.Trim();
|
||||
}
|
||||
|
||||
if (fixedParagraph != text)
|
||||
{
|
||||
p.Text = fixedParagraph;
|
||||
fixCount++;
|
||||
_totalErrors++;
|
||||
AddFixToListView(p, fixAction, oldText, fixedParagraph);
|
||||
if (fixedParagraph != text)
|
||||
{
|
||||
p.Text = fixedParagraph;
|
||||
fixCount++;
|
||||
_totalErrors++;
|
||||
AddFixToListView(p, fixAction, oldText, fixedParagraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3476,72 +3477,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
LogStatus(_language.FixEllipsesStart, string.Format(_language.XFixEllipsesStart, fixCount));
|
||||
}
|
||||
|
||||
private string FixEllipsesStartHelper(string text)
|
||||
{
|
||||
if (text == null || text.Trim().Length < 4)
|
||||
return text;
|
||||
if (!text.Contains(".."))
|
||||
return text;
|
||||
|
||||
if (text.StartsWith("..."))
|
||||
{
|
||||
text = text.TrimStart('.');
|
||||
}
|
||||
|
||||
text = text.Replace("-..", "- ..");
|
||||
var tag = "- ...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "- " + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("- ."))
|
||||
{
|
||||
text = "- " + text.Substring(3, text.Length - 3);
|
||||
text = text.Replace(" ", " ");
|
||||
}
|
||||
}
|
||||
|
||||
tag = "<i>...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "<i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("<i>."))
|
||||
text = "<i>" + text.Substring(4, text.Length - 4);
|
||||
}
|
||||
tag = "<i> ...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "<i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("<i>."))
|
||||
text = "<i>" + text.Substring(4, text.Length - 4);
|
||||
}
|
||||
|
||||
tag = "- <i>...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "- <i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("- <i>."))
|
||||
text = "- <i>" + text.Substring(6, text.Length - 6);
|
||||
}
|
||||
tag = "- <i> ...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "- <i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("- <i>."))
|
||||
text = "- <i>" + text.Substring(6, text.Length - 6);
|
||||
}
|
||||
|
||||
// Narrator:... Hello foo!
|
||||
text = text.Replace(":..", ": ..");
|
||||
tag = ": ..";
|
||||
if(text.Contains(tag))
|
||||
{
|
||||
text = text.Replace(": ..", ": ");
|
||||
while (text.Contains(": ."))
|
||||
text = text.Replace(": .", ": ");
|
||||
}
|
||||
text = text.Replace(" ", " ");
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
private string FixMissingOpenBracket(string text, string openB)
|
||||
{
|
||||
|
83
src/Logic/Forms/FixCommonErrorsHelper.cs
Normal file
83
src/Logic/Forms/FixCommonErrorsHelper.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.Forms
|
||||
{
|
||||
public static class FixCommonErrorsHelper
|
||||
{
|
||||
|
||||
public static string FixEllipsesStartHelper(string text)
|
||||
{
|
||||
if (text == null || text.Trim().Length < 4)
|
||||
return text;
|
||||
if (!text.Contains(".."))
|
||||
return text;
|
||||
|
||||
if (text.StartsWith("..."))
|
||||
{
|
||||
text = text.TrimStart('.').TrimStart();
|
||||
}
|
||||
|
||||
text = text.Replace("-..", "- ..");
|
||||
var tag = "- ...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "- " + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("- ."))
|
||||
{
|
||||
text = "- " + text.Substring(3, text.Length - 3);
|
||||
text = text.Replace(" ", " ");
|
||||
}
|
||||
}
|
||||
|
||||
tag = "<i>...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "<i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("<i>."))
|
||||
text = "<i>" + text.Substring(4, text.Length - 4);
|
||||
while (text.StartsWith("<i> "))
|
||||
text = "<i>" + text.Substring(4, text.Length - 4);
|
||||
}
|
||||
tag = "<i> ...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "<i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("<i>."))
|
||||
text = "<i>" + text.Substring(4, text.Length - 4);
|
||||
while (text.StartsWith("<i> "))
|
||||
text = "<i>" + text.Substring(4, text.Length - 4);
|
||||
}
|
||||
|
||||
tag = "- <i>...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "- <i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("- <i>."))
|
||||
text = "- <i>" + text.Substring(6, text.Length - 6);
|
||||
}
|
||||
tag = "- <i> ...";
|
||||
if (text.StartsWith(tag))
|
||||
{
|
||||
text = "- <i>" + text.Substring(tag.Length, text.Length - tag.Length);
|
||||
while (text.StartsWith("- <i>."))
|
||||
text = "- <i>" + text.Substring(6, text.Length - 6);
|
||||
}
|
||||
|
||||
// Narrator:... Hello foo!
|
||||
text = text.Replace(":..", ": ..");
|
||||
tag = ": ..";
|
||||
if (text.Contains(tag))
|
||||
{
|
||||
text = text.Replace(": ..", ": ");
|
||||
while (text.Contains(": ."))
|
||||
text = text.Replace(": .", ": ");
|
||||
}
|
||||
text = text.Replace(" ", " ");
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -760,6 +760,7 @@
|
||||
<Compile Include="Logic\ColorChooser\ColorHandler.cs" />
|
||||
<Compile Include="Logic\ColorChooser\ColorWheel.cs" />
|
||||
<Compile Include="Logic\Forms\CheckForUpdatesHelper.cs" />
|
||||
<Compile Include="Logic\Forms\FixCommonErrorsHelper.cs" />
|
||||
<Compile Include="Logic\Forms\RemoveTextForHISettings.cs" />
|
||||
<Compile Include="Logic\Forms\RemoveTextForHI.cs" />
|
||||
<Compile Include="Logic\Forms\SplitLongLinesHelper.cs" />
|
||||
@ -1137,7 +1138,7 @@
|
||||
<Compile Include="Logic\VobSub\VobSubPack.cs" />
|
||||
<Compile Include="Logic\VobSub\VobSubWriter.cs" />
|
||||
<Compile Include="Logic\WordSpellChecker.cs" />
|
||||
<Compile Include="Logic\XmlDeserializerGenerator.cs" />
|
||||
<Compile Include="Logic\LanguageDeserializerGenerator.cs" />
|
||||
<Compile Include="Logic\XSub.cs" />
|
||||
<Compile Include="Logic\zlib\Adler32.cs" />
|
||||
<Compile Include="Logic\zlib\Deflate.cs" />
|
||||
|
@ -3,6 +3,7 @@ using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Nikse.SubtitleEdit.Forms;
|
||||
using Nikse.SubtitleEdit.Logic;
|
||||
using Nikse.SubtitleEdit.Logic.Forms;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
@ -571,6 +572,72 @@ namespace Test
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Ellipses start
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartNormal1()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("...But that is true.");
|
||||
Assert.AreEqual(result, "But that is true.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartNormal2()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("... But that is true.");
|
||||
Assert.AreEqual(result, "But that is true.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartNormal3()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("Kurt: ... true but bad.");
|
||||
Assert.AreEqual(result, "Kurt: true but bad.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartNormal4()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("Kurt: ... true but bad.");
|
||||
Assert.AreEqual(result, "Kurt: true but bad.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartItalic1()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>...But that is true.</i>");
|
||||
Assert.AreEqual(result, "<i>But that is true.</i>");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartItalic2()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>... But that is true.</i>");
|
||||
Assert.AreEqual(result, "<i>But that is true.</i>");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartItalic3()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
|
||||
Assert.AreEqual(result, "<i>Kurt: true but bad.</i>");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixEllipsesStartItalic4()
|
||||
{
|
||||
var result = FixCommonErrorsHelper.FixEllipsesStartHelper("<i>Kurt: ... true but bad.</i>");
|
||||
Assert.AreEqual(result, "<i>Kurt: true but bad.</i>");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
@ -602,8 +669,5 @@ namespace Test
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Yeah, see, that's not mine.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user