# encoding=UTF-8
import unittest

from antpm import AntPathMatcher


class TestAntPathMatcher(unittest.TestCase):
    def test_match(self):
        ant_matcher = AntPathMatcher()
        self.assertTrue(ant_matcher.match("test", "test"))
        self.assertTrue(ant_matcher.match("/test", "/test"))
        self.assertTrue(ant_matcher.match("https://example.org", "https://example.org"))
        self.assertFalse(ant_matcher.match("/test.jpg", "test.jpg"))
        self.assertFalse(ant_matcher.match("test", "/test"))
        self.assertFalse(ant_matcher.match("/test", "test"))

        self.assertTrue(ant_matcher.match("t?st", "test"))
        self.assertTrue(ant_matcher.match("??st", "test"))
        self.assertTrue(ant_matcher.match("tes?", "test"))
        self.assertTrue(ant_matcher.match("te??", "test"))
        self.assertTrue(ant_matcher.match("?es?", "test"))
        self.assertFalse(ant_matcher.match("tes?", "tes"))
        self.assertFalse(ant_matcher.match("tes?", "testt"))
        self.assertFalse(ant_matcher.match("tes?", "tsst"))

        self.assertTrue(ant_matcher.match("*", "test"))
        self.assertTrue(ant_matcher.match("test*", "test"))
        self.assertTrue(ant_matcher.match("test*", "testTest"))
        self.assertTrue(ant_matcher.match("test/*", "test/Test"))
        self.assertTrue(ant_matcher.match("test/*", "test/t"))
        self.assertTrue(ant_matcher.match("test/*", "test/"))
        self.assertTrue(ant_matcher.match("*test*", "AnothertestTest"))
        self.assertTrue(ant_matcher.match("*test", "Anothertest"))
        self.assertTrue(ant_matcher.match("*.*", "test."))
        self.assertTrue(ant_matcher.match("*.*", "test.test"))
        self.assertTrue(ant_matcher.match("*.*", "test.test.test"))
        self.assertTrue(ant_matcher.match("test*aaa", "testblaaaa"))
        self.assertFalse(ant_matcher.match("test*", "tst"))
        self.assertFalse(ant_matcher.match("test*", "tsttest"))
        self.assertFalse(ant_matcher.match("test*", "test/"))
        self.assertFalse(ant_matcher.match("test*", "test/t"))
        self.assertFalse(ant_matcher.match("test/*", "test"))
        self.assertFalse(ant_matcher.match("*test*", "tsttst"))
        self.assertFalse(ant_matcher.match("*test", "tsttst"))
        self.assertFalse(ant_matcher.match("*.*", "tsttst"))
        self.assertFalse(ant_matcher.match("test*aaa", "test"))
        self.assertFalse(ant_matcher.match("test*aaa", "testblaaab"))
        self.assertTrue(ant_matcher.match("/?", "/a"))
        self.assertTrue(ant_matcher.match("/?/a", "/a/a"))
        self.assertTrue(ant_matcher.match("/a/?", "/a/b"))
        self.assertTrue(ant_matcher.match("/??/a", "/aa/a"))
        self.assertTrue(ant_matcher.match("/a/??", "/a/bb"))
        self.assertTrue(ant_matcher.match("/?", "/a"))
        self.assertTrue(ant_matcher.match("/**", "/testing/testing"))
        self.assertTrue(ant_matcher.match("/*/**", "/testing/testing"))
        self.assertTrue(ant_matcher.match("/**/*", "/testing/testing"))
        self.assertTrue(ant_matcher.match("/bla/**/bla", "/bla/testing/testing/bla"))
        self.assertTrue(ant_matcher.match("/bla/**/bla", "/bla/testing/testing/bla/bla"))
        self.assertTrue(ant_matcher.match("/**/test", "/bla/bla/test"))
        self.assertTrue(ant_matcher.match("/bla/**/**/bla", "/bla/bla/bla/bla/bla/bla"))
        self.assertTrue(ant_matcher.match("/bla*bla/test", "/blaXXXbla/test"))
        self.assertTrue(ant_matcher.match("/*bla/test", "/XXXbla/test"))
        self.assertFalse(ant_matcher.match("/bla*bla/test", "/blaXXXbl/test"))
        self.assertFalse(ant_matcher.match("/*bla/test", "XXXblab/test"))
        self.assertFalse(ant_matcher.match("/*bla/test", "XXXbl/test"))
        self.assertFalse(ant_matcher.match("/????", "/bala/bla"))
        self.assertFalse(ant_matcher.match("/**/*bla", "/bla/bla/bla/bbb"))
        self.assertTrue(ant_matcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing/"))
        self.assertTrue(ant_matcher.match("/*bla*/**/bla/*", "/XXXblaXXXX/testing/testing/bla/testing"))
        self.assertTrue(ant_matcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing"))
        self.assertTrue(
            ant_matcher.match("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing.jpg"))
        self.assertTrue(ant_matcher.match("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing/"))
        self.assertTrue(ant_matcher.match("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing"))
        self.assertTrue(ant_matcher.match("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing"))
        self.assertFalse(ant_matcher.match("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing/testing"))
        self.assertFalse(ant_matcher.match("/x/x/**/bla", "/x/x/x/"))
        self.assertTrue(ant_matcher.match("/foo/bar/**", "/foo/bar"))
        self.assertTrue(ant_matcher.match("", ""))
        self.assertTrue("/**", "/hello/world")
