Merge branch 'lisardggY-master'

This commit is contained in:
Jon Galloway 2017-03-12 16:14:33 -07:00
commit 5e8ac93ead
3 changed files with 121 additions and 1 deletions

View File

@ -86,7 +86,7 @@ namespace OpenLiveWriter.HtmlEditor
{
#region Regex To Find Words
//private readonly static Regex regexWords = new Regex(@"[\p{Ll}\p{Lu}\p{Lt}\p{Nd}\p{Pc}\p{Pf}\p{Pi}\p{Po}\p{Sc}\u2019]+|\p{Lo}", RegexOptions.Compiled);
private readonly static Regex regexWords = new Regex(@"[^\n\r\t\s()\p{Lo}]+|\p{Lo}", RegexOptions.Compiled);
private readonly static Regex regexWords = new Regex(@"[^\n\r\t\s()]+", RegexOptions.Compiled);
private readonly static Regex regexChars = new Regex("[^\n\r\t]", RegexOptions.Compiled);
private readonly static Regex regexCharsWithoutSpace = new Regex("\\S", RegexOptions.Compiled);
private readonly static Regex regexParagraph = new Regex(@"(\r\n){1,2}\s*", RegexOptions.Compiled);

View File

@ -0,0 +1,108 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenLiveWriter.HtmlEditor;
using System;
namespace OpenLiveWriter.UnitTest.HtmlEditor.WordCounterTests
{
[TestClass]
public class HebrewTextWordCount
{
private static void CountText(string text, int expectedCount, int? expectedCharCount = null)
{
var wordCounter = new WordCounter(text);
Assert.AreEqual(expectedCount, wordCounter.Words);
if (expectedCharCount.HasValue)
{
Assert.AreEqual(expectedCharCount, wordCounter.Chars);
}
}
[TestMethod]
public void EmptyText_ReturnZero()
{
CountText(string.Empty, 0, 0);
}
[TestMethod]
public void SanityEnglishText()
{
CountText("Simple English Text", 3, 19);
}
[TestMethod]
public void SanityEnglishTextEndsWithPunctuation()
{
CountText("Simple English Text.", 3, 20);
}
[TestMethod]
public void SanityEnglishMultiline()
{
CountText("This is a " + Environment.NewLine + "multiline text", 5);
}
[TestMethod]
public void EnglishSeparatedBy()
{
CountText("This is a " + Environment.NewLine + "multiline text", 5);
}
[TestMethod]
public void CyrillicText()
{
CountText("ДЖem", 1, 4);
}
[TestMethod]
public void OneHebrewWordText()
{
CountText("עברית", 1, 5);
}
[TestMethod]
public void SimpleHebrewText()
{
CountText("משפט עם חמש מילים בעברית", 5);
}
[TestMethod]
public void HebrewMultiline()
{
CountText("משפט עם חמש " + "\n" + "מילים בעברית", 5);
}
[TestMethod]
public void MixedHebrewEnglishWords()
{
CountText("מילה בעברית and an english word", 6);
}
[TestMethod]
public void MixedHebrewEnglishChars()
{
CountText("עבריתenglish", 1, 12);
}
[TestMethod]
public void OneArabicWordText()
{
CountText("عربي", 1, 4);
}
[TestMethod]
public void SimpleArabicText()
{
CountText("اللغة العربية هي أكثر اللغات تحدثاً", 6);
}
}
}

View File

@ -28,6 +28,8 @@
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VSSDK.UnitTestLibrary, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Net" />
@ -79,6 +81,10 @@
<Project>{A803C16E-6619-4017-883C-EA73EB947F34}</Project>
<Name>OpenLiveWriter.Extensibility</Name>
</ProjectReference>
<ProjectReference Include="..\OpenLiveWriter.HtmlEditor\OpenLiveWriter.HtmlEditor.csproj">
<Project>{6a6872bc-67ef-4a42-a21a-30eced376923}</Project>
<Name>OpenLiveWriter.HtmlEditor</Name>
</ProjectReference>
<ProjectReference Include="..\OpenLiveWriter.Interop\OpenLiveWriter.Interop.csproj">
<Project>{0937EF37-EB01-48E2-885B-991044877712}</Project>
<Name>OpenLiveWriter.Interop</Name>
@ -98,6 +104,12 @@
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="HtmlEditor\WordCounterTests\HebrewTextWordCount.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(RepoRoot)\writer.build.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />