Separated UnicodeCodePointRange tests.
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Unicode;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace UnicodeInformation.Tests
|
||||||
|
{
|
||||||
|
public class UnicodeCodePointRangeTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0, 0x10FFFF)]
|
||||||
|
public void MultiCodePointRangeShouldHaveExpectedResults(int firstCodePoint, int lastCodePoint)
|
||||||
|
{
|
||||||
|
var range = new UnicodeCodePointRange(firstCodePoint, lastCodePoint);
|
||||||
|
|
||||||
|
Assert.Equal(firstCodePoint, range.FirstCodePoint);
|
||||||
|
Assert.Equal(lastCodePoint, range.LastCodePoint);
|
||||||
|
Assert.False(range.IsSingleCodePoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData((int)'A')]
|
||||||
|
[InlineData(0x0)]
|
||||||
|
[InlineData(0x10FFFF)]
|
||||||
|
public void SingleCodePointRangeShouldHaveExpectedResults(int codePoint)
|
||||||
|
{
|
||||||
|
var range = new UnicodeCodePointRange(codePoint);
|
||||||
|
|
||||||
|
Assert.Equal(codePoint, range.FirstCodePoint);
|
||||||
|
Assert.Equal(codePoint, range.LastCodePoint);
|
||||||
|
Assert.True(range.IsSingleCodePoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(-1)]
|
||||||
|
[InlineData(0x110000)]
|
||||||
|
[InlineData(int.MaxValue)]
|
||||||
|
public void ConstructorShouldFailForInvalidCodePoint(int codePoint)
|
||||||
|
{
|
||||||
|
Assert.Throws<ArgumentOutOfRangeException>(() => new UnicodeCodePointRange(codePoint));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(-1, 10)]
|
||||||
|
[InlineData(10, 0x110000)]
|
||||||
|
[InlineData(-1, 0x110000)]
|
||||||
|
public void ConstructorShouldFailForInvalidCodePoints(int firstCodePoint, int lastCodePoint)
|
||||||
|
{
|
||||||
|
Assert.Throws<ArgumentOutOfRangeException>(() => new UnicodeCodePointRange(firstCodePoint, lastCodePoint));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0xA3F, 0x105F)]
|
||||||
|
public void EnumerationShouldHaveExpectedResults(int firstCodePoint, int lastCodePoint)
|
||||||
|
{
|
||||||
|
// Generic test
|
||||||
|
{
|
||||||
|
int i = firstCodePoint;
|
||||||
|
|
||||||
|
foreach (int n in new UnicodeCodePointRange(firstCodePoint, lastCodePoint))
|
||||||
|
{
|
||||||
|
Assert.Equal(i++, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nongeneric test
|
||||||
|
{
|
||||||
|
int i = firstCodePoint;
|
||||||
|
|
||||||
|
var enumerator = (IEnumerator)new UnicodeCodePointRange(firstCodePoint, lastCodePoint).GetEnumerator();
|
||||||
|
|
||||||
|
while (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
Assert.Equal(i++, enumerator.Current);
|
||||||
|
}
|
||||||
|
|
||||||
|
enumerator.Reset();
|
||||||
|
|
||||||
|
Assert.True(enumerator.MoveNext());
|
||||||
|
Assert.Equal(firstCodePoint, enumerator.Current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Unicode;
|
using System.Unicode;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace UnicodeInformation.Tests
|
namespace UnicodeInformation.Tests
|
||||||
{
|
{
|
||||||
@@ -99,7 +96,7 @@ namespace UnicodeInformation.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestRadicalStrokeCount()
|
public void RadicalStrokeCountShouldHaveExpectedResults()
|
||||||
{
|
{
|
||||||
var char5E7A = UnicodeInfo.GetCharInfo(0x5E7A);
|
var char5E7A = UnicodeInfo.GetCharInfo(0x5E7A);
|
||||||
|
|
||||||
@@ -117,7 +114,7 @@ namespace UnicodeInformation.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestRadicalInfo()
|
public void RadicalInfoShouldHaveExpectedResults()
|
||||||
{
|
{
|
||||||
var radical1 = UnicodeInfo.GetCjkRadicalInfo(1);
|
var radical1 = UnicodeInfo.GetCjkRadicalInfo(1);
|
||||||
|
|
||||||
@@ -141,74 +138,6 @@ namespace UnicodeInformation.Tests
|
|||||||
Assert.Throws<IndexOutOfRangeException>(() => UnicodeInfo.GetCjkRadicalInfo(215));
|
Assert.Throws<IndexOutOfRangeException>(() => UnicodeInfo.GetCjkRadicalInfo(215));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestCodePointRange()
|
|
||||||
{
|
|
||||||
var fullRange = new UnicodeCodePointRange(0, 0x10FFFF);
|
|
||||||
|
|
||||||
Assert.Equal(0, fullRange.FirstCodePoint);
|
|
||||||
Assert.Equal(0x10FFFF, fullRange.LastCodePoint);
|
|
||||||
Assert.False(fullRange.IsSingleCodePoint);
|
|
||||||
|
|
||||||
var letterA = new UnicodeCodePointRange('A');
|
|
||||||
|
|
||||||
Assert.Equal('A', letterA.FirstCodePoint);
|
|
||||||
Assert.Equal('A', letterA.LastCodePoint);
|
|
||||||
Assert.True(letterA.IsSingleCodePoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(-1)]
|
|
||||||
[InlineData(0x110000)]
|
|
||||||
[InlineData(int.MaxValue)]
|
|
||||||
public void TestInvalidSingleCodePointRanges(int codePoint)
|
|
||||||
{
|
|
||||||
Assert.Throws<ArgumentOutOfRangeException>(() => new UnicodeCodePointRange(codePoint));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(-1, 10)]
|
|
||||||
[InlineData(10, 0x110000)]
|
|
||||||
[InlineData(-1, 0x110000)]
|
|
||||||
public void TestInvalidCodePointRanges(int firstCodePoint, int lastCodePoint)
|
|
||||||
{
|
|
||||||
Assert.Throws<ArgumentOutOfRangeException>(() => new UnicodeCodePointRange(firstCodePoint, lastCodePoint));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestCodePointRangeEnumeration()
|
|
||||||
{
|
|
||||||
const int start = 0xA3F;
|
|
||||||
const int end = 0x105F;
|
|
||||||
|
|
||||||
// Generic test
|
|
||||||
{
|
|
||||||
int i = start;
|
|
||||||
|
|
||||||
foreach (int n in new UnicodeCodePointRange(start, end))
|
|
||||||
{
|
|
||||||
Assert.Equal(i++, n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nongeneric test
|
|
||||||
{
|
|
||||||
int i = start;
|
|
||||||
|
|
||||||
var enumerator = (IEnumerator)new UnicodeCodePointRange(start, end).GetEnumerator();
|
|
||||||
|
|
||||||
while (enumerator.MoveNext())
|
|
||||||
{
|
|
||||||
Assert.Equal(i++, enumerator.Current);
|
|
||||||
}
|
|
||||||
|
|
||||||
enumerator.Reset();
|
|
||||||
|
|
||||||
Assert.True(enumerator.MoveNext());
|
|
||||||
Assert.Equal(start, enumerator.Current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MethodGetNameShouldNeverFail()
|
public void MethodGetNameShouldNeverFail()
|
||||||
{
|
{
|
||||||
@@ -246,7 +175,7 @@ namespace UnicodeInformation.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestGetCharInfoCoherence()
|
public void MethodGetCharInfoShouldHaveCoherentResults()
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= 0x10FFFF; i++)
|
for (int i = 0; i <= 0x10FFFF; i++)
|
||||||
{
|
{
|
||||||
@@ -260,7 +189,7 @@ namespace UnicodeInformation.Tests
|
|||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestUnihanCodePointPacking()
|
public void UnihanCodePointPackingShouldHaveExpectedResults()
|
||||||
{
|
{
|
||||||
for (int i = 0x3400; i < 0x4E00; ++i)
|
for (int i = 0x3400; i < 0x4E00; ++i)
|
||||||
Assert.Equal(i, UnihanCharacterData.UnpackCodePoint(UnihanCharacterData.PackCodePoint(i)));
|
Assert.Equal(i, UnihanCharacterData.UnpackCodePoint(UnihanCharacterData.PackCodePoint(i)));
|
||||||
|
|||||||
@@ -72,6 +72,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="PermissiveCodePointEnumerableTests.cs" />
|
<Compile Include="PermissiveCodePointEnumerableTests.cs" />
|
||||||
<Compile Include="CodePointEnumerableTests.cs" />
|
<Compile Include="CodePointEnumerableTests.cs" />
|
||||||
|
<Compile Include="UnicodeCodePointRangeTests.cs" />
|
||||||
<Compile Include="UnicodeInfoBuilderTests.cs" />
|
<Compile Include="UnicodeInfoBuilderTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="UnicodeRationalNumerTests.cs" />
|
<Compile Include="UnicodeRationalNumerTests.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user