def test_parse_literal_empty_empty_builder(self): # Given message = _InputMessage._create('') parser = _ReconParser() # When actual = parser._parse_literal(message) # Then self.assertEqual(_Absent._get_absent(), actual)
def test_parse_string_normal(self): # Given message = _InputMessage._create('"Hello, friend"') parser = _ReconParser() # When actual = parser._parse_string(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('Hello, friend', actual.value)
def test_parse_string_empty(self): # Given message = _InputMessage() parser = _ReconParser() # When actual = parser._parse_string(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('', actual.value)
def test_parse_string_missing_closing_quote(self): # Given message = _InputMessage._create(' "Hello, World') parser = _ReconParser() # When actual = parser._parse_string(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('Hello, World', actual.value)
def test_parse_number_empty(self): # Given message = _InputMessage._create('') parser = _ReconParser() # When actual = parser._parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(0, actual.value)
def test_parse_number_leading_zeroes(self): # Given message = _InputMessage._create('00013') parser = _ReconParser() # When actual = parser._parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(13, actual.value)
def test_parse_number_positive_float_decimal_only(self): # Given message = _InputMessage._create(' .12') parser = _ReconParser() # When actual = parser._parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(0.12, actual.value)
def test_parse_number_float_point_only(self): # Given message = _InputMessage._create('.') parser = _ReconParser() # When actual = parser._parse_number(message, sign_output=-1) # Then self.assertIsInstance(actual, Num) self.assertEqual(-0.00, actual.value)
def test_parse_decimal_dot_only_negative_empty_value(self): # Given message = _InputMessage._create('.') parser = _ReconParser() # When actual = _DecimalParser._parse(message, parser, sign_output=-1) # Then self.assertIsInstance(actual, Num) self.assertEqual(-0.0, actual.value)
def test_parse_number_negative_float_full(self): # Given message = _InputMessage._create(' -11.12') parser = _ReconParser() # When actual = parser._parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(-11.12, actual.value)
def test_parse_decimal_empty_positive_empty_value(self): # Given message = _InputMessage._create('') parser = _ReconParser() # When actual = _DecimalParser._parse(message, parser) # Then self.assertIsInstance(actual, Num) self.assertEqual(0.0, actual.value)
def test_attr_expression_parser_parse_literal(self): # Given message = _InputMessage._create('literal') parser = _ReconParser() # When actual = parser._parse_attr_expression(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('literal', actual.value)
def test_parse_ident_valid_with_leading_spaces(self): # Given message = _InputMessage._create(' foo') parser = _ReconParser() # When actual = parser._parse_ident(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('foo', actual.value)
def test_parse_string_existing_output(self): # Given message = _InputMessage._create('"dog"') output = _OutputMessage._create('This is ') parser = _ReconParser() # When actual = parser._parse_string(message, output) # Then self.assertIsInstance(actual, Text) self.assertEqual('This is dog', actual.value)
def test_parse_decimal_dot_only_positive_existing_value(self): # Given message = _InputMessage._create('.') parser = _ReconParser() value_output = 17 # When actual = _DecimalParser._parse(message, parser, value_output) # Then self.assertIsInstance(actual, Num) self.assertEqual(17.0, actual.value)
def test_parse_ident_invalid_with_output(self): # Given message = _InputMessage._create('$$') parser = _ReconParser() output = _OutputMessage._create('hello') # When actual = parser._parse_ident(message, output) # Then self.assertIsInstance(actual, Text) self.assertEqual('hello', actual.value)
def test_record_parser_parse_empty(self): # Given message = _InputMessage._create('') parser = _ReconParser() # When actual = parser._parse_record(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(0, actual.size) self.assertEqual(_Absent._get_absent(), actual.value)
def test_parse_literal_quote_empty_builder(self): # Given message = _InputMessage._create('"Baz_Foo"') parser = _ReconParser() # When actual = parser._parse_literal(message) # Then self.assertIsInstance(actual, Text) self.assertIsInstance(actual.value, str) self.assertEqual('Baz_Foo', actual.value)
def test_parse_literal_minus_empty_builder(self): # Given message = _InputMessage._create('-13.42') parser = _ReconParser() # When actual = parser._parse_literal(message) # Then self.assertIsInstance(actual, Num) self.assertIsInstance(actual.value, float) self.assertEqual(-13.42, actual.value)
def test_parse_literal_ident_empty_builder(self): # Given message = _InputMessage._create('foo') parser = _ReconParser() # When actual = parser._parse_literal(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('foo', actual.value) self.assertEqual(_Absent._get_absent(), actual.key)
def test_attr_expression_parser_parse_record_square_brackets(self): # Given message = _InputMessage._create('[record]') parser = _ReconParser() # When actual = parser._parse_attr_expression(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertEqual('record', actual.get_item(0).key.value)
def test_attr_expression_parser_parse_attribute(self): # Given message = _InputMessage._create('@test') parser = _ReconParser() # When actual = parser._parse_attr_expression(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertEqual('test', actual._tag)
def test_parse_attr_no_body(self): # Given message = _InputMessage._create('@animal') parser = _ReconParser() # When actual = parser._parse_attr(message) # Then self.assertIsInstance(actual, Attr) self.assertIsInstance(actual.key, Text) self.assertEqual('animal', actual.key.value)
def test_record_parser_parse_key_only(self): # Given message = _InputMessage._create('{foo}') parser = _ReconParser() # When actual = parser._parse_record(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertIsInstance(actual.get_item(0), Slot) self.assertEqual('foo', actual.get_item(0).key.value)
def test_record_parser_parse_square_brackets(self): # Given message = _InputMessage._create('[pet: mouse]') parser = _ReconParser() # When actual = parser._parse_record(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertEqual('pet', actual.get_item(0).key.value) self.assertEqual('mouse', actual.get_item(0).value.value)
def test_record_parser_parse_single(self): # Given message = _InputMessage._create('{animal: dog}') parser = _ReconParser() # When actual = parser._parse_record(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertEqual('animal', actual.get_item(0).key.value) self.assertEqual('dog', actual.get_item(0).value.value)
def test_parse_attr_empty(self): # Given message = _InputMessage._create('') parser = _ReconParser() # When with self.assertRaises(TypeError) as error: parser._parse_attr(message) # Then message = error.exception.args[0] self.assertEqual( 'Attribute starting at position 0 is invalid!\nMessage: ', message)
def test_record_parser_parse_existing_key_value(self): # Given message = _InputMessage._create(':dog') parser = _ReconParser() key = Text.create_from('animal') # When actual = parser._parse_record(message, key_output=key) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertEqual('animal', actual.get_item(0).key.value) self.assertEqual('dog', actual.get_item(0).value.value)
def test_parse_literal_empty_existing_builder(self): # Given message = _InputMessage._create('') builder = _ReconParser._create_value_builder() builder.add(Text.create_from('Hello')) parser = _ReconParser() # When actual = parser._parse_literal(message, builder) # Then self.assertIsInstance(actual, Text) self.assertEqual(0, actual.size) self.assertEqual('Hello', actual.value)
def test_parse_ident_invalid(self): # Given message = _InputMessage._create('$lane: test') parser = _ReconParser() # When with self.assertRaises(TypeError) as error: parser._parse_ident(message) # Then message = error.exception.args[0] self.assertEqual( 'Identifier starting at position 0 is invalid!\nMessage: $lane: test', message)