Fixed minor issue with "Remove text for HI" + unit tests

This commit is contained in:
niksedk 2014-10-07 20:07:11 +02:00
parent 5c72dcff9c
commit f6c7dc2a30
2 changed files with 101 additions and 50 deletions

View File

@ -1,9 +1,9 @@
using System;
using Nikse.SubtitleEdit.Core;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using Nikse.SubtitleEdit.Core;
namespace Nikse.SubtitleEdit.Logic.Forms
{
@ -92,14 +92,14 @@ namespace Nikse.SubtitleEdit.Logic.Forms
if (indexOfColon > 0)
{
string pre = s.Substring(0, indexOfColon);
if (Settings.RemoveTextBeforeColonOnlyUppercase && pre.Replace("<i>", string.Empty) != pre.Replace("<i>", string.Empty).ToUpper())
if (Settings.RemoveTextBeforeColonOnlyUppercase && Utilities.RemoveHtmlTags(pre, true) != Utilities.RemoveHtmlTags(pre, true).ToUpper())
{
newText = newText + Environment.NewLine + s;
newText = newText.Trim();
}
else
{
StripableText st = new StripableText(pre);
var st = new StripableText(pre);
if (count == 1 && Utilities.CountTagInText(text, Environment.NewLine) == 1 && removedInFirstLine && Utilities.CountTagInText(s, ":") == 1 &&
!newText.EndsWith('.') && !newText.EndsWith('!') && !newText.EndsWith('?') && !newText.EndsWith(".</i>") && !newText.EndsWith("!</i>") && !newText.EndsWith("?</i>") &&
s != s.ToUpper())
@ -282,7 +282,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
{
if (indexOfDialogChar < 0 || indexOfDialogChar > 4)
{
StripableText st = new StripableText(newText, "", "");
var st = new StripableText(newText, "", "");
newText = st.Pre + "- " + st.StrippedText + st.Post;
}
@ -291,7 +291,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
indexOfDialogChar = second.IndexOf('-');
if (indexOfDialogChar < 0 || indexOfDialogChar > 6)
{
StripableText st = new StripableText(second, "", "");
var st = new StripableText(second, "", "");
second = st.Pre + "- " + st.StrippedText + st.Post;
newText = newText.Remove(indexOfNewLine) + Environment.NewLine + second;
}
@ -299,7 +299,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
}
else if (!newText.Contains(Environment.NewLine) && newText.Contains('-'))
{
StripableText st = new StripableText(newText);
var st = new StripableText(newText);
if (st.Pre.Contains('-'))
newText = st.Pre.Replace("-", string.Empty) + st.StrippedText + st.Post;
}
@ -345,7 +345,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
int noOfNamesRemovedNotInLineOne = 0;
foreach (string s in parts)
{
StripableText stSub = new StripableText(s, pre, post);
var stSub = new StripableText(s, pre, post);
if (!StartAndEndsWithHearImpariedTags(stSub.StrippedText))
{
if (removedDialogInFirstLine && stSub.Pre.Contains("- "))
@ -414,7 +414,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
string[] a = Utilities.RemoveHtmlTags(text).Replace(" ", string.Empty).Split(new[] { '!', '?', '.' }, StringSplitOptions.RemoveEmptyEntries);
if (a.Length == 2)
{
StripableText temp = new StripableText(text);
var temp = new StripableText(text);
temp.StrippedText = temp.StrippedText.Replace(Environment.NewLine, " ");
int splitIndex = temp.StrippedText.LastIndexOf('!');
if (splitIndex == -1)
@ -554,7 +554,7 @@ namespace Nikse.SubtitleEdit.Logic.Forms
{
string oldText = text;
string[] arr = Configuration.Settings.Tools.Interjections.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
var arr = Configuration.Settings.Tools.Interjections.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (_interjectionList == null)
{
_interjectionList = new List<string>();

View File

@ -9,11 +9,11 @@ namespace Test
///This is a test class for FormRemoveTextForHearImpairedTest and is intended
///to contain all FormRemoveTextForHearImpairedTest Unit Tests
///</summary>
[TestClass()]
[TestClass]
public class RemoveTextForHearImpairedTest
{
private TestContext testContextInstance;
private TestContext _testContextInstance;
/// <summary>
///Gets or sets the test context which provides
@ -23,11 +23,11 @@ namespace Test
{
get
{
return testContextInstance;
return _testContextInstance;
}
set
{
testContextInstance = value;
_testContextInstance = value;
}
}
@ -72,7 +72,7 @@ namespace Test
/// <summary>
///A test for RemoveColon
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonTest()
{
@ -89,9 +89,9 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonTest2a()
public void RemoveColonTest2A()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
@ -106,9 +106,9 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonTest2b()
public void RemoveColonTest2B()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
@ -126,7 +126,7 @@ namespace Test
/// <summary>
///A test for RemoveHIInsideLine
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIInsideLine()
{
@ -146,7 +146,7 @@ namespace Test
/// <summary>
///A test for RemoveHI
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHI1()
{
@ -165,7 +165,7 @@ namespace Test
/// <summary>
///A test for RemoveHI
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHI2()
{
@ -184,7 +184,7 @@ namespace Test
/// <summary>
///A test for no removal
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHINot()
{
@ -202,7 +202,7 @@ namespace Test
/// <summary>
///A test for RemoveHI
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIMultilineItalic()
{
@ -222,7 +222,7 @@ namespace Test
/// <summary>
///A test for RemoveHI
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIMultilineBold()
{
@ -242,7 +242,7 @@ namespace Test
/// <summary>
///A test for RemoveHI
///</summary>
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHISecondLineDelay()
{
@ -259,7 +259,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIQuotes()
{
@ -274,7 +274,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveHIDouble()
{
@ -290,7 +290,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveRemoveNameOfFirstLine()
{
@ -307,7 +307,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveRemoveNameOfFirstLineBold()
{
@ -324,7 +324,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections()
{
@ -340,7 +340,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections2()
{
@ -356,7 +356,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections3()
{
@ -372,7 +372,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections4()
{
@ -388,7 +388,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections5()
{
@ -404,7 +404,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections6a()
{
@ -420,7 +420,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections6b()
{
@ -436,7 +436,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections6bItalic()
{
@ -452,7 +452,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections7()
{
@ -468,7 +468,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections8()
{
@ -484,7 +484,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections9()
{
@ -500,7 +500,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections10()
{
@ -516,7 +516,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections10Italic()
{
@ -532,7 +532,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveInterjections11()
{
@ -548,7 +548,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveColonOnlyOnSeparateLine()
{
@ -565,7 +565,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfAllUppercase1()
{
@ -582,7 +582,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfAllUppercase2()
{
@ -599,7 +599,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfAllUppercase3()
{
@ -617,7 +617,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveLineIfParentheses3()
{
@ -635,7 +635,7 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveTextBeforeColonSecondLine()
{
@ -652,5 +652,56 @@ namespace Test
Assert.AreEqual(expected, actual);
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveTextBeforeColonOnlyUpper1()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBeforeColon = true;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = true;
target.Settings.ColonSeparateLine = false;
string text = "RACHEL <i>&</i> ROSS: Hi there!";
string expected = "Hi there!";
string actual = target.RemoveColon(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveTextBeforeColonOnlyUpper2()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBeforeColon = true;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = true;
target.Settings.ColonSeparateLine = false;
string text = "RACHEL AND ROSS: Hi there!";
string expected = "Hi there!";
string actual = target.RemoveColon(text);
Assert.AreEqual(expected, actual);
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void RemoveTextBeforeColonOnlyUpper3Negative()
{
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = false;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBeforeColon = true;
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = true;
target.Settings.ColonSeparateLine = false;
string text = "RACHEL and ROSS: Hi there!";
string expected = "RACHEL and ROSS: Hi there!";
string actual = target.RemoveColon(text);
Assert.AreEqual(expected, actual);
}
}
}