using NATS.Server.Subscriptions;

namespace NATS.Server.Core.Tests.Subscriptions;

public class SubjectSubsetMatchParityBatch1Tests
{
    [Theory]
    [InlineData("foo.bar", "foo.bar", true)]
    [InlineData("foo.bar", "foo.*", true)]
    [InlineData("foo.bar", "foo.>", true)]
    [InlineData("foo.bar", "*.*", true)]
    [InlineData("foo.bar", ">", true)]
    [InlineData("foo.bar", "foo.baz", false)]
    [InlineData("foo.bar.baz", "foo.*", false)]
    public void SubjectMatchesFilter_matches_go_subset_behavior(string subject, string filter, bool expected)
    {
        SubjectMatch.SubjectMatchesFilter(subject, filter).ShouldBe(expected);
    }

    [Fact]
    public void SubjectIsSubsetMatch_uses_subject_tokens_against_test_pattern()
    {
        SubjectMatch.SubjectIsSubsetMatch("foo.*", "foo.*").ShouldBeTrue();
        SubjectMatch.SubjectIsSubsetMatch("foo.*", "foo.bar").ShouldBeFalse();
    }

    [Fact]
    public void IsSubsetMatch_tokenizes_test_subject_and_delegates_to_tokenized_matcher()
    {
        SubjectMatch.IsSubsetMatch(["foo", "bar"], "foo.*").ShouldBeTrue();
        SubjectMatch.IsSubsetMatch(["foo", "bar"], "foo.baz").ShouldBeFalse();
    }

    [Fact]
    public void IsSubsetMatchTokenized_handles_fwc_and_rejects_empty_tokens_like_go()
    {
        SubjectMatch.IsSubsetMatchTokenized(["foo", "bar"], ["foo", ">"]).ShouldBeTrue();
        SubjectMatch.IsSubsetMatchTokenized(["foo", "bar"], ["foo", ""]).ShouldBeFalse();
    }
}
