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 json | 6 import json |
7 import os | 7 import os |
8 import unittest | 8 import unittest |
9 | 9 |
| 10 from docs_server_utils import GetLinkToRefType |
10 from handlebar_dict_generator import HandlebarDictGenerator | 11 from handlebar_dict_generator import HandlebarDictGenerator |
11 from handlebar_dict_generator import _GetLinkToRefType | |
12 from handlebar_dict_generator import _FormatValue | 12 from handlebar_dict_generator import _FormatValue |
13 import third_party.json_schema_compiler.json_comment_eater as comment_eater | 13 import third_party.json_schema_compiler.json_comment_eater as comment_eater |
14 import third_party.json_schema_compiler.model as model | 14 import third_party.json_schema_compiler.model as model |
15 | 15 |
16 def _MakeLink(href, text): | 16 def _MakeLink(href, text): |
17 return '<a href="%s">%s</a>' % (href, text) | 17 return '<a href="%s">%s</a>' % (href, text) |
18 | 18 |
19 def _GetType(dict_, name): | 19 def _GetType(dict_, name): |
20 for type_ in dict_['types']: | 20 for type_ in dict_['types']: |
21 if type_['name'] == name: | 21 if type_['name'] == name: |
(...skipping 12 matching lines...) Expand all Loading... |
34 | 34 |
35 def _GenerateTest(self, filename): | 35 def _GenerateTest(self, filename): |
36 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) | 36 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) |
37 gen = HandlebarDictGenerator(self._LoadJSON(filename)) | 37 gen = HandlebarDictGenerator(self._LoadJSON(filename)) |
38 self.assertEquals(expected_json, gen.Generate()) | 38 self.assertEquals(expected_json, gen.Generate()) |
39 | 39 |
40 def testGenerate(self): | 40 def testGenerate(self): |
41 self._GenerateTest('test_file.json') | 41 self._GenerateTest('test_file.json') |
42 | 42 |
43 def testGetLinkToRefType(self): | 43 def testGetLinkToRefType(self): |
44 link = _GetLinkToRefType('truthTeller', 'liar.Tab') | 44 link = GetLinkToRefType('truthTeller', 'liar.Tab') |
45 self.assertEquals('liar.html#type-Tab', link['href']) | 45 self.assertEquals('liar.html#type-Tab', link['href']) |
46 self.assertEquals('liar.Tab', link['text']) | 46 self.assertEquals('liar.Tab', link['text']) |
47 link = _GetLinkToRefType('truthTeller', 'Tab') | 47 link = GetLinkToRefType('truthTeller', 'Tab') |
48 self.assertEquals('#type-Tab', link['href']) | 48 self.assertEquals('#type-Tab', link['href']) |
49 self.assertEquals('Tab', link['text']) | 49 self.assertEquals('Tab', link['text']) |
50 link = _GetLinkToRefType('nay', 'lies.chrome.bookmarks.Tab') | 50 link = GetLinkToRefType('nay', 'lies.chrome.bookmarks.Tab') |
51 self.assertEquals('lies.chrome.bookmarks.html#type-Tab', link['href']) | 51 self.assertEquals('lies.chrome.bookmarks.html#type-Tab', link['href']) |
52 self.assertEquals('lies.chrome.bookmarks.Tab', link['text']) | 52 self.assertEquals('lies.chrome.bookmarks.Tab', link['text']) |
53 | 53 |
54 def testFormatValue(self): | 54 def testFormatValue(self): |
55 self.assertEquals('1,234,567', _FormatValue(1234567)) | 55 self.assertEquals('1,234,567', _FormatValue(1234567)) |
56 self.assertEquals('67', _FormatValue(67)) | 56 self.assertEquals('67', _FormatValue(67)) |
57 self.assertEquals('234,567', _FormatValue(234567)) | 57 self.assertEquals('234,567', _FormatValue(234567)) |
58 | 58 |
59 def testFormatDescription(self): | 59 def testFormatDescription(self): |
60 dict_ = HandlebarDictGenerator(self._LoadJSON('ref_test.json')).Generate() | 60 dict_ = HandlebarDictGenerator(self._LoadJSON('ref_test.json')).Generate() |
61 self.assertEquals(_MakeLink('#type-type2', 'type2'), | 61 self.assertEquals(_MakeLink('#type-type2', 'type2'), |
62 _GetType(dict_, 'type1')['description']) | 62 _GetType(dict_, 'type1')['description']) |
63 self.assertEquals( | 63 self.assertEquals( |
64 'A %s, or %s' % (_MakeLink('#type-type3', 'type3'), | 64 'A %s, or %s' % (_MakeLink('#type-type3', 'type3'), |
65 _MakeLink('#type-type2', 'type2')), | 65 _MakeLink('#type-type2', 'type2')), |
66 _GetType(dict_, 'type2')['description']) | 66 _GetType(dict_, 'type2')['description']) |
67 self.assertEquals( | 67 self.assertEquals( |
68 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), | 68 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), |
69 _MakeLink('#type-type2', 'type2')), | 69 _MakeLink('#type-type2', 'type2')), |
70 _GetType(dict_, 'type3')['description']) | 70 _GetType(dict_, 'type3')['description']) |
71 | 71 |
72 if __name__ == '__main__': | 72 if __name__ == '__main__': |
73 unittest.main() | 73 unittest.main() |
OLD | NEW |