Ejemplo n.º 1
0
def check_name(name):
    (result, index, comment) = (True, -1, "")
    if len(name) >= 30:
        return fcr.FormatCheckResult(False, 30, "Too long name")
    m = re.search("[A-Za-z亜-熙ぁ-んァ-ヶ .]+", name)
    if m.start() != 0:
        (result, index, comment) = (False, m.start() - 1, "Wrong name")
    elif m.end() != len(name):
        (result, index, comment) = (False, m.end(), "Wrong name")

    return fcr.FormatCheckResult(result, index, comment)
Ejemplo n.º 2
0
 def test_raise_indexerror_when_index_is_negative_when_false_result(self):
     try:
         fresult = fcr.FormatCheckResult(result=False,
                                         index=-1,
                                         comment="something wrong")
         self.fail("do not raise")
     except IndexError:
         pass
Ejemplo n.º 3
0
 def test_set_value_only_in_constructing(self):
     fresult = fcr.FormatCheckResult(result=True,
                                     index=4,
                                     comment="something wrong")
     self.assertEqual(fresult.get_result(), True)
     self.assertEqual(fresult.get_index(), 4)
     self.assertEqual(fresult.get_message(),
                      "Wrong format in [4]: something wrong")
Ejemplo n.º 4
0
def check_email(email):
    (result, index, comment) = (True, -1, "")
    m = re.search("[A-Za-z0-9._-]+@[A-Za-z]+(.[A-Za-z]+)+", email)
    if m.start() != 0:
        (result, index, comment) = (False, m.start() - 1, "Wrong email format")
    elif m.end() != len(email):
        (result, index, comment) = (False, m.end(), "Wrong email format")
    else:
        m = re.search("\.\.|\.@", email)
        if m is not None:
            (result, index,
             comment) = (False, m.start(),
                         "Wrong email format. Cannnot use '..' or '.@'.")
    return fcr.FormatCheckResult(result, index, comment)
Ejemplo n.º 5
0
def check_address(address):
    (result, index, comment) = (True, -1, "")
    m = re.search("[亜-熙ぁ-んァ-ヶA-Za-z]+", address)
    if m is None:
        (result, index, comment) = (False, 0, "Wrong address format")
    return fcr.FormatCheckResult(result, index, comment)
Ejemplo n.º 6
0
    def test_can_return_result(self):
        fresult = fcr.FormatCheckResult(result=True, index=0, comment="")
        self.assertEqual(fresult.get_result(), True)

        fresult = fcr.FormatCheckResult(result=False, index=1, comment="fail")
        self.assertEqual(fresult.get_result(), False)
Ejemplo n.º 7
0
 def test_raise_indexerror_when_index_is_negative_when_false_result(self):
     try:
         fresult = fcr.FormatCheckResult(result=True, index=-1, comment="")
     except IndexError:
         self.fail("raised")
Ejemplo n.º 8
0
 def test_format_message_with_index_and_comment(self):
     fresult = fcr.FormatCheckResult(result=False,
                                     index=50,
                                     comment="Error message")
     self.assertEqual(fresult.get_message(),
                      "Wrong format in [50]: Error message")
Ejemplo n.º 9
0
 def test_can_return_index(self):
     fresult = fcr.FormatCheckResult(result=False, index=10, comment="")
     self.assertEqual(fresult.get_index(), 10)