Exemplo n.º 1
0
 def test_MatchPatternsReturnEmails(self):
     string = """
     [email protected]
     [email protected]
     [email protected]
     [email protected]"""
     reg = Regex(string)
     regexExpression = r"[a-zA-Z0-9.\-_]+@[\w-]+\.(com|gov|net)+"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     #() group conditions together for matches that are option to match
     #[] sets of characters to look for
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 2
0
 def test_matchPatternsNameReturnsFanny(self):
     string = """
        Raymond Mustafa
        Ryan Lion
        Khan Jr
        Nizmo
        Fanny
        """
     reg = Regex(string)
     regexExpression = r"[F][a-z][a-z][a-z][a-z]"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     #  looks for F and any letter after it
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 3
0
 def test_SubGroupPatternsReturnTopDomainName(self):
     string = """
     http://www.cartoonnetwork.com
     http://www.nick.com
     https://www.SocGen.net
     https://www.youtube.gov
     https://www.youtube.uk
     https://youtube.uk
     http://www.amandaplease.com
     http://www.amanda-please.com
     https://www.Ilovenum123.com"""
     reg = Regex(string)
     regexExpression = r"https?://(w{3}\.)?([a-zA-Z0-9/-]+)(\.[a-zA-Z]+)"
     actual = reg.subGroupPatterns(pattern=regexExpression,
                                   string=string,
                                   indices=[1])
     expected = re.sub(regexExpression, r'\1', string)
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 4
0
 def test_matchPatternsNegateFNameReturnsNotFanny(self):
     string = """
        Raymond Mustafa
        Ryan Lion
        Khan Jr
        Nizmo
        Fanny
        """
     reg = Regex(string)
     regexExpression = r"[^F][a-z][a-z][a-z][a-z]"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # ^  negate what you are not looking for in this case F
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 5
0
 def test_MatchPatternsReturnsPrefixNamesString(self):
     string = """Mr Roy roger
     Mr. John Wayne
     mr Ray Yaz
     mr. Niz Hanif
     Ms Mary Jane Watson
     Ms Fanny Reguieg
     Ms Vanessa Ragubar"""
     reg = Regex(string)
     regexExpression = r"[mM]r\.?"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # ? option value for the period if it is there or not return match
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 6
0
 def test_SetSelectormatchPatternstelephoneEndReturnsAllInstance(self):
     string = """
     917-293-9422
     514*264*8577
     516a524a7485
     516452487485
     """
     reg = Regex(string)
     regexExpression = r"\d\d\d[-*]\d\d\d[-*]\d\d\d\d"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # /d - for digits
     # . all instance of word
     # [-*] set selector looking for only instances of - and * in that one char
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 7
0
 def test_PeriodIsNotTheBestOptmatchPatternstelephoneEndReturnsAllInstance(
         self):
     string = """
     917-293-9422
     514*264*8577
     516a524a7485
     516452487485
     """
     reg = Regex(string)
     regexExpression = r"\d\d\d.\d\d\d.\d\d\d\d"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # /d - for digits
     # . all instance of word
     # period is not the best instance because it returns also alphaNumeric instance
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 8
0
 def test_MatchPatternsReturnURLsSocieteGeneralLowerrCaseURLs(self):
     string = """
     http://www.cartoonnetwork.com
     http://www.nick.com
     https://www.SocGen.net
     https://www.youtube.gov
     https://www.youtube.uk
     https://youtube.uk
     http://www.amandaplease.com
     http://www.amanda-please.com
     https://www.Ilovenum123.com"""
     reg = Regex(string)
     regexExpression = r"https?://(w{3}\.)?([socgen]+)(\.[a-zA-Z]+)"
     actual = reg.matchPatterns(pattern=regexExpression, flag=re.IGNORECASE)
     patternX = re.compile(regexExpression, flags=re.IGNORECASE)
     expected = []
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 9
0
 def test_MatchPatternsReturnFemaleNames(self):
     string = """Mr Roy roger
     Mr. John Wayne
     mr Ray Yaz
     mr. Niz Hanif
     Ms Rebecca Wong
     Ms Fanny Reguieg
     Ms Vanessa Ragubar"""
     reg = Regex(string)
     regexExpression = r"[mM]s\.?\s[A-Z]\w*\s\w*"
     actual = reg.matchPatterns(pattern=regexExpression)
     patternX = re.compile(regexExpression)
     expected = []
     # ? option value for the period if it is there or not return match
     # * return 0 or more instance of character matching
     # \s return space instance
     # \. period character
     for match in patternX.finditer(string):
         expected.append(match.start())
         expected.append(match.group())
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 10
0
 def test_MatchPatternsReturnTopDomainName(self):
     string = """
     http://www.cartoonnetwork.com
     http://www.nick.com
     https://www.SocGen.net
     https://www.youtube.gov
     https://www.youtube.uk
     https://youtube.uk
     http://www.amandaplease.com
     http://www.amanda-please.com
     https://www.Ilovenum123.com"""
     reg = Regex(string)
     regexExpression = r"https?://(w{3}\.)?([a-zA-Z0-9/-]+)(\.[a-zA-Z]+)"
     actual = reg.matchPatternsGroups(pattern=regexExpression, index=3)
     patternX = re.compile(regexExpression)
     expected = []
     #() group conditions together for matches that are option to match
     #[] sets of characters to look for
     #? match only if it exist or not for that char
     for match in patternX.finditer(string):
         expected.append(match.group(3))
     print(actual)
     self.assertEqual(actual, expected)
Exemplo n.º 11
0
 def test_getString(self):
     string = "HW"
     regex = Regex(string)
     actual = regex.getString()
     expected = string
     self.assertEqual(actual, expected)
Exemplo n.º 12
0
 def test_NumericStringisAllLettersreturnsFalse(self):
     string = "1231414"
     reg = Regex(string)
     actual = reg.isAllLetters()
     expected = False
     self.assertEqual(actual, expected)
Exemplo n.º 13
0
 def test_NumericWithAlphaStringisAllLettersreturnsFalse(self):
     string = "123ABC"
     reg = Regex(string)
     actual = reg.isAllLetters(pattern="^[a-zA-Z]+$")
     expected = False
     self.assertEqual(actual, expected)
Exemplo n.º 14
0
 def test_isPatternOfreturnsTrue(self):
     string = "HelloWorld"
     reg = Regex(string)
     actual = reg.isPatternOf()
     expected = True
     self.assertEqual(actual, expected)
Exemplo n.º 15
0
 def test_isInstanceOfRegexModXisTrue(self):
     string = "HW"
     regex = Regex(string)
     self.assertTrue(isinstance(regex, Regex))
Exemplo n.º 16
0
 def test_NumericStringisAllLettersreturnsFalse(self):
     string = "123"
     reg = Regex(string)
     actual = reg.isAllLetters(pattern="^[0-9]+$")
     expected = True
     self.assertEqual(actual, expected)
Exemplo n.º 17
0
 def test_emptyStringisAllLettersreturnsFalse(self):
     string = ""
     reg = Regex(string)
     actual = reg.isAllLetters()
     expected = False
     self.assertEqual(actual, expected)