def test_can_append_scalar_conditional(self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) parser.append({ 'name': 'bar', 'condition': 'foo', 'condition_value': 'red' }) result = parser.commit() # Assert: self.assertEqual(('Car', { 'type': 'struct', 'layout': [{ 'name': 'foo' }, { 'name': 'bar', 'condition': 'foo', 'condition_value': 'red' }] }), result)
def test_cannot_append_array_with_invalid_size_reference(self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) # Assert: with self.assertRaises(CatsParseException): parser.append({'name': 'bar', 'size': 'fob'})
def test_cannot_append_multiple_properties_with_same_name_and_disposition( self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) parser.append({'name': 'bar'}) # Assert: with self.assertRaises(CatsParseException): parser.append({'name': 'foo'})
def test_cannot_append_scalar_with_invalid_condition_reference(self): for condition in ['baz', '10']: # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) # Assert: with self.assertRaises(CatsParseException): parser.append({ 'name': 'bar', 'condition': condition, 'condition_value': 'red' })
def test_can_append_array_with_fill_disposition_last(self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) parser.append({'name': 'cat', 'disposition': 'fill'}) result = parser.commit() # Assert: self.assertEqual(('Car', { 'type': 'struct', 'layout': [{ 'name': 'foo' }, { 'name': 'cat', 'disposition': 'fill' }] }), result)
def test_can_append_unnamed_descriptor(self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'disposition': 'inline', 'type': 'Foo'}) parser.append({'name': 'foo'}) result = parser.commit() # Assert: self.assertEqual(('Car', { 'type': 'struct', 'layout': [{ 'disposition': 'inline', 'type': 'Foo' }, { 'name': 'foo' }] }), result)
def test_can_append_array_with_valid_size_reference(self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) parser.append({'name': 'bar', 'size': 'foo'}) result = parser.commit() # Assert: self.assertEqual( ('Car', { 'type': 'struct', 'layout': [{ 'name': 'foo' }, { 'name': 'bar', 'size': 'foo' }] }), result)
def test_can_append_multiple_properties_with_same_name_and_different_disposition( self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) parser.append({'name': 'foo', 'disposition': 'const'}) result = parser.commit() # Assert: self.assertEqual(('Car', { 'type': 'struct', 'layout': [{ 'name': 'foo' }, { 'name': 'foo', 'disposition': 'const' }] }), result)
def test_cannot_append_property_after_array_with_fill_disposition(self): # Arrange: parser = StructParserFactory().create() # Act: parser.process_line('struct Car') parser.append({'name': 'foo'}) parser.append({'name': 'cat', 'disposition': 'fill'}) # Assert: with self.assertRaises(CatsParseException): parser.append({'name': 'bar'})