@@ -400,6 +400,89 @@ ref Unsafe.AsRef<int>(null),
400
400
Assert . IsTrue ( Unsafe . AreSame ( ref r0 , ref array [ 0 , 0 ] ) ) ;
401
401
}
402
402
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
+
403
486
[ TestCategory ( "ReadOnlySpan2DT" ) ]
404
487
[ TestMethod ]
405
488
public void Test_ReadOnlySpan2DT_Slice_1 ( )
0 commit comments