Merge pull request #87 from mousavian/master
[git-ftp.git] / git-ftp-test.py
blob75f05a5e3b0f0dc30c6dd6388b1d12ac54afcc86
1 #!/usr/bin/env python
2 # -*- coding:utf-8 -*-
4 import unittest
6 git_ftp = __import__('git-ftp', globals(), locals(), ['parse_ftpignore', 'is_ignored', 'split_pattern'], 0)
7 parse_ftpignore = git_ftp.parse_ftpignore
8 is_ignored = git_ftp.is_ignored
9 split_pattern = git_ftp.split_pattern
12 class TestGitFtp(unittest.TestCase):
14 def test_parse_ftpignore(self):
15 patterns = '''
16 # comment and blank line
18 # negate patterns behaviour (not supported)
19 !fileX.txt
20 # directory match
21 config/
22 # shell glob (without /)
23 *swp
24 BasePresenter.php
25 # with /
26 css/*less
27 # beginning of path
28 /.htaccess
29 '''
30 self.assertEqual(parse_ftpignore(patterns.split("\n")),
31 ['!fileX.txt', 'config/', '*swp', 'BasePresenter.php', 'css/*less', '/.htaccess']
33 pass
35 def test_split_pattern(self):
36 self.assertEqual(split_pattern('/foo/rand[/]om/dir/'), ['', 'foo\\Z(?ms)', 'rand[/]om\\Z(?ms)', 'dir\\Z(?ms)', '\\Z(?ms)'])
37 self.assertEqual(split_pattern('/ano[/]her/bar/file[.-0]txt'), ['', 'ano[/]her\\Z(?ms)', 'bar\\Z(?ms)', 'file[.-0]txt\\Z(?ms)'])
38 self.assertEqual(split_pattern('left[/right'), ['left\\[\\Z(?ms)', 'right\\Z(?ms)'])
39 self.assertEqual(split_pattern('left[/notright]'), ['left[/notright]\\Z(?ms)'])
40 pass
42 def test_is_ignored(self):
43 self.assertTrue(is_ignored('/foo/bar/', 'bar/'), 'Ending slash matches only dir.')
44 self.assertFalse(is_ignored('/foo/bar', 'bar/'), 'Ending slash matches only dir.')
45 self.assertTrue(is_ignored('/foo/bar/baz', 'bar/'), 'Ending slash matches only dir and path underneath it.')
47 self.assertFalse(is_ignored('foo/bar', 'foo?*bar'), 'Slash must be matched explicitly.')
49 self.assertTrue(is_ignored('/foo/bar/', 'bar'))
50 self.assertTrue(is_ignored('/foo/bar', 'bar'))
51 self.assertTrue(is_ignored('/foo/bar/baz', 'bar'))
53 self.assertTrue(is_ignored('/foo/bar/file.txt', 'bar/*.txt'))
54 self.assertFalse(is_ignored('/foo/bar/file.txt', '/*.txt'), 'Leading slash matches against root dir.')
55 self.assertTrue(is_ignored('/file.txt', '/*.txt'), 'Leading slash matches against root dir.')
57 self.assertTrue(is_ignored('/foo/bar/output.o', 'bar/*.[oa]'), 'Character group.')
58 self.assertFalse(is_ignored('/aaa/bbb/ccc', 'aaa/[!b]*'), 'Character ignore.')
59 self.assertTrue(is_ignored('/aaa/bbb/ccc', '[a-z][a-c][!b-d]'), 'Character range.')
60 pass
63 if __name__ == '__main__':
64 unittest.main()