def test_is_consonant(self):
     """Test that consonants are correctly identified"""
     # Test all defined consonants. Should be True
     for i in self.consonants + self.consonants.upper():
         self.assertTrue(validate.is_consonant(i))
     # Test all defined consonants to be vowels or numbers. Should
     # be False
     for i in self.vowels + self.numbers:
         self.assertFalse(validate.is_consonant(i))
예제 #2
0
 def test_is_consonant(self):
     """Test that consonants are correctly identified"""
     # Test all defined consonants. Should be True
     for i in self.consonants + self.consonants.upper():
         self.assertTrue(validate.is_consonant(i))
     # Test all defined consonants to be vowels or numbers. Should
     # be False
     for i in self.vowels + self.numbers:
         self.assertFalse(validate.is_consonant(i))
    def test_is_punctuation(self):
        """Test that punctuations are correctly identified

        Anything that is neither a number, nor vowel nor consonant is
        identified as a punctuation.

        """
        for i in '`~!@#$%^&*()-_=+\\|[{}]\'",<.>/?':
            self.assertTrue(validate.is_punctuation(i))
            self.assertFalse(validate.is_vowel(i))
            self.assertFalse(validate.is_consonant(i))
            self.assertFalse(validate.is_number(i))
예제 #4
0
    def test_is_punctuation(self):
        """Test that punctuations are correctly identified

        Anything that is neither a number, nor vowel nor consonant is
        identified as a punctuation.

        """
        for i in '`~!@#$%^&*()-_=+\\|[{}]\'",<.>/?':
            self.assertTrue(validate.is_punctuation(i))
            self.assertFalse(validate.is_vowel(i))
            self.assertFalse(validate.is_consonant(i))
            self.assertFalse(validate.is_number(i))
예제 #5
0
def process_match(match, fixed_text, cur, cur_end):
    """Processes a single match in rules"""
    # Set our tools
    # -- Initial/default value for replace
    replace = True
    # -- Set check cursor depending on match['type']
    if match['type'] == 'prefix':
        chk = cur - 1
    else:
        # suffix
        chk = cur_end
    # -- Set scope based on whether scope is negative
    if match['scope'].startswith('!'):
        scope = match['scope'][1:]
        negative = True
    else:
        scope = match['scope']
        negative = False

    # Let the matching begin
    # -- Punctuations
    if scope == 'punctuation':
        # Conditions: XORd with negative
        if (not ((chk < 0 and match['type'] == 'prefix') or
                 (chk >= len(fixed_text) and match['type'] == 'suffix') or
                 validate.is_punctuation(fixed_text[chk]))
            ^ negative):
            replace = False
    # -- Vowels -- Checks: 1. Cursor should not be at first character
    # -- if prefix or last character if suffix, 2. Character at chk
    # -- should be a vowel. 3. 'negative' will invert the value of 1
    # -- AND 2
    elif scope == 'vowel':
        if (not (((chk >= 0 and match['type'] == 'prefix') or
                  (chk < len(fixed_text) and match['type'] == 'suffix'))
                 and validate.is_vowel(fixed_text[chk]))
            ^ negative):
            replace =  False
    # -- Consonants -- Checks: 1. Cursor should not be at first
    # -- character if prefix or last character if suffix, 2. Character
    # -- at chk should be a consonant. 3. 'negative' will invert the
    # -- value of 1 AND 2
    elif scope == 'consonant':
        if (not (((chk >= 0 and match['type'] == 'prefix') or
                  (chk < len(fixed_text) and match['type'] == 'suffix'))
                 and validate.is_consonant(fixed_text[chk]))
            ^ negative):
            replace = False
    # -- Exacts
    elif scope == 'exact':
        # Prepare cursor for exact search
        if match['type'] == 'prefix':
            exact_start = cur - len(match['value'])
            exact_end = cur
        else:
            # suffix
            exact_start = cur_end
            exact_end = cur_end + len(match['value'])
        # Validate exact find.
        if not validate.is_exact(match['value'], fixed_text, exact_start,
                                 exact_end, negative):
            replace = False
    # Return replace, which will be true if none of the checks above match
    return replace