Exemplo n.º 1
0
 def test_WHEN_defined_symbol_is_in_symbol_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = singleton_symbol_table(string_entry('already-defined'))
     symbol_usage = symbol_of('already-defined')
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Exemplo n.º 2
0
 def test_WHEN_referenced_symbol_is_in_symbol_table_and_satisfies_value_restriction_THEN_no_error(self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('val_name', 'value string').symbol_table
     symbol_reference = SymbolReference('val_name',
                                        ReferenceRestrictionsOnDirectAndIndirect(
                                            RestrictionThatIsAlwaysSatisfied()))
     # ACT #
     actual = sut.validate_symbol_usage(symbol_reference, symbol_table)
     self.assertIsNone(actual, 'result should indicate success')
Exemplo n.º 3
0
 def test_WHEN_referenced_symbol_is_in_symbol_table_and_satisfies_value_restriction_THEN_no_error(self):
     # ARRANGE #
     symbol_table = singleton_symbol_table(string_entry('val_name', 'value string'))
     symbol_usage = su.SymbolReference('val_name',
                                       ReferenceRestrictionsOnDirectAndIndirect(
                                           RestrictionThatIsAlwaysSatisfied()))
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNone(actual, 'result should indicate success')
Exemplo n.º 4
0
 def test_WHEN_referenced_symbol_not_in_symbol_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     symbol_usage = su.SymbolReference('undefined', unconditionally_satisfied_reference_restrictions())
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Exemplo n.º 5
0
 def test_WHEN_referenced_symbol_not_in_symbol_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = empty_symbol_table()
     symbol_usage = SymbolReference('undefined', reference_restrictions__unconditionally_satisfied())
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Exemplo n.º 6
0
 def test_WHEN_defined_symbol_is_in_symbol_table_THEN_validation_error(self):
     # ARRANGE #
     name = 'already-defined'
     symbol_table = StringSymbolContext.of_constant(name, 'arbitrary value').symbol_table
     symbol_definition = StringSymbolContext.of_constant(name, 'other value').definition
     # ACT #
     actual = sut.validate_symbol_usage(symbol_definition, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Exemplo n.º 7
0
 def test_WHEN_defined_symbol_not_in_symbol_table_THEN_None_and_added_to_symbol_table(self):
     # ARRANGE #
     symbol_table = singleton_symbol_table(string_entry('other'))
     symbol_usage = symbol_of('undefined')
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNone(actual, 'return value for indicating')
     self.assertTrue(symbol_table.contains('undefined'),
                     'definition should be added to symbol table')
     self.assertTrue(symbol_table.contains('other'),
                     'definition in symbol table before definition should remain there')
Exemplo n.º 8
0
 def test_WHEN_referenced_symbol_is_in_symbol_table_but_does_not_satisfy_value_restriction_THEN_validation_error(
         self):
     # ARRANGE #
     symbol_table = singleton_symbol_table(string_entry('val_name', 'symbol string'))
     symbol_usage = su.SymbolReference('val_name',
                                       unconditionally_unsatisfied_reference_restrictions())
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Exemplo n.º 9
0
 def test_WHEN_defined_symbol_not_in_symbol_table_THEN_None_and_added_to_symbol_table(self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('other', 'value').symbol_table
     symbol_definition = StringSymbolContext.of_constant('undefined', 'value').definition
     # ACT #
     actual = sut.validate_symbol_usage(symbol_definition, symbol_table)
     self.assertIsNone(actual, 'return value for indicating')
     self.assertTrue(symbol_table.contains('undefined'),
                     'definition should be added to symbol table')
     self.assertTrue(symbol_table.contains('other'),
                     'definition in symbol table before definition should remain there')
Exemplo n.º 10
0
 def test_WHEN_referenced_symbol_is_in_symbol_table_but_does_not_satisfy_value_restriction_THEN_validation_error(
         self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('val_name', 'symbol string').symbol_table
     symbol_usage = SymbolReference('val_name',
                                    reference_restrictions__unconditionally_unsatisfied())
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'result should indicate error')
     self.assertIs(PartialControlledFailureEnum.VALIDATION_ERROR,
                   actual.status)
Exemplo n.º 11
0
 def test_WHEN_defined_symbol_not_in_symbol_table_but_referenced_symbols_not_in_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('OTHER', 'value').symbol_table
     symbol = PathSymbolContext.of_sdv(
         'UNDEFINED',
         path_sdvs.rel_symbol(SymbolReference('REFERENCED',
                                              ReferenceRestrictionsOnDirectAndIndirect(
                                                  RestrictionThatIsAlwaysSatisfied())),
                              path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     self.assertIsNotNone(actual, 'return value for indicating error')
Exemplo n.º 12
0
 def test_WHEN_defined_symbol_not_in_symbol_table_but_referenced_symbols_not_in_table_THEN_validation_error(self):
     # ARRANGE #
     symbol_table = singleton_symbol_table(string_entry('OTHER'))
     symbol_usage = su.SymbolDefinition(
         'UNDEFINED',
         file_ref_resolver_container(
             file_ref_resolvers.rel_symbol(su.SymbolReference('REFERENCED',
                                                              ReferenceRestrictionsOnDirectAndIndirect(
                                                                  RestrictionThatIsAlwaysSatisfied())),
                                           path_part_resolvers.from_constant_str('file-name'))))
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage, symbol_table)
     self.assertIsNotNone(actual, 'return value for indicating error')
Exemplo n.º 13
0
 def test_WHEN_defined_symbol_not_in_table_but_referenced_symbol_in_table_does_not_satisfy_restriction_THEN_error(
         self):
     # ARRANGE #
     symbol_table = StringSymbolContext.of_constant('REFERENCED', 'value').symbol_table
     symbol = PathSymbolContext.of_sdv(
         'UNDEFINED',
         path_sdvs.rel_symbol(SymbolReference('REFERENCED',
                                              reference_restrictions__unconditionally_unsatisfied()),
                              path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     # ASSERT #
     self.assertIsNotNone(actual, 'return value for indicating error')
Exemplo n.º 14
0
 def test_WHEN_defined_symbol_not_in_table_but_referenced_symbol_in_table_does_not_satisfy_restriction_THEN_error(
         self):
     # ARRANGE #
     referenced_entry = string_entry('REFERENCED')
     symbol_table = singleton_symbol_table(referenced_entry)
     symbol_usage_to_check = su.SymbolDefinition(
         'UNDEFINED',
         file_ref_resolver_container(
             file_ref_resolvers.rel_symbol(su.SymbolReference('REFERENCED',
                                                              unconditionally_unsatisfied_reference_restrictions()),
                                           path_part_resolvers.from_constant_str('file-name'))))
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage_to_check, symbol_table)
     # ASSERT #
     self.assertIsNotNone(actual, 'return value for indicating error')
Exemplo n.º 15
0
 def test_WHEN_defined_symbol_not_in_symbol_table_and_referenced_symbol_is_in_table_and_satisfies_restriction_THEN_ok(
         self):
     # ARRANGE #
     referenced_symbol = StringSymbolContext.of_constant('REFERENCED', 'value')
     symbol_table = referenced_symbol.symbol_table
     symbol = PathSymbolContext.of_sdv('UNDEFINED',
                                       path_sdvs.rel_symbol(
                                           SymbolReference('REFERENCED',
                                                           ReferenceRestrictionsOnDirectAndIndirect(
                                                               RestrictionThatIsAlwaysSatisfied())),
                                           path_part_sdvs.from_constant_str('file-name')))
     # ACT #
     actual = sut.validate_symbol_usage(symbol.definition, symbol_table)
     # ASSERT #
     self.assertIsNone(actual, 'return value for indicating success')
     self.assertTrue(symbol_table.contains('UNDEFINED'),
                     'definition should have been added')
Exemplo n.º 16
0
 def test_WHEN_defined_symbol_not_in_symbol_table_and_referenced_symbol_is_in_table_and_satisfies_restriction_THEN_ok(
         self):
     # ARRANGE #
     referenced_entry = string_entry('REFERENCED')
     symbol_table = singleton_symbol_table(referenced_entry)
     symbol_usage_to_check = su.SymbolDefinition(
         'UNDEFINED',
         file_ref_resolver_container(
             file_ref_resolvers.rel_symbol(su.SymbolReference('REFERENCED',
                                                              ReferenceRestrictionsOnDirectAndIndirect(
                                                                  RestrictionThatIsAlwaysSatisfied())),
                                           path_part_resolvers.from_constant_str('file-name'))))
     # ACT #
     actual = sut.validate_symbol_usage(symbol_usage_to_check, symbol_table)
     # ASSERT #
     self.assertIsNone(actual, 'return value for indicating success')
     self.assertTrue(symbol_table.contains('UNDEFINED'),
                     'definition should have been added')