| Index: chrome/common/extensions/docs/server2/handlebar_dict_generator_test.py
|
| diff --git a/chrome/common/extensions/docs/server2/handlebar_dict_generator_test.py b/chrome/common/extensions/docs/server2/handlebar_dict_generator_test.py
|
| index db7fba46c39fd81e3e04d7a10e356142f626d2c4..594dc9020952c372d7c0dba347b240d3956e1a55 100755
|
| --- a/chrome/common/extensions/docs/server2/handlebar_dict_generator_test.py
|
| +++ b/chrome/common/extensions/docs/server2/handlebar_dict_generator_test.py
|
| @@ -13,6 +13,14 @@ from handlebar_dict_generator import _FormatValue
|
| import third_party.json_schema_compiler.json_comment_eater as comment_eater
|
| import third_party.json_schema_compiler.model as model
|
|
|
| +def _MakeLink(href, text):
|
| + return '<a href="%s">%s</a>' % (href, text)
|
| +
|
| +def _GetType(dict_, name):
|
| + for type_ in dict_['types']:
|
| + if type_['name'] == name:
|
| + return type_
|
| +
|
| class DictGeneratorTest(unittest.TestCase):
|
| def setUp(self):
|
| self._base_path = os.path.join('test_data', 'test_json')
|
| @@ -21,10 +29,12 @@ class DictGeneratorTest(unittest.TestCase):
|
| with open(os.path.join(self._base_path, filename), 'r') as f:
|
| return f.read()
|
|
|
| + def _LoadJSON(self, filename):
|
| + return json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0]
|
| +
|
| def _GenerateTest(self, filename):
|
| expected_json = json.loads(self._ReadLocalFile('expected_' + filename))
|
| - gen = HandlebarDictGenerator(
|
| - json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0])
|
| + gen = HandlebarDictGenerator(self._LoadJSON(filename))
|
| self.assertEquals(expected_json, gen.Generate())
|
|
|
| def testGenerate(self):
|
| @@ -32,19 +42,32 @@ class DictGeneratorTest(unittest.TestCase):
|
|
|
| def testGetLinkToRefType(self):
|
| link = _GetLinkToRefType('truthTeller', 'liar.Tab')
|
| - self.assertEquals(link['href'], 'liar.html#type-Tab')
|
| - self.assertEquals(link['text'], 'Tab')
|
| + self.assertEquals('liar.html#type-Tab', link['href'])
|
| + self.assertEquals('liar.Tab', link['text'])
|
| link = _GetLinkToRefType('truthTeller', 'Tab')
|
| - self.assertEquals(link['href'], 'truthTeller.html#type-Tab')
|
| - self.assertEquals(link['text'], 'Tab')
|
| + self.assertEquals('#type-Tab', link['href'])
|
| + self.assertEquals('Tab', link['text'])
|
| link = _GetLinkToRefType('nay', 'lies.chrome.bookmarks.Tab')
|
| - self.assertEquals(link['href'], 'lies.html#type-chrome.bookmarks.Tab')
|
| - self.assertEquals(link['text'], 'chrome.bookmarks.Tab')
|
| + self.assertEquals('lies.chrome.bookmarks.html#type-Tab', link['href'])
|
| + self.assertEquals('lies.chrome.bookmarks.Tab', link['text'])
|
|
|
| def testFormatValue(self):
|
| self.assertEquals('1,234,567', _FormatValue(1234567))
|
| self.assertEquals('67', _FormatValue(67))
|
| self.assertEquals('234,567', _FormatValue(234567))
|
|
|
| + def testFormatDescription(self):
|
| + dict_ = HandlebarDictGenerator(self._LoadJSON('ref_test.json')).Generate()
|
| + self.assertEquals(_MakeLink('#type-type2', 'type2'),
|
| + _GetType(dict_, 'type1')['description'])
|
| + self.assertEquals(
|
| + 'A %s, or %s' % (_MakeLink('#type-type3', 'type3'),
|
| + _MakeLink('#type-type2', 'type2')),
|
| + _GetType(dict_, 'type2')['description'])
|
| + self.assertEquals(
|
| + '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
|
| + _MakeLink('#type-type2', 'type2')),
|
| + _GetType(dict_, 'type3')['description'])
|
| +
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|