| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 func['parameters']) | 157 func['parameters']) |
| 156 func = getFunction(schema, 'function4') | 158 func = getFunction(schema, 'function4') |
| 157 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' | 159 self.assertEquals(('This tests if "double-quotes" are escaped correctly.' |
| 158 '<br/><br/> It also tests a comment with two newlines.'), | 160 '<br/><br/> It also tests a comment with two newlines.'), |
| 159 func['description']) | 161 func['description']) |
| 160 | 162 |
| 161 def testReservedWords(self): | 163 def testReservedWords(self): |
| 162 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] | 164 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] |
| 163 | 165 |
| 164 foo_type = getType(schema, 'Foo') | 166 foo_type = getType(schema, 'Foo') |
| 165 self.assertEquals(['float', 'DOMString'], foo_type['enum']) | 167 self.assertEquals([{'name': 'float'}, {'name': 'DOMString'}], |
| 168 foo_type['enum']) |
| 166 | 169 |
| 167 enum_type = getType(schema, 'enum') | 170 enum_type = getType(schema, 'enum') |
| 168 self.assertEquals(['callback', 'namespace'], enum_type['enum']) | 171 self.assertEquals([{'name': 'callback'}, {'name': 'namespace'}], |
| 172 enum_type['enum']) |
| 169 | 173 |
| 170 dictionary = getType(schema, 'dictionary') | 174 dictionary = getType(schema, 'dictionary') |
| 171 self.assertEquals('integer', dictionary['properties']['long']['type']) | 175 self.assertEquals('integer', dictionary['properties']['long']['type']) |
| 172 | 176 |
| 173 mytype = getType(schema, 'MyType') | 177 mytype = getType(schema, 'MyType') |
| 174 self.assertEquals('string', mytype['properties']['interface']['type']) | 178 self.assertEquals('string', mytype['properties']['interface']['type']) |
| 175 | 179 |
| 176 params = getParams(schema, 'static') | 180 params = getParams(schema, 'static') |
| 177 self.assertEquals('Foo', params[0]['$ref']) | 181 self.assertEquals('Foo', params[0]['$ref']) |
| 178 self.assertEquals('enum', params[1]['$ref']) | 182 self.assertEquals('enum', params[1]['$ref']) |
| 179 | 183 |
| 180 | 184 |
| 181 if __name__ == '__main__': | 185 if __name__ == '__main__': |
| 182 unittest.main() | 186 unittest.main() |
| OLD | NEW |