async def test_parse_literal_empty_empty_builder(self): # Given message = await InputMessage.create('') parser = ReconParser() # When actual = await parser.parse_literal(message) # Then self.assertEqual(Absent.get_absent(), actual)
async def test_parse_decimal_empty_positive_empty_value(self): # Given message = await InputMessage.create('') parser = ReconParser() # When actual = await DecimalParser.parse(message, parser) # Then self.assertIsInstance(actual, Num) self.assertEqual(0.0, actual.value)
async def test_parse_string_normal(self): # Given message = await InputMessage.create('"Hello, friend"') parser = ReconParser() # When actual = await parser.parse_string(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('Hello, friend', actual.value)
async def test_parse_ident_valid_with_leading_spaces(self): # Given message = await InputMessage.create(' foo') parser = ReconParser() # When actual = await parser.parse_ident(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('foo', actual.value)
async def test_parse_decimal_dot_only_negative_empty_value(self): # Given message = await InputMessage.create('.') parser = ReconParser() # When actual = await DecimalParser.parse(message, parser, sign_output=-1) # Then self.assertIsInstance(actual, Num) self.assertEqual(-0.0, actual.value)
async def test_parse_string_empty(self): # Given message = InputMessage() parser = ReconParser() # When actual = await parser.parse_string(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('', actual.value)
async def test_parse_number_empty(self): # Given message = await InputMessage.create('') parser = ReconParser() # When actual = await parser.parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(0, actual.value)
async def test_attr_expression_parser_parse_literal(self): # Given message = await InputMessage.create('literal') parser = ReconParser() # When actual = await parser.parse_attr_expression(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('literal', actual.value)
async def test_parse_number_leading_zeroes(self): # Given message = await InputMessage.create('00013') parser = ReconParser() # When actual = await parser.parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(13, actual.value)
async def test_parse_number_float_point_only(self): # Given message = await InputMessage.create('.') parser = ReconParser() # When actual = await parser.parse_number(message, sign_output=-1) # Then self.assertIsInstance(actual, Num) self.assertEqual(-0.00, actual.value)
async def test_parse_number_positive_float_decimal_only(self): # Given message = await InputMessage.create(' .12') parser = ReconParser() # When actual = await parser.parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(0.12, actual.value)
async def test_parse_number_negative_float_full(self): # Given message = await InputMessage.create(' -11.12') parser = ReconParser() # When actual = await parser.parse_number(message) # Then self.assertIsInstance(actual, Num) self.assertEqual(-11.12, actual.value)
async def test_parse_string_missing_closing_quote(self): # Given message = await InputMessage.create(' "Hello, World') parser = ReconParser() # When actual = await parser.parse_string(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('Hello, World', actual.value)
async def test_parse_attr_no_body(self): # Given message = await InputMessage.create('@animal') parser = ReconParser() # When actual = await parser.parse_attr(message) # Then self.assertIsInstance(actual, Attr) self.assertIsInstance(actual.key, Text) self.assertEqual('animal', actual.key.value)
async def test_parse_ident_invalid(self): # Given message = await InputMessage.create('$lane: test') parser = ReconParser() # When with self.assertRaises(TypeError) as error: await parser.parse_ident(message) # Then message = error.exception.args[0] self.assertEqual('Identifier starting at position 0 is invalid!\nMessage: $lane: test', message)
async def test_parse_ident_invalid_with_output(self): # Given message = await InputMessage.create('$$') parser = ReconParser() output = await OutputMessage.create('hello') # When actual = await parser.parse_ident(message, output) # Then self.assertIsInstance(actual, Text) self.assertEqual('hello', actual.value)
async def test_parse_decimal_negative_existing_value(self): # Given message = await InputMessage.create('.1091') parser = ReconParser() value_output = -13 # When actual = await DecimalParser.parse(message, parser, value_output, sign_output=-1) # Then self.assertIsInstance(actual, Num) self.assertEqual(-13.1091, actual.value)
async def test_attr_expression_parser_parse_record_square_brackets(self): # Given message = await InputMessage.create('[record]') parser = ReconParser() # When actual = await parser.parse_attr_expression(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertEqual('record', actual.get_item(0).key.value)
async def test_parse_attr_empty(self): # Given message = await InputMessage.create('') parser = ReconParser() # When with self.assertRaises(TypeError) as error: await parser.parse_attr(message) # Then message = error.exception.args[0] self.assertEqual('Attribute starting at position 0 is invalid!\nMessage: ', message)
async def test_attr_expression_parser_parse_attribute(self): # Given message = await InputMessage.create('@test') parser = ReconParser() # When actual = await parser.parse_attr_expression(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(1, actual.size) self.assertEqual('test', actual.tag)
async def test_parse_string_existing_output(self): # Given message = await InputMessage.create('"dog"') output = await OutputMessage.create('This is ') parser = ReconParser() # When actual = await parser.parse_string(message, output) # Then self.assertIsInstance(actual, Text) self.assertEqual('This is dog', actual.value)
async def test_parse_literal_ident_empty_builder(self): # Given message = await InputMessage.create('foo') parser = ReconParser() # When actual = await parser.parse_literal(message) # Then self.assertIsInstance(actual, Text) self.assertEqual('foo', actual.value) self.assertEqual(Absent.get_absent(), actual.key)
async def test_parse_decimal_dot_only_positive_existing_value(self): # Given message = await InputMessage.create('.') parser = ReconParser() value_output = 17 # When actual = await DecimalParser.parse(message, parser, value_output) # Then self.assertIsInstance(actual, Num) self.assertEqual(17.0, actual.value)
async def test_record_parser_parse_empty(self): # Given message = await InputMessage.create('') parser = ReconParser() # When actual = await parser.parse_record(message) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(0, actual.size) self.assertEqual(Absent.get_absent(), actual.value)
async def test_parse_literal_minus_empty_builder(self): # Given message = await InputMessage.create('-13.42') parser = ReconParser() # When actual = await parser.parse_literal(message) # Then self.assertIsInstance(actual, Num) self.assertIsInstance(actual.value, float) self.assertEqual(-13.42, actual.value)
async def test_parse_literal_quote_empty_builder(self): # Given message = await InputMessage.create('"Baz_Foo"') parser = ReconParser() # When actual = await parser.parse_literal(message) # Then self.assertIsInstance(actual, Text) self.assertIsInstance(actual.value, str) self.assertEqual('Baz_Foo', actual.value)
async def test_record_parser_parse_key_only(self): # Given message = await InputMessage.create('{foo}') parser = ReconParser() # When actual = await 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)
async def test_record_parser_parse_square_brackets(self): # Given message = await InputMessage.create('[pet: mouse]') parser = ReconParser() # When actual = await 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)
async def test_record_parser_parse_single(self): # Given message = await InputMessage.create('{animal: dog}') parser = ReconParser() # When actual = await 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)
async def test_record_parser_parse_existing_key_value(self): # Given message = await InputMessage.create(':dog') parser = ReconParser() key = Text.create_from('animal') # When actual = await 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)