feat: add NumTokens, TokenAt, SubjectsCollide, UTF-8 validation to SubjectMatch
This commit is contained in:
@@ -54,4 +54,50 @@ public class SubjectMatchTests
|
||||
{
|
||||
SubjectMatch.MatchLiteral(literal, pattern).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("foo.bar.baz", 3)]
|
||||
[InlineData("foo", 1)]
|
||||
[InlineData("a.b.c.d.e", 5)]
|
||||
[InlineData("", 0)]
|
||||
public void NumTokens(string subject, int expected)
|
||||
{
|
||||
SubjectMatch.NumTokens(subject).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("foo.bar.baz", 0, "foo")]
|
||||
[InlineData("foo.bar.baz", 1, "bar")]
|
||||
[InlineData("foo.bar.baz", 2, "baz")]
|
||||
[InlineData("foo", 0, "foo")]
|
||||
[InlineData("foo.bar.baz", 5, "")]
|
||||
public void TokenAt(string subject, int index, string expected)
|
||||
{
|
||||
SubjectMatch.TokenAt(subject, index).ToString().ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("foo.bar", "foo.bar", true)]
|
||||
[InlineData("foo.bar", "foo.baz", false)]
|
||||
[InlineData("foo.*", "foo.bar", true)]
|
||||
[InlineData("foo.*", "foo.>", true)]
|
||||
[InlineData("foo.>", "foo.bar.baz", true)]
|
||||
[InlineData(">", "foo.bar", true)]
|
||||
[InlineData("foo.*", "bar.*", false)]
|
||||
[InlineData("foo.*.baz", "foo.bar.*", true)]
|
||||
[InlineData("*.bar", "foo.*", true)]
|
||||
[InlineData("foo.*", "bar.>", false)]
|
||||
public void SubjectsCollide(string subj1, string subj2, bool expected)
|
||||
{
|
||||
SubjectMatch.SubjectsCollide(subj1, subj2).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("foo\0bar", true, false)]
|
||||
[InlineData("foo\0bar", false, true)]
|
||||
[InlineData("foo.bar", true, true)]
|
||||
public void IsValidSubject_checkRunes(string subject, bool checkRunes, bool expected)
|
||||
{
|
||||
SubjectMatch.IsValidSubject(subject, checkRunes).ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user