mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 14:32:35 +01:00
Work on unit tests
This commit is contained in:
parent
387c50aba8
commit
40bcfe3525
46
src/Test/Core/MergeShortLinesUtilsTest.cs
Normal file
46
src/Test/Core/MergeShortLinesUtilsTest.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Nikse.SubtitleEdit.Core.Common;
|
||||
|
||||
namespace Test.Core
|
||||
{
|
||||
[TestClass]
|
||||
public class MergeShortLinesUtilsTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void ThreeShortLines()
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
subtitle.Paragraphs.Add(new Paragraph("How", 0, 200));
|
||||
subtitle.Paragraphs.Add(new Paragraph("are", 200, 400));
|
||||
subtitle.Paragraphs.Add(new Paragraph("you?", 400, 600));
|
||||
var mergedSubtitle = MergeShortLinesUtils.MergeShortLinesInSubtitle(subtitle, 500, 80, true);
|
||||
|
||||
Assert.AreEqual(1, mergedSubtitle.Paragraphs.Count);
|
||||
Assert.AreEqual("How are you?", mergedSubtitle.Paragraphs[0].Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ThreeShortLinesNoMergeDueToLength()
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
subtitle.Paragraphs.Add(new Paragraph("How", 0, 200));
|
||||
subtitle.Paragraphs.Add(new Paragraph("are", 200, 400));
|
||||
subtitle.Paragraphs.Add(new Paragraph("you?", 400, 600));
|
||||
var mergedSubtitle = MergeShortLinesUtils.MergeShortLinesInSubtitle(subtitle, 500, 2, true);
|
||||
|
||||
Assert.AreEqual(3, mergedSubtitle.Paragraphs.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ThreeShortLinesNoMergeDueToGap()
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
subtitle.Paragraphs.Add(new Paragraph("How", 0, 200));
|
||||
subtitle.Paragraphs.Add(new Paragraph("are", 2000, 2400));
|
||||
subtitle.Paragraphs.Add(new Paragraph("you?", 4400, 4600));
|
||||
var mergedSubtitle = MergeShortLinesUtils.MergeShortLinesInSubtitle(subtitle, 500, 80, true);
|
||||
|
||||
Assert.AreEqual(3, mergedSubtitle.Paragraphs.Count);
|
||||
}
|
||||
}
|
||||
}
|
@ -64,6 +64,7 @@
|
||||
<Compile Include="Assa\ResamplerTest.cs" />
|
||||
<Compile Include="Assa\AssaTimeCodes.cs" />
|
||||
<Compile Include="Core\AudioToTextTest.cs" />
|
||||
<Compile Include="Core\MergeShortLinesUtilsTest.cs" />
|
||||
<Compile Include="Core\CsvUtilTest.cs" />
|
||||
<Compile Include="Core\WebVttHelperTest.cs" />
|
||||
<Compile Include="Core\WebVttToAssaTest.cs" />
|
||||
|
@ -6,11 +6,11 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
{
|
||||
public static Subtitle MergeShortLinesInSubtitle(Subtitle subtitle, double maxMillisecondsBetweenLines, int maxCharacters, bool onlyContinuousLines)
|
||||
{
|
||||
string language = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
|
||||
var language = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
|
||||
var mergedSubtitle = new Subtitle();
|
||||
bool lastMerged = false;
|
||||
var lastMerged = false;
|
||||
Paragraph p = null;
|
||||
for (int i = 1; i < subtitle.Paragraphs.Count; i++)
|
||||
for (var i = 1; i < subtitle.Paragraphs.Count; i++)
|
||||
{
|
||||
if (!lastMerged)
|
||||
{
|
||||
@ -22,12 +22,11 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
{
|
||||
if (Utilities.QualifiesForMerge(p, next, maxMillisecondsBetweenLines, maxCharacters, onlyContinuousLines))
|
||||
{
|
||||
if (GetStartTag(p.Text) == GetStartTag(next.Text) &&
|
||||
GetEndTag(p.Text) == GetEndTag(next.Text))
|
||||
if (GetStartTag(p.Text) == GetStartTag(next.Text) && GetEndTag(p.Text) == GetEndTag(next.Text))
|
||||
{
|
||||
string s1 = p.Text.Trim();
|
||||
var s1 = p.Text.Trim();
|
||||
s1 = s1.Substring(0, s1.Length - GetEndTag(s1).Length);
|
||||
string s2 = next.Text.Trim();
|
||||
var s2 = next.Text.Trim();
|
||||
s2 = s2.Substring(GetStartTag(s2).Length);
|
||||
p.Text = Utilities.AutoBreakLine(s1 + Environment.NewLine + s2, language);
|
||||
}
|
||||
@ -71,7 +70,7 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
}
|
||||
|
||||
var endTag = string.Empty;
|
||||
int start = text.LastIndexOf("</", StringComparison.Ordinal);
|
||||
var start = text.LastIndexOf("</", StringComparison.Ordinal);
|
||||
if (start > 0 && start >= text.Length - 8)
|
||||
{
|
||||
endTag = text.Substring(start);
|
||||
@ -93,11 +92,12 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
}
|
||||
|
||||
var startTag = string.Empty;
|
||||
int end = text.IndexOf('>');
|
||||
var end = text.IndexOf('>');
|
||||
if (end > 0 && end < 25)
|
||||
{
|
||||
startTag = text.Substring(0, end + 1);
|
||||
}
|
||||
|
||||
return startTag;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ using Nikse.SubtitleEdit.Logic.Ocr;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
Loading…
Reference in New Issue
Block a user