def test_parse_string(self): # Arrange txt = 'lorem ipsum' parser_succ = stp.parse_string('lorem') parser_fail = stp.parse_string('ipsum', label='FAIL') # Act result_succ = parser_succ(txt) result_fail = parser_fail(txt) expected_succ = res.Success(('lorem', ' ipsum')) expected_fail = res.Failure('error') # Assert self.assertEqual(result_succ, expected_succ) self.assertEqual(result_fail, expected_fail) self.assertEqual(parser_succ.label, 'lorem') self.assertEqual(parser_fail.label, 'FAIL')
def test_strip(self): # Arrange txt1 = ' \n\tLorem \n\tIpsum' txt2 = ' 12312 \nXYZ' txt3 = '11Lorem111Ipsum' exp1 = res.Success(('Lorem', 'Ipsum')) exp2 = res.Success(('12312', 'XYZ')) exp3 = res.Success(('Lorem', 'Ipsum')) parser1 = stp.strip(stp.parse_string("Lorem")) parser2 = stp.strip(stp.parse_digits(), ignored_lst=[' ', '\n']) parser3 = stp.strip(stp.parse_string("Lorem"), ignored_lst=['1']) # Act res1 = parser1(txt1) res2 = parser2(txt2) res3 = parser3(txt3) # Assert self.assertEqual(res1, exp1) self.assertEqual(res2, exp2) self.assertEqual(res3, exp3) self.assertEqual(parser1.label, "Lorem") self.assertEqual(parser2.label, "[0-9]+") self.assertEqual(parser3.label, "Lorem")