summaryrefslogtreecommitdiff
path: root/tests/test_util.py
blob: 41aa34c6a608db36b93fd9136e5052f02f4c6a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# gemato: Utility function tests
# vim:fileencoding=utf-8
# (c) 2017 Michał Górny
# Licensed under the terms of 2-clause BSD license

import unittest

import gemato.util


class UtilityTestCase(unittest.TestCase):
    def test_path_starts_with(self):
        self.assertTrue(gemato.util.path_starts_with("", ""))
        self.assertTrue(gemato.util.path_starts_with("foo", ""))
        self.assertTrue(gemato.util.path_starts_with("foo/", ""))
        self.assertTrue(gemato.util.path_starts_with("foo/bar", ""))
        self.assertTrue(gemato.util.path_starts_with("bar", ""))
        self.assertTrue(gemato.util.path_starts_with("bar/", ""))
        self.assertTrue(gemato.util.path_starts_with("bar/bar", ""))
        self.assertTrue(gemato.util.path_starts_with("foo", "foo"))
        self.assertTrue(gemato.util.path_starts_with("foo/", "foo"))
        self.assertTrue(gemato.util.path_starts_with("foo/bar", "foo"))
        self.assertFalse(gemato.util.path_starts_with("bar", "foo"))
        self.assertFalse(gemato.util.path_starts_with("fooo", "foo"))
        self.assertFalse(gemato.util.path_starts_with("foo.", "foo"))
        self.assertTrue(gemato.util.path_starts_with("foo", "foo/"))
        self.assertTrue(gemato.util.path_starts_with("foo/", "foo/"))
        self.assertTrue(gemato.util.path_starts_with("foo/bar", "foo/bar/"))

    def test_path_inside_dir(self):
        self.assertFalse(gemato.util.path_inside_dir("", ""))
        self.assertTrue(gemato.util.path_inside_dir("foo", ""))
        self.assertTrue(gemato.util.path_inside_dir("foo/", ""))
        self.assertTrue(gemato.util.path_inside_dir("foo/bar", ""))
        self.assertTrue(gemato.util.path_inside_dir("bar", ""))
        self.assertTrue(gemato.util.path_inside_dir("bar/", ""))
        self.assertTrue(gemato.util.path_inside_dir("bar/bar", ""))
        self.assertFalse(gemato.util.path_inside_dir("foo", "foo"))
        self.assertFalse(gemato.util.path_inside_dir("foo/", "foo"))
        self.assertTrue(gemato.util.path_inside_dir("foo/bar", "foo"))
        self.assertFalse(gemato.util.path_inside_dir("bar", "foo"))
        self.assertFalse(gemato.util.path_inside_dir("fooo", "foo"))
        self.assertFalse(gemato.util.path_inside_dir("foo.", "foo"))
        self.assertFalse(gemato.util.path_inside_dir("foo", "foo/"))
        self.assertFalse(gemato.util.path_inside_dir("foo/", "foo/"))
        self.assertFalse(gemato.util.path_inside_dir("foo/bar", "foo/bar/"))