summaryrefslogtreecommitdiff
path: root/tests/test_util.py
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-24 18:34:29 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-24 18:34:29 +0200
commit5f1b073c967928624cc8cfb417644df0db152f84 (patch)
treedc4d561c4e2747577c943ac85446752b056f8b5b /tests/test_util.py
parentbad53c86d171ed892df985ecc73aa5fdb8710d50 (diff)
downloadgemato-5f1b073c967928624cc8cfb417644df0db152f84.tar.gz
Abstract out path prefix comparisons
Diffstat (limited to 'tests/test_util.py')
-rw-r--r--tests/test_util.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_util.py b/tests/test_util.py
new file mode 100644
index 0000000..41aa34c
--- /dev/null
+++ b/tests/test_util.py
@@ -0,0 +1,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/"))