OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import idl_schema | 6 import idl_schema |
7 import unittest | 7 import unittest |
8 | 8 |
9 def getFunction(schema, name): | 9 def getFunction(schema, name): |
10 for item in schema['functions']: | 10 for item in schema['functions']: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 'c': {'name': 'c', 'type': 'string'}}, | 70 'c': {'name': 'c', 'type': 'string'}}, |
71 getType(self.idl_basics, 'MyType1')['properties']) | 71 getType(self.idl_basics, 'MyType1')['properties']) |
72 | 72 |
73 def testMemberOrdering(self): | 73 def testMemberOrdering(self): |
74 self.assertEquals( | 74 self.assertEquals( |
75 ['x', 'y', 'z', 'a', 'b', 'c'], | 75 ['x', 'y', 'z', 'a', 'b', 'c'], |
76 getType(self.idl_basics, 'MyType1')['properties'].keys()) | 76 getType(self.idl_basics, 'MyType1')['properties'].keys()) |
77 | 77 |
78 def testEnum(self): | 78 def testEnum(self): |
79 schema = self.idl_basics | 79 schema = self.idl_basics |
80 expected = {'enum': [{'name': 'name1', 'description': 'comment1'}, | 80 expected = {'enum': ['name1', 'name2'], 'description': 'Enum description', |
81 {'name': 'name2'}], | |
82 'description': 'Enum description', | |
83 'type': 'string', 'id': 'EnumType'} | 81 'type': 'string', 'id': 'EnumType'} |
84 self.assertEquals(expected, getType(schema, expected['id'])) | 82 self.assertEquals(expected, getType(schema, expected['id'])) |
85 | 83 |
86 expected = [{'name':'type', '$ref':'EnumType'}, | 84 expected = [{'name':'type', '$ref':'EnumType'}, |
87 {'type':'function', 'name':'cb', | 85 {'type':'function', 'name':'cb', |
88 'parameters':[{'name':'type', '$ref':'EnumType'}]}] | 86 'parameters':[{'name':'type', '$ref':'EnumType'}]}] |
89 self.assertEquals(expected, getParams(schema, 'function13')) | 87 self.assertEquals(expected, getParams(schema, 'function13')) |
90 | 88 |
91 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types', | 89 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types', |
92 'type': 'array'}] | 90 'type': 'array'}] |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 func['parameters']) | 155 func['parameters']) |
158 func = getFunction(schema, 'function4') | 156 func = getFunction(schema, 'function4') |
159 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' | 157 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' |
160 '<br/><br/> It also tests a comment with two newlines.'), | 158 '<br/><br/> It also tests a comment with two newlines.'), |
161 func['description']) | 159 func['description']) |
162 | 160 |
163 def testReservedWords(self): | 161 def testReservedWords(self): |
164 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] | 162 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] |
165 | 163 |
166 foo_type = getType(schema, 'Foo') | 164 foo_type = getType(schema, 'Foo') |
167 self.assertEquals([{'name': 'float'}, {'name': 'DOMString'}], | 165 self.assertEquals(['float', 'DOMString'], foo_type['enum']) |
168 foo_type['enum']) | |
169 | 166 |
170 enum_type = getType(schema, 'enum') | 167 enum_type = getType(schema, 'enum') |
171 self.assertEquals([{'name': 'callback'}, {'name': 'namespace'}], | 168 self.assertEquals(['callback', 'namespace'], enum_type['enum']) |
172 enum_type['enum']) | |
173 | 169 |
174 dictionary = getType(schema, 'dictionary') | 170 dictionary = getType(schema, 'dictionary') |
175 self.assertEquals('integer', dictionary['properties']['long']['type']) | 171 self.assertEquals('integer', dictionary['properties']['long']['type']) |
176 | 172 |
177 mytype = getType(schema, 'MyType') | 173 mytype = getType(schema, 'MyType') |
178 self.assertEquals('string', mytype['properties']['interface']['type']) | 174 self.assertEquals('string', mytype['properties']['interface']['type']) |
179 | 175 |
180 params = getParams(schema, 'static') | 176 params = getParams(schema, 'static') |
181 self.assertEquals('Foo', params[0]['$ref']) | 177 self.assertEquals('Foo', params[0]['$ref']) |
182 self.assertEquals('enum', params[1]['$ref']) | 178 self.assertEquals('enum', params[1]['$ref']) |
183 | 179 |
184 | 180 |
185 if __name__ == '__main__': | 181 if __name__ == '__main__': |
186 unittest.main() | 182 unittest.main() |
OLD | NEW |