Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator_unittest.py

Issue 1522583003: New Mojom compiler: Assign a meaningful spec string instead of 'dummyspec' because it turns out it… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 import module 6 import module
7 7
8 try: 8 try:
9 import mojom_translator 9 import mojom_translator
10 from generated import mojom_files_mojom 10 from generated import mojom_files_mojom
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 source_file_info=mojom_types_mojom.SourceFileInfo( 70 source_file_info=mojom_types_mojom.SourceFileInfo(
71 file_name=file_name)), 71 file_name=file_name)),
72 interface_name='AnInterface') 72 interface_name='AnInterface')
73 graph.resolved_types['interface_key'] = mojom_types_mojom.UserDefinedType( 73 graph.resolved_types['interface_key'] = mojom_types_mojom.UserDefinedType(
74 interface_type=mojom_interface) 74 interface_type=mojom_interface)
75 75
76 mojom_struct = mojom_types_mojom.MojomStruct( 76 mojom_struct = mojom_types_mojom.MojomStruct(
77 fields=[], 77 fields=[],
78 decl_data=mojom_types_mojom.DeclarationData( 78 decl_data=mojom_types_mojom.DeclarationData(
79 short_name='AStruct', 79 short_name='AStruct',
80 full_identifier='foo.AStruct',
80 source_file_info=mojom_types_mojom.SourceFileInfo( 81 source_file_info=mojom_types_mojom.SourceFileInfo(
81 file_name=file_name))) 82 file_name=file_name)))
82 graph.resolved_types['struct_key'] = mojom_types_mojom.UserDefinedType( 83 graph.resolved_types['struct_key'] = mojom_types_mojom.UserDefinedType(
83 struct_type=mojom_struct) 84 struct_type=mojom_struct)
84 85
85 mojom_union = mojom_types_mojom.MojomUnion( 86 mojom_union = mojom_types_mojom.MojomUnion(
86 fields=[], 87 fields=[],
87 decl_data=mojom_types_mojom.DeclarationData( 88 decl_data=mojom_types_mojom.DeclarationData(
88 short_name='AUnion', 89 short_name='AUnion',
89 source_file_info=mojom_types_mojom.SourceFileInfo( 90 source_file_info=mojom_types_mojom.SourceFileInfo(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 mod.imports[0]['namespace']) 132 mod.imports[0]['namespace'])
132 self.assertEquals(imported_file.file_name, mod.imports[0]['module'].path) 133 self.assertEquals(imported_file.file_name, mod.imports[0]['module'].path)
133 134
134 self.assertEquals(2, len(mod.transitive_imports)) 135 self.assertEquals(2, len(mod.transitive_imports))
135 transitive_imports_paths = [imp['module'].path 136 transitive_imports_paths = [imp['module'].path
136 for imp in mod.transitive_imports] 137 for imp in mod.transitive_imports]
137 self.assertIn(imported_file_name, transitive_imports_paths) 138 self.assertIn(imported_file_name, transitive_imports_paths)
138 self.assertIn(second_level_imported_file_name, transitive_imports_paths) 139 self.assertIn(second_level_imported_file_name, transitive_imports_paths)
139 140
140 self.assertEquals(mojom_interface.interface_name, mod.interfaces[0].name) 141 self.assertEquals(mojom_interface.interface_name, mod.interfaces[0].name)
142 # Interfaces should be assigned their name as their spec.
143 self.assertEquals('AnInterface', mod.interfaces[0].spec)
141 self.assertEquals(mojom_struct.decl_data.short_name, mod.structs[0].name) 144 self.assertEquals(mojom_struct.decl_data.short_name, mod.structs[0].name)
145 # The struct was given a full_identifier so its spec should be that.
146 self.assertEquals(mojom_struct.decl_data.full_identifier,
147 mod.structs[0].spec)
142 self.assertEquals(mojom_union.decl_data.short_name, mod.unions[0].name) 148 self.assertEquals(mojom_union.decl_data.short_name, mod.unions[0].name)
149 # The union was given a short name but not a full_identifier so its spec
150 # should be the short name.
151 self.assertEquals(mojom_union.decl_data.short_name,
152 mod.unions[0].spec)
143 self.assertEquals(mojom_enum.decl_data.short_name, mod.enums[0].name) 153 self.assertEquals(mojom_enum.decl_data.short_name, mod.enums[0].name)
144 self.assertEquals(mojom_const.decl_data.short_name, mod.constants[0].name) 154 self.assertEquals(mojom_const.decl_data.short_name, mod.constants[0].name)
145 155
146 def test_no_imports(self): 156 def test_no_imports(self):
147 graph = mojom_files_mojom.MojomFileGraph( 157 graph = mojom_files_mojom.MojomFileGraph(
148 resolved_types={}) 158 resolved_types={})
149 file_name = 'root/f.mojom' 159 file_name = 'root/f.mojom'
150 mojom_file = mojom_files_mojom.MojomFile( 160 mojom_file = mojom_files_mojom.MojomFile(
151 file_name=file_name, 161 file_name=file_name,
152 module_namespace='somens') 162 module_namespace='somens')
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 result2 = t.KindFromMojom(mojom_type) 900 result2 = t.KindFromMojom(mojom_type)
891 self.assertIs(result, result2) 901 self.assertIs(result, result2)
892 902
893 # Nullable type reference 903 # Nullable type reference
894 mojom_type.type_reference.nullable = True 904 mojom_type.type_reference.nullable = True
895 nullable_result = t.KindFromMojom(mojom_type) 905 nullable_result = t.KindFromMojom(mojom_type)
896 self.assertTrue(module.IsNullableKind(nullable_result)) 906 self.assertTrue(module.IsNullableKind(nullable_result))
897 907
898 if __name__ == '__main__': 908 if __name__ == '__main__':
899 unittest.main() 909 unittest.main()
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698