type_parsing_test.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2022 DeepMind Technologies Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """Tests for type_parsing.py."""
  16. from absl.testing import absltest
  17. from . import ast_nodes
  18. from . import type_parsing
  19. class TypeParsingTest(absltest.TestCase):
  20. def test_parse_complex_type(self):
  21. parsed_type = type_parsing.parse_type(
  22. 'int unsigned volatile long const long'+
  23. '(**const(*const restrict*[9])[7])[3][4]')
  24. expected_type = ast_nodes.ArrayType(
  25. extents=[9],
  26. inner_type=ast_nodes.PointerType(
  27. ast_nodes.PointerType(
  28. is_const=True,
  29. is_restrict=True,
  30. inner_type=ast_nodes.ArrayType(
  31. extents=[7],
  32. inner_type=ast_nodes.PointerType(
  33. is_const=True,
  34. inner_type=ast_nodes.PointerType(
  35. ast_nodes.ArrayType(
  36. extents=(3, 4),
  37. inner_type=ast_nodes.ValueType(
  38. 'int unsigned long long',
  39. is_const=True, is_volatile=True)
  40. )
  41. )
  42. )
  43. )
  44. )
  45. )
  46. )
  47. self.assertEqual(parsed_type, expected_type)
  48. if __name__ == '__main__':
  49. absltest.main()