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': ['name1', 'name2'], 'description': 'Enum description', | 80 expected = {'enum': [{'name': 'name1', 'description': 'comment1'}, |
| 81 {'name': 'name2'}], |
| 82 'description': 'Enum description', |
81 'type': 'string', 'id': 'EnumType'} | 83 'type': 'string', 'id': 'EnumType'} |
82 self.assertEquals(expected, getType(schema, expected['id'])) | 84 self.assertEquals(expected, getType(schema, expected['id'])) |
83 | 85 |
84 expected = [{'name':'type', '$ref':'EnumType'}, | 86 expected = [{'name':'type', '$ref':'EnumType'}, |
85 {'type':'function', 'name':'cb', | 87 {'type':'function', 'name':'cb', |
86 'parameters':[{'name':'type', '$ref':'EnumType'}]}] | 88 'parameters':[{'name':'type', '$ref':'EnumType'}]}] |
87 self.assertEquals(expected, getParams(schema, 'function13')) | 89 self.assertEquals(expected, getParams(schema, 'function13')) |
88 | 90 |
89 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types', | 91 expected = [{'items': {'$ref': 'EnumType'}, 'name': 'types', |
90 'type': 'array'}] | 92 'type': 'array'}] |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 func['parameters']) | 138 func['parameters']) |
137 func = getFunction(schema, 'function4') | 139 func = getFunction(schema, 'function4') |
138 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' | 140 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' |
139 '<br/><br/> It also tests a comment with two newlines.'), | 141 '<br/><br/> It also tests a comment with two newlines.'), |
140 func['description']) | 142 func['description']) |
141 | 143 |
142 def testReservedWords(self): | 144 def testReservedWords(self): |
143 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] | 145 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] |
144 | 146 |
145 foo_type = getType(schema, 'Foo') | 147 foo_type = getType(schema, 'Foo') |
146 self.assertEquals(['float', 'DOMString'], foo_type['enum']) | 148 self.assertEquals([{'name': 'float'}, {'name': 'DOMString'}], |
| 149 foo_type['enum']) |
147 | 150 |
148 enum_type = getType(schema, 'enum') | 151 enum_type = getType(schema, 'enum') |
149 self.assertEquals(['callback', 'namespace'], enum_type['enum']) | 152 self.assertEquals([{'name': 'callback'}, {'name': 'namespace'}], |
| 153 enum_type['enum']) |
150 | 154 |
151 dictionary = getType(schema, 'dictionary') | 155 dictionary = getType(schema, 'dictionary') |
152 self.assertEquals('integer', dictionary['properties']['long']['type']) | 156 self.assertEquals('integer', dictionary['properties']['long']['type']) |
153 | 157 |
154 mytype = getType(schema, 'MyType') | 158 mytype = getType(schema, 'MyType') |
155 self.assertEquals('string', mytype['properties']['interface']['type']) | 159 self.assertEquals('string', mytype['properties']['interface']['type']) |
156 | 160 |
157 params = getParams(schema, 'static') | 161 params = getParams(schema, 'static') |
158 self.assertEquals('Foo', params[0]['$ref']) | 162 self.assertEquals('Foo', params[0]['$ref']) |
159 self.assertEquals('enum', params[1]['$ref']) | 163 self.assertEquals('enum', params[1]['$ref']) |
160 | 164 |
161 | 165 |
162 if __name__ == '__main__': | 166 if __name__ == '__main__': |
163 unittest.main() | 167 unittest.main() |
OLD | NEW |