mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add GetNthIndexOfCharShould tests (#581)
This commit is contained in:
parent
334666c335
commit
51481d2da2
5 changed files with 50 additions and 14 deletions
|
|
@ -9,7 +9,12 @@ public static bool IsValidHttpOrHttpsUrl(this string source) =>
|
|||
Uri.TryCreate(source, UriKind.Absolute, out var uriResult) &&
|
||||
new[] {Uri.UriSchemeHttps, Uri.UriSchemeHttp}.Contains(uriResult.Scheme);
|
||||
|
||||
public static int GetNthIndexOfChar(this string s, int n, char t) =>
|
||||
s.TakeWhile(c => (n -= c == t ? 1 : 0) > 0).Count();
|
||||
public static int GetNthIndexOfChar(this string s, int n, char t)
|
||||
{
|
||||
if (n < 1)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
var nthIndexOfChar = s.TakeWhile(c => (n -= c == t ? 1 : 0) > 0).Count();
|
||||
return nthIndexOfChar == s.Length ? -1 : nthIndexOfChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,10 +7,7 @@ namespace FilterLists.Services.Tests.Extensions.Collection
|
|||
{
|
||||
public class AddIfNotNullOrEmptyShould
|
||||
{
|
||||
public AddIfNotNullOrEmptyShould() =>
|
||||
sut = new Collection<string>();
|
||||
|
||||
private readonly ICollection<string> sut;
|
||||
private readonly ICollection<string> sut = new Collection<string>();
|
||||
private string item;
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@ namespace FilterLists.Services.Tests.Extensions.Collection
|
|||
{
|
||||
public class AddRangeShould
|
||||
{
|
||||
public AddRangeShould() =>
|
||||
sut = new Collection<string>();
|
||||
|
||||
private readonly ICollection<string> sut;
|
||||
private readonly ICollection<string> sut = new Collection<string>();
|
||||
private IEnumerable<string> range;
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using FilterLists.Services.Extensions;
|
||||
using Xunit;
|
||||
|
||||
namespace FilterLists.Services.Tests.Extensions.String
|
||||
{
|
||||
public class GetNthIndexOfCharShould
|
||||
{
|
||||
private const string Sut = "abcdeabcde";
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 'a', 0)]
|
||||
[InlineData(2, 'a', 5)]
|
||||
public void ReturnNthIndexOfCharIfExists(int n, char c, int expectedIndex)
|
||||
{
|
||||
Assert.Equal(expectedIndex, Sut.GetNthIndexOfChar(n, c));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(3, 'a')]
|
||||
[InlineData(1, 'f')]
|
||||
public void ReturnNegativeOneIfDoesNotExist(int n, char c)
|
||||
{
|
||||
Assert.Equal(-1, Sut.GetNthIndexOfChar(n, c));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 'a')]
|
||||
[InlineData(-1, 'a')]
|
||||
public void ThrowArgumentOutOfRangeExceptionIfInvalidN(int n, char c)
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Sut.GetNthIndexOfChar(n, c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,11 +5,13 @@ namespace FilterLists.Services.Tests.Extensions.String
|
|||
{
|
||||
public class IsValidHttpOrHttpsUrlShould
|
||||
{
|
||||
[Fact]
|
||||
public void ReturnFalseIfNotHttpOrHttps()
|
||||
[Theory]
|
||||
[InlineData("abp://www.google.com")]
|
||||
[InlineData("www.google.com")]
|
||||
[InlineData("google")]
|
||||
public void ReturnFalseIfNotHttpOrHttps(string url)
|
||||
{
|
||||
const string abp = "abp://www.google.com";
|
||||
Assert.False(abp.IsValidHttpOrHttpsUrl());
|
||||
Assert.False(url.IsValidHttpOrHttpsUrl());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in a new issue