Skip to content

Commit 235738c

Browse files
committed
Add tests
1 parent d9e697a commit 235738c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Ramstack.Structures.Tests/Collections/ArrayViewTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Immutable;
12
using System.Diagnostics.CodeAnalysis;
23
using System.Runtime.CompilerServices;
34

@@ -417,9 +418,15 @@ public void IndexOf()
417418
public void AsView(string? value)
418419
{
419420
var list = value?.ToCharArray();
421+
var immutable = value.AsSpan().ToImmutableArray();
422+
420423
Assert.That(
421424
list.AsView(),
422425
Is.EquivalentTo(value.AsSpan().ToArray()));
426+
427+
Assert.That(
428+
immutable.AsView(),
429+
Is.EquivalentTo(value.AsSpan().ToArray()));
423430
}
424431

425432
[TestCase(null, 0)]
@@ -432,10 +439,15 @@ public void AsView(string? value)
432439
public void AsView_Index(string? value, int index)
433440
{
434441
var list = value?.ToCharArray();
442+
var immutable = value.AsSpan().ToImmutableArray();
435443

436444
Assert.That(
437445
list.AsView(index),
438446
Is.EquivalentTo(value.AsSpan(index).ToArray()));
447+
448+
Assert.That(
449+
immutable.AsView(index),
450+
Is.EquivalentTo(value.AsSpan(index).ToArray()));
439451
}
440452

441453
[TestCase(null, 0, 0)]
@@ -449,10 +461,15 @@ public void AsView_Index(string? value, int index)
449461
public void AsView_Range(string? value, int index, int length)
450462
{
451463
var list = value?.ToCharArray();
464+
var immutable = value.AsSpan().ToImmutableArray();
452465

453466
Assert.That(
454467
list.AsView(index, length),
455468
Is.EquivalentTo(value.AsSpan(index, length).ToArray()));
469+
470+
Assert.That(
471+
immutable.AsView(index, length),
472+
Is.EquivalentTo(value.AsSpan(index, length).ToArray()));
456473
}
457474

458475
[TestCase(null, 1)]
@@ -462,10 +479,15 @@ public void AsView_Range(string? value, int index, int length)
462479
public void AsView_InvalidIndex_ShouldThrow(string? value, int index)
463480
{
464481
var list = value?.ToCharArray();
482+
var immutable = value.AsSpan().ToImmutableArray();
465483

466484
Assert.That(
467485
() => list.AsView(index),
468486
Throws.TypeOf<ArgumentOutOfRangeException>());
487+
488+
Assert.That(
489+
() => immutable.AsView(index),
490+
Throws.TypeOf<ArgumentOutOfRangeException>());
469491
}
470492

471493
[TestCase(null, 1, 0)]
@@ -479,9 +501,14 @@ public void AsView_InvalidIndex_ShouldThrow(string? value, int index)
479501
public void AsView_InvalidRange_ShouldThrow(string? value, int index, int length)
480502
{
481503
var list = value?.ToCharArray();
504+
var immutable = value.AsSpan().ToImmutableArray();
482505

483506
Assert.That(
484507
() => list.AsView(index, length),
485508
Throws.TypeOf<ArgumentOutOfRangeException>());
509+
510+
Assert.That(
511+
() => immutable.AsView(index, length),
512+
Throws.TypeOf<ArgumentOutOfRangeException>());
486513
}
487514
}

0 commit comments

Comments
 (0)