mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[PS-1471] Create Allocation Free EncryptedStringAttribute
validation (#2273)
* Add new logic for validating encrypted strings
* Add benchmarks
* Formatting & Comments
* Move Debug assertion to just be a test
* Address PR feedback pt.1
* Address more PR feedback
* Formatting
* merge branch 'master' into 'encrypted-string-perf'
* Revert "merge branch 'master' into 'encrypted-string-perf'"
This reverts commit a20e127c9c
.
This commit is contained in:
52
test/Core.Test/Utilities/SpanExtensionsTests.cs
Normal file
52
test/Core.Test/Utilities/SpanExtensionsTests.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Xunit;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.Test.Utilities;
|
||||
|
||||
public class SpanExtensionsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(".", "", "")]
|
||||
[InlineData("T.T", "T", "T")]
|
||||
[InlineData("T.", "T", "")]
|
||||
[InlineData(".T", "", "T")]
|
||||
[InlineData("T.T.T", "T", "T.T")]
|
||||
public void TrySplitBy_CanSplit_Success(string fullString, string firstPart, string secondPart)
|
||||
{
|
||||
var success = fullString.AsSpan().TrySplitBy('.', out var firstPartSpan, out var secondPartSpan);
|
||||
Assert.True(success);
|
||||
Assert.Equal(firstPart, firstPartSpan.ToString());
|
||||
Assert.Equal(secondPart, secondPartSpan.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Test", '.')]
|
||||
[InlineData("Other test", 'S')]
|
||||
public void TrySplitBy_CanNotSplit_Success(string fullString, char splitChar)
|
||||
{
|
||||
var success = fullString.AsSpan().TrySplitBy(splitChar, out var splitChunk, out var rest);
|
||||
Assert.False(success);
|
||||
Assert.True(splitChunk.IsEmpty);
|
||||
Assert.Equal(fullString, rest.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("11111", '1', 5)]
|
||||
[InlineData("Text", 'z', 0)]
|
||||
[InlineData("1", '1', 1)]
|
||||
public void Count_ReturnsCount(string text, char countChar, int expectedInstances)
|
||||
{
|
||||
Assert.Equal(expectedInstances, text.AsSpan().Count(countChar));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(new[] { 5, 4 }, 5, 1)]
|
||||
[InlineData(new[] { 1 }, 5, 0)]
|
||||
[InlineData(new[] { 5, 5, 5 }, 5, 3)]
|
||||
public void CountIntegers_ReturnsCount(int[] array, int countNumber, int expectedInstances)
|
||||
{
|
||||
Assert.Equal(expectedInstances, ((ReadOnlySpan<int>)array.AsSpan()).Count(countNumber));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user