|
| 1 | +// Copyright 2020 ONIXLabs |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +using System; |
| 16 | +using System.Buffers; |
| 17 | +using OnixLabs.Core.UnitTests.Data; |
| 18 | +using Xunit; |
| 19 | + |
| 20 | +namespace OnixLabs.Core.UnitTests; |
| 21 | + |
| 22 | +public sealed class ReadOnlySequenceExtensionTests |
| 23 | +{ |
| 24 | + [Fact(DisplayName = "ReadOnlySequence.CopyTo should copy into a new array with a single element")] |
| 25 | + public void ReadOnlySequenceCopyToShouldCopyIntoNewArrayWithSingleElement() |
| 26 | + { |
| 27 | + // Given |
| 28 | + string[] expected = ["ABC", "XYZ", "123", "789"]; |
| 29 | + ReadOnlySequence<string> value = new(expected); |
| 30 | + |
| 31 | + // When |
| 32 | + value.CopyTo(out string[] actual); |
| 33 | + |
| 34 | + // Then |
| 35 | + Assert.Equal(expected, actual); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact(DisplayName = "ReadOnlySequence.CopyTo should copy into a new array with multiple elements")] |
| 39 | + public void ReadOnlySequenceCopyToShouldCopyIntoNewArrayWithMultipleElements() |
| 40 | + { |
| 41 | + // Given |
| 42 | + string[] expected = ["ABC", "XYZ", "123", "789"]; |
| 43 | + ReadOnlySequence<string> value = BufferSegment<string>.FromMemory([ |
| 44 | + new ReadOnlyMemory<string>(["ABC", "XYZ"]), |
| 45 | + new ReadOnlyMemory<string>(["123", "789"]) |
| 46 | + ]); |
| 47 | + |
| 48 | + // When |
| 49 | + value.CopyTo(out string[] actual); |
| 50 | + |
| 51 | + // Then |
| 52 | + Assert.Equal(expected, actual); |
| 53 | + } |
| 54 | +} |
0 commit comments