def test_context_with_api_usages(self): """Tests a context with some API usages is highlighted.""" context = """chrome.power.requestKeepAwake(); chrome.app.runtime.onLaunched.addListener(makeWindow); notAChromeAppCall();""" highlighted = report.highlight_relevant_line(context, 0, self.apis) self.assertEqual(highlighted, """<span class="ca-feature none">chrome.power.requestKeepAwake</span>(); chrome.app.runtime.onLaunched.addListener(makeWindow); notAChromeAppCall();""") highlighted = report.highlight_relevant_line(context, 1, self.apis) self.assertEqual(highlighted, """chrome.power.requestKeepAwake(); <span class="ca-feature none">chrome.app.runtime.onLaunched.addListener</span>\ (makeWindow);\nnotAChromeAppCall();""")
def test_context_with_no_api_usages(self): """Tests a context with no API usages is not highlighted.""" context = """// hello world javascript(); var fun = function() { anotherCall(); }""" highlighted = report.highlight_relevant_line(context, 2, self.apis) self.assertEqual(highlighted, context)
def test_context_with_api_usages(self): """Tests a context with some API usages is highlighted.""" context = """chrome.power.requestKeepAwake(); chrome.app.runtime.onLaunched.addListener(makeWindow); notAChromeAppCall();""" highlighted = report.highlight_relevant_line(context, 0, self.apis) self.assertEqual( highlighted, """<span class="ca-feature none">chrome.power.requestKeepAwake</span>(); chrome.app.runtime.onLaunched.addListener(makeWindow); notAChromeAppCall();""") highlighted = report.highlight_relevant_line(context, 1, self.apis) self.assertEqual( highlighted, """chrome.power.requestKeepAwake(); <span class="ca-feature none">chrome.app.runtime.onLaunched.addListener</span>\ (makeWindow);\nnotAChromeAppCall();""")
def test_empty_context(self): """Tests that highlighting an empty context returns the empty string.""" highlighted = report.highlight_relevant_line("", 0, self.apis) self.assertEqual(highlighted, '')