Debian Codegraph @

tests/test_02_gitignore_base.py

raw
1 """
2 This script tests :class:`._GitIgnoreBasePattern`.
3 """
4
5 import unittest
6
7 from pathspec.patterns.gitignore.base import (
8 _BYTES_ENCODING,
9 _GitIgnoreBasePattern)
10
11
12 class GitIgnoreBasePatternTest(unittest.TestCase):
13 """
14 The :class:`GitIgnoreBasePatternTest` class tests the :class:`_GitIgnoreBasePattern`
15 implementation.
16 """
17
18 def test_01_escape_bytes(self):
19 """
20 Test escaping binary strings.
21 """
22 byte_to_escaped = {__b: b'\\' + __b for __b in (
23 __c.encode(_BYTES_ENCODING) for __c in '\\[]!*#?'
24 )}
25 for char_ord in range(256):
26 char_byte = chr(char_ord).encode(_BYTES_ENCODING)
27 escape_val = _GitIgnoreBasePattern.escape(char_byte)
28 expect_val = byte_to_escaped.get(char_byte, char_byte)
29 self.assertEqual(escape_val, expect_val)
30
31 def test_01_escape_str(self):
32 """
33 Test escaping unicode strings.
34 """
35 char_to_escaped = {__c: f"\\{__c}" for __c in '\\[]!*#?'}
36 for char_ord in range(128):
37 char = chr(char_ord)
38 escape_val = _GitIgnoreBasePattern.escape(char)
39 expect_val = char_to_escaped.get(char, char)
40 self.assertEqual(escape_val, expect_val)