Пример #1
0
 def test_AddingLabel(self):
     # Arrange
     parser1 = bpr.LParser('l')
     parser2 = bpr.LParser('o')
     parser3 = bpr.LParser('r')
     parser = cmb.until(parser1, parser2, parser3, label='Parser: lor')
     parser_default_label = cmb.until(parser1, parser2, parser3)
     # Assert
     self.assertEqual(parser.label, 'Parser: lor')
     self.assertEqual(parser_default_label.label, '(.*?)[lor]')
Пример #2
0
    def test_FailureCase(self):
        # Arrange
        txt = 'Lorem'
        parser_1 = bpr.LParser('1')

        # Act
        parser = cmb.until(parser_1)
        result = parser(txt)
        expected = res.Failure('No more input')
        # Assert
        self.assertEqual(result, expected)
Пример #3
0
 def test_CorrectlyHandlesDifferentNumberOfArguments_Failure(self):
     # Arrange
     txt = 'Lorem'
     parser_1 = bpr.LParser('1')
     parser_2 = bpr.LParser('2')
     parser_3 = bpr.LParser('3')
     parser = cmb.until(parser_1, parser_2, parser_3)
     # Act
     result = parser(txt)
     expected = res.Failure.unit('No more input')
     # Arrange
     self.assertEqual(result, expected)
Пример #4
0
    def test_SuccessCase(self):
        # Arrange
        txt1 = 'Lorem1'
        txt2 = 'Lorem#ipsum'
        parser_1 = bpr.LParser('1')
        parser_sharp = bpr.LParser('#')

        # Act
        parser = cmb.until(parser_1, parser_sharp)
        result1 = parser(txt1)
        result2 = parser(txt2)
        expected1 = res.Success(('Lorem', '1'))
        expected2 = res.Success(('Lorem', '#ipsum'))
        # Assert
        self.assertEqual(result1, expected1)
        self.assertEqual(result2, expected2)
Пример #5
0
    def test_CorrectlyHandlesDifferentNumberOfArguments_Success(self):
        # Arrange
        txt1 = 'Lorem1'
        txt2 = 'Lorem2asdas'
        txt3 = 'Lorem31as'
        parser_1 = bpr.LParser('1')
        parser_2 = bpr.LParser('2')
        parser_3 = bpr.LParser('3')

        # Act
        parser = cmb.until(parser_1, parser_2, parser_3)
        result1 = parser(txt1)
        result2 = parser(txt2)
        result3 = parser(txt3)
        expected1 = res.Success.unit(('Lorem', '1'))
        expected2 = res.Success.unit(('Lorem', '2asdas'))
        expected3 = res.Success.unit(('Lorem', '31as'))

        # # Assert
        self.assertEqual(result1, expected1)
        self.assertEqual(result2, expected2)
        self.assertEqual(result3, expected3)