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

Side by Side Diff: tools/json_schema_compiler/schema_util_test.py

Issue 11827026: Overhaul JSON Schema Compiler to support a number of features required to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 months 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 | Annotate | Revision Log
OLDNEW
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 from schema_util import JsFunctionNameToClassName 6 from schema_util import JsFunctionNameToClassName
7 from schema_util import PrefixSchemasWithNamespace
8 from schema_util import StripSchemaNamespace 7 from schema_util import StripSchemaNamespace
9 import unittest 8 import unittest
10 9
11 class SchemaUtilTest(unittest.TestCase): 10 class SchemaUtilTest(unittest.TestCase):
12 def testStripSchemaNamespace(self): 11 def testStripSchemaNamespace(self):
13 self.assertEquals('Bar', StripSchemaNamespace('foo.Bar')) 12 self.assertEquals('Bar', StripSchemaNamespace('foo.Bar'))
14 self.assertEquals('Baz', StripSchemaNamespace('Baz')) 13 self.assertEquals('Baz', StripSchemaNamespace('Baz'))
15 14
16 def testPrefixSchemasWithNamespace(self):
17 schemas = [
18 { 'namespace': 'n1',
19 'types': [
20 {
21 'id': 'T1',
22 'customBindings': 'T1',
23 'properties': {
24 'p1': {'$ref': 'T1'},
25 'p2': {'$ref': 'fully.qualified.T'},
26 }
27 }
28 ],
29 'functions': [
30 {
31 'parameters': [
32 { '$ref': 'T1' },
33 { '$ref': 'fully.qualified.T' },
34 ],
35 'returns': { '$ref': 'T1' }
36 },
37 ],
38 'events': [
39 {
40 'parameters': [
41 { '$ref': 'T1' },
42 { '$ref': 'fully.qualified.T' },
43 ],
44 },
45 ],
46 },
47 ]
48 PrefixSchemasWithNamespace(schemas)
49 self.assertEquals('n1.T1', schemas[0]['types'][0]['id'])
50 self.assertEquals('n1.T1', schemas[0]['types'][0]['customBindings'])
51 self.assertEquals('n1.T1',
52 schemas[0]['types'][0]['properties']['p1']['$ref'])
53 self.assertEquals('fully.qualified.T',
54 schemas[0]['types'][0]['properties']['p2']['$ref'])
55
56 self.assertEquals('n1.T1',
57 schemas[0]['functions'][0]['parameters'][0]['$ref'])
58 self.assertEquals('fully.qualified.T',
59 schemas[0]['functions'][0]['parameters'][1]['$ref'])
60 self.assertEquals('n1.T1',
61 schemas[0]['functions'][0]['returns']['$ref'])
62
63 self.assertEquals('n1.T1',
64 schemas[0]['events'][0]['parameters'][0]['$ref'])
65 self.assertEquals('fully.qualified.T',
66 schemas[0]['events'][0]['parameters'][1]['$ref'])
67
68
69 def testJsFunctionNameToClassName(self): 15 def testJsFunctionNameToClassName(self):
70 self.assertEquals('FooBar', JsFunctionNameToClassName('foo', 'bar')) 16 self.assertEquals('FooBar', JsFunctionNameToClassName('foo', 'bar'))
71 self.assertEquals('FooBar', 17 self.assertEquals('FooBar',
72 JsFunctionNameToClassName('experimental.foo', 'bar')) 18 JsFunctionNameToClassName('experimental.foo', 'bar'))
73 self.assertEquals('FooBarBaz', 19 self.assertEquals('FooBarBaz',
74 JsFunctionNameToClassName('foo.bar', 'baz')) 20 JsFunctionNameToClassName('foo.bar', 'baz'))
75 self.assertEquals('FooBarBaz', 21 self.assertEquals('FooBarBaz',
76 JsFunctionNameToClassName('experimental.foo.bar', 'baz')) 22 JsFunctionNameToClassName('experimental.foo.bar', 'baz'))
77 23
78 if __name__ == '__main__': 24 if __name__ == '__main__':
79 unittest.main() 25 unittest.main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/schema_util.py ('k') | tools/json_schema_compiler/test/additional_properties.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698