def test_no_todos(self): """Tests that if there are no TODOs to add, nothing is changed.""" js = """// héllo world unrelated.app.call();""" filename = 'test.js' filepath = os.path.join(self.temp_path, filename) with codecs.open(filepath, 'w', encoding='utf-8') as js_file: js_file.write(js) caterpillar.insert_todos_into_file(filepath) with codecs.open(filepath, encoding='utf-8') as js_file: self.assertEqual(js, js_file.read())
def test_deeper_todos(self): """Tests TODOs are inserted for deeper API calls. Deep API calls include members like chrome.storage.onChanged.addListener, and have more than two levels of membership.""" js = """// hello world chrome.storage.onChanged.addListener(function() {}); unrelated.app.call();""" filename = 'test.js' filepath = os.path.join(self.temp_path, filename) with codecs.open(filepath, 'w', encoding='utf-8') as js_file: js_file.write(js) caterpillar.insert_todos_into_file(filepath) with codecs.open(filepath, encoding='utf-8') as js_file: js = js_file.read() self.assertEqual(js, """// hello world // TODO(Caterpillar): Check usage of storage.onChanged.addListener. chrome.storage.onChanged.addListener(function() {}); unrelated.app.call();""")
def test_top_level_todos(self): """Tests TODOs are inserted for top-level API calls like chrome.tts.speak. """ js = """// héllo world chrome.tts.speak('héllø'); chrome.unrelated.call(); unrelated.app.call();""" filename = 'test.js' filepath = os.path.join(self.temp_path, filename) with codecs.open(filepath, 'w', encoding='utf-8') as js_file: js_file.write(js) caterpillar.insert_todos_into_file(filepath) with codecs.open(filepath, encoding='utf-8') as js_file: js = js_file.read() self.assertEqual(js, """// héllo world // TODO(Caterpillar): Check usage of tts.speak. chrome.tts.speak('héllø'); // TODO(Caterpillar): Check usage of unrelated.call. chrome.unrelated.call(); unrelated.app.call();""")
def test_deeper_todos(self): """Tests TODOs are inserted for deeper API calls. Deep API calls include members like chrome.storage.onChanged.addListener, and have more than two levels of membership.""" js = """// hello world chrome.storage.onChanged.addListener(function() {}); unrelated.app.call();""" filename = 'test.js' filepath = os.path.join(self.temp_path, filename) with codecs.open(filepath, 'w', encoding='utf-8') as js_file: js_file.write(js) caterpillar.insert_todos_into_file(filepath) with codecs.open(filepath, encoding='utf-8') as js_file: js = js_file.read() self.assertEqual( js, """// hello world // TODO(Caterpillar): Check usage of storage.onChanged.addListener. chrome.storage.onChanged.addListener(function() {}); unrelated.app.call();""")
def test_top_level_todos(self): """Tests TODOs are inserted for top-level API calls like chrome.tts.speak. """ js = """// héllo world chrome.tts.speak('héllø'); chrome.unrelated.call(); unrelated.app.call();""" filename = 'test.js' filepath = os.path.join(self.temp_path, filename) with codecs.open(filepath, 'w', encoding='utf-8') as js_file: js_file.write(js) caterpillar.insert_todos_into_file(filepath) with codecs.open(filepath, encoding='utf-8') as js_file: js = js_file.read() self.assertEqual( js, """// héllo world // TODO(Caterpillar): Check usage of tts.speak. chrome.tts.speak('héllø'); // TODO(Caterpillar): Check usage of unrelated.call. chrome.unrelated.call(); unrelated.app.call();""")