@@ -400,6 +400,89 @@ ref Unsafe.AsRef<int>(null),
400400 Assert . IsTrue ( Unsafe . AreSame ( ref r0 , ref array [ 0 , 0 ] ) ) ;
401401 }
402402
403+ #if NETCOREAPP3_1_OR_GREATER
404+ [ TestCategory ( "Span2DT" ) ]
405+ [ TestMethod ]
406+ public unsafe void Test_ReadOnlySpan2DT_Index_Indexer_1 ( )
407+ {
408+ int [ , ] array = new int [ 4 , 4 ] ;
409+
410+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array ) ;
411+
412+ ref int arrayRef = ref array [ 1 , 3 ] ;
413+ ref readonly int span2dRef = ref span2d [ 1 , ^ 1 ] ;
414+
415+ Assert . IsTrue ( Unsafe . AreSame ( ref arrayRef , ref Unsafe . AsRef ( in span2dRef ) ) ) ;
416+ }
417+
418+ [ TestCategory ( "Span2DT" ) ]
419+ [ TestMethod ]
420+ public unsafe void Test_ReadOnlySpan2DT_Index_Indexer_2 ( )
421+ {
422+ int [ , ] array = new int [ 4 , 4 ] ;
423+
424+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array ) ;
425+
426+ ref int arrayRef = ref array [ 2 , 1 ] ;
427+ ref readonly int span2dRef = ref span2d [ ^ 2 , ^ 3 ] ;
428+
429+ Assert . IsTrue ( Unsafe . AreSame ( ref arrayRef , ref Unsafe . AsRef ( in span2dRef ) ) ) ;
430+ }
431+
432+ [ TestCategory ( "Span2DT" ) ]
433+ [ TestMethod ]
434+ [ ExpectedException ( typeof ( IndexOutOfRangeException ) ) ]
435+ public unsafe void Test_ReadOnlySpan2DT_Index_Indexer_Fail ( )
436+ {
437+ int [ , ] array = new int [ 4 , 4 ] ;
438+
439+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array ) ;
440+
441+ ref readonly int span2dRef = ref span2d [ ^ 6 , 2 ] ;
442+ }
443+
444+ [ TestCategory ( "Span2DT" ) ]
445+ [ TestMethod ]
446+ public unsafe void Test_ReadOnlySpan2DT_Range_Indexer_1 ( )
447+ {
448+ int [ , ] array = new int [ 4 , 4 ] ;
449+
450+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array ) ;
451+ ReadOnlySpan2D < int > slice = span2d [ 1 .., 1 ..] ;
452+
453+ Assert . AreEqual ( slice . Length , 9 ) ;
454+ Assert . IsTrue ( Unsafe . AreSame ( ref array [ 1 , 1 ] , ref Unsafe . AsRef ( in slice [ 0 , 0 ] ) ) ) ;
455+ Assert . IsTrue ( Unsafe . AreSame ( ref array [ 3 , 3 ] , ref Unsafe . AsRef ( in slice [ 2 , 2 ] ) ) ) ;
456+ }
457+
458+ [ TestCategory ( "Span2DT" ) ]
459+ [ TestMethod ]
460+ public unsafe void Test_ReadOnlySpan2DT_Range_Indexer_2 ( )
461+ {
462+ int [ , ] array = new int [ 4 , 4 ] ;
463+
464+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array ) ;
465+ ReadOnlySpan2D < int > slice = span2d [ 0 ..^ 2 , 1 ..^ 1 ] ;
466+
467+ Assert . AreEqual ( slice . Length , 4 ) ;
468+ Assert . IsTrue ( Unsafe . AreSame ( ref array [ 0 , 1 ] , ref Unsafe . AsRef ( in slice [ 0 , 0 ] ) ) ) ;
469+ Assert . IsTrue ( Unsafe . AreSame ( ref array [ 1 , 2 ] , ref Unsafe . AsRef ( in slice [ 1 , 1 ] ) ) ) ;
470+ }
471+
472+ [ TestCategory ( "Span2DT" ) ]
473+ [ TestMethod ]
474+ [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
475+ public unsafe void Test_ReadOnlySpan2DT_Range_Indexer_Fail ( )
476+ {
477+ int [ , ] array = new int [ 4 , 4 ] ;
478+
479+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array ) ;
480+ _ = span2d [ 0 ..6 , 2 ..^ 1 ] ;
481+
482+ Assert . Fail ( ) ;
483+ }
484+ #endif
485+
403486 [ TestCategory ( "ReadOnlySpan2DT" ) ]
404487 [ TestMethod ]
405488 public void Test_ReadOnlySpan2DT_Slice_1 ( )
@@ -412,7 +495,7 @@ public void Test_ReadOnlySpan2DT_Slice_1()
412495
413496 ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array ) ;
414497
415- ReadOnlySpan2D < int > slice1 = span2d . Slice ( 1 , 1 , 2 , 1 ) ;
498+ ReadOnlySpan2D < int > slice1 = span2d . Slice ( 1 , 1 , 1 , 2 ) ;
416499
417500 Assert . AreEqual ( slice1 . Length , 2 ) ;
418501 Assert . AreEqual ( slice1 . Height , 1 ) ;
@@ -431,11 +514,11 @@ public void Test_ReadOnlySpan2DT_Slice_1()
431514
432515 Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( - 1 , 1 , 1 , 1 ) ) ;
433516 Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , - 1 , 1 , 1 ) ) ;
434- Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , 1 , - 1 , 1 ) ) ;
435517 Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , 1 , 1 , - 1 ) ) ;
518+ Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , 1 , - 1 , 1 ) ) ;
436519 Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 10 , 1 , 1 , 1 ) ) ;
437- Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , 12 , 12 , 1 ) ) ;
438- Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , 1 , 1 , 55 ) ) ;
520+ Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , 12 , 1 , 12 ) ) ;
521+ Assert . ThrowsException < ArgumentOutOfRangeException > ( ( ) => new ReadOnlySpan2D < int > ( array ) . Slice ( 1 , 1 , 55 , 1 ) ) ;
439522 }
440523
441524 [ TestCategory ( "ReadOnlySpan2DT" ) ]
@@ -458,7 +541,7 @@ public void Test_ReadOnlySpan2DT_Slice_2()
458541 Assert . AreEqual ( slice1 [ 0 , 0 ] , 1 ) ;
459542 Assert . AreEqual ( slice1 [ 1 , 1 ] , 5 ) ;
460543
461- ReadOnlySpan2D < int > slice2 = slice1 . Slice ( 1 , 0 , 2 , 1 ) ;
544+ ReadOnlySpan2D < int > slice2 = slice1 . Slice ( 1 , 0 , 1 , 2 ) ;
462545
463546 Assert . AreEqual ( slice2 . Length , 2 ) ;
464547 Assert . AreEqual ( slice2 . Height , 1 ) ;
@@ -503,7 +586,51 @@ ref Unsafe.AsRef(span[2]),
503586
504587 [ TestCategory ( "ReadOnlySpan2DT" ) ]
505588 [ TestMethod ]
506- public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_1 ( )
589+ public void Test_ReadOnlySpan2DT_TryGetSpan_From1DArray_1 ( )
590+ {
591+ int [ ] array = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
592+
593+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array , 3 , 3 ) ;
594+
595+ bool success = span2d . TryGetSpan ( out ReadOnlySpan < int > span ) ;
596+
597+ Assert . IsTrue ( success ) ;
598+ Assert . AreEqual ( span . Length , span2d . Length ) ;
599+ Assert . IsTrue ( Unsafe . AreSame ( ref array [ 0 ] , ref Unsafe . AsRef ( in span [ 0 ] ) ) ) ;
600+ }
601+
602+ [ TestCategory ( "ReadOnlySpan2DT" ) ]
603+ [ TestMethod ]
604+ public void Test_ReadOnlySpan2DT_TryGetSpan_From1DArray_2 ( )
605+ {
606+ int [ ] array = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
607+
608+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array , 3 , 3 ) . Slice ( 1 , 0 , 2 , 3 ) ;
609+
610+ bool success = span2d . TryGetSpan ( out ReadOnlySpan < int > span ) ;
611+
612+ Assert . IsTrue ( success ) ;
613+ Assert . AreEqual ( span . Length , span2d . Length ) ;
614+ Assert . IsTrue ( Unsafe . AreSame ( ref array [ 3 ] , ref Unsafe . AsRef ( in span [ 0 ] ) ) ) ;
615+ }
616+
617+ [ TestCategory ( "ReadOnlySpan2DT" ) ]
618+ [ TestMethod ]
619+ public void Test_ReadOnlySpan2DT_TryGetSpan_From1DArray_3 ( )
620+ {
621+ int [ ] array = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
622+
623+ ReadOnlySpan2D < int > span2d = new ReadOnlySpan2D < int > ( array , 3 , 3 ) . Slice ( 0 , 1 , 3 , 2 ) ;
624+
625+ bool success = span2d . TryGetSpan ( out ReadOnlySpan < int > span ) ;
626+
627+ Assert . IsFalse ( success ) ;
628+ Assert . AreEqual ( span . Length , 0 ) ;
629+ }
630+
631+ [ TestCategory ( "ReadOnlySpan2DT" ) ]
632+ [ TestMethod ]
633+ public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_From2DArray_1 ( )
507634 {
508635 int [ , ] array =
509636 {
@@ -527,7 +654,7 @@ public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_1()
527654
528655 [ TestCategory ( "ReadOnlySpan2DT" ) ]
529656 [ TestMethod ]
530- public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_2 ( )
657+ public void Test_ReadOnlySpan2DT_TryGetReadOnlySpan_From2DArray_2 ( )
531658 {
532659 int [ , ] array =
533660 {
0 commit comments