@@ -68,7 +68,7 @@ private static void AssertChar(int codePoint, UnicodeCategory category, string n
6868 {
6969 var info = UnicodeInfo . GetCharInfo ( codePoint ) ;
7070 Assert . AreEqual ( codePoint , info . CodePoint ) ;
71- Assert . AreEqual ( category , info . Category ) ;
71+ Assert . AreEqual ( category , info . Category ) ;
7272 Assert . AreEqual ( name , info . Name ) ;
7373 Assert . AreEqual ( block , UnicodeInfo . GetBlockName ( codePoint ) ) ;
7474 Assert . AreEqual ( block , info . Block ) ;
@@ -192,7 +192,64 @@ public void RadicalInfoTest()
192192
193193 AssertEx . ThrowsExactly < IndexOutOfRangeException > ( ( ) => UnicodeInfo . GetCjkRadicalInfo ( 0 ) , nameof ( UnicodeInfo . GetCjkRadicalInfo ) ) ;
194194 AssertEx . ThrowsExactly < IndexOutOfRangeException > ( ( ) => UnicodeInfo . GetCjkRadicalInfo ( 215 ) , nameof ( UnicodeInfo . GetCjkRadicalInfo ) ) ;
195- }
195+ }
196+
197+ [ TestMethod ]
198+ public void CodePointRangeTest ( )
199+ {
200+ var fullRange = new UnicodeCodePointRange ( 0 , 0x10FFFF ) ;
201+
202+ Assert . AreEqual ( 0 , fullRange . FirstCodePoint ) ;
203+ Assert . AreEqual ( 0x10FFFF , fullRange . LastCodePoint ) ;
204+ Assert . AreEqual ( false , fullRange . IsSingleCodePoint ) ;
205+
206+ var letterA = new UnicodeCodePointRange ( 'A' ) ;
207+
208+ Assert . AreEqual ( 'A' , letterA . FirstCodePoint ) ;
209+ Assert . AreEqual ( 'A' , letterA . LastCodePoint ) ;
210+ Assert . AreEqual ( true , letterA . IsSingleCodePoint ) ;
211+
212+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => new UnicodeCodePointRange ( - 1 ) ) ;
213+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => new UnicodeCodePointRange ( 0x110000 ) ) ;
214+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => new UnicodeCodePointRange ( int . MaxValue ) ) ;
215+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => new UnicodeCodePointRange ( - 1 , 10 ) ) ;
216+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => new UnicodeCodePointRange ( 10 , 0x110000 ) ) ;
217+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => new UnicodeCodePointRange ( - 1 , 0x110000 ) ) ;
218+ }
219+
220+ [ TestMethod ]
221+ public void CodePointRangeEnumerationTest ( )
222+ {
223+ const int start = 0xA3F ;
224+ const int end = 0x105F ;
225+
226+ // Generic test
227+ {
228+ int i = start ;
229+
230+ foreach ( int n in new UnicodeCodePointRange ( start , end ) )
231+ {
232+ Assert . AreEqual ( i ++ , n ) ;
233+ }
234+ }
235+
236+ // Nongeneric test
237+ {
238+ int i = start ;
239+
240+ var enumerator = ( IEnumerator ) new UnicodeCodePointRange ( start , end ) . GetEnumerator ( ) ;
241+
242+ while ( enumerator . MoveNext ( ) )
243+ {
244+ Assert . AreEqual ( i ++ , enumerator . Current ) ;
245+ }
246+
247+ enumerator . Reset ( ) ;
248+
249+ Assert . AreEqual ( true , enumerator . MoveNext ( ) ) ;
250+ Assert . AreEqual ( start , enumerator . Current ) ;
251+ }
252+ }
196253
197254#if DEBUG
198255 [ TestMethod ]
@@ -209,41 +266,15 @@ public void UnihanCodePointPackingTest()
209266 for ( int i = 0x2F800 ; i < 0x30000 ; ++ i )
210267 Assert . AreEqual ( i , UnihanCharacterData . UnpackCodePoint ( UnihanCharacterData . PackCodePoint ( i ) ) ) ;
211268
212- try
213- {
214- UnihanCharacterData . PackCodePoint ( 0xA000 ) ;
215- Assert . Fail ( "The PackCodePoint method should fail for code points outside of the valid range." ) ;
216- }
217- catch ( ArgumentOutOfRangeException )
218- {
219- }
220-
221- try
222- {
223- UnihanCharacterData . PackCodePoint ( 0xFB00 ) ;
224- Assert . Fail ( "The PackCodePoint method should fail for code points outside of the valid range." ) ;
225- }
226- catch ( ArgumentOutOfRangeException )
227- {
228- }
269+ const string packCodePointErrorMessage = "The PackCodePoint method should fail for code points outside of the valid range." ;
270+ const string unpackCodePointErrorMessage = "The PackCodePoint method should fail for values outside of the valid range." ;
229271
230- try
231- {
232- UnihanCharacterData . PackCodePoint ( 0x30000 ) ;
233- Assert . Fail ( "The PackCodePoint method should fail for code points outside of the valid range." ) ;
234- }
235- catch ( ArgumentOutOfRangeException )
236- {
237- }
272+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => UnihanCharacterData . PackCodePoint ( 0xA000 ) , nameof ( UnihanCharacterData . PackCodePoint ) , packCodePointErrorMessage ) ;
273+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => UnihanCharacterData . PackCodePoint ( 0xFB00 ) , nameof ( UnihanCharacterData . PackCodePoint ) , packCodePointErrorMessage ) ;
274+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => UnihanCharacterData . PackCodePoint ( 0x30000 ) , nameof ( UnihanCharacterData . PackCodePoint ) , packCodePointErrorMessage ) ;
238275
239- try
240- {
241- UnihanCharacterData . UnpackCodePoint ( 0x20000 ) ;
242- Assert . Fail ( "The UnpackCodePoint method should fail for code points outside of the valid range." ) ;
243- }
244- catch ( ArgumentOutOfRangeException )
245- {
246- }
276+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => UnihanCharacterData . UnpackCodePoint ( - 1 ) , nameof ( UnihanCharacterData . UnpackCodePoint ) , unpackCodePointErrorMessage ) ;
277+ AssertEx . ThrowsExactly < ArgumentOutOfRangeException > ( ( ) => UnihanCharacterData . UnpackCodePoint ( 0x20000 ) , nameof ( UnihanCharacterData . UnpackCodePoint ) , unpackCodePointErrorMessage ) ;
247278 }
248279#endif
249280 }
0 commit comments