| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 unittest | 6 import unittest |
| 7 | 7 |
| 8 import extract_actions | 8 import extract_actions |
| 9 | 9 |
| 10 # Empty value to be inserted to |ACTIONS_MOCK|. | 10 # Empty value to be inserted to |ACTIONS_MOCK|. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 def testAddNewActions(self): | 187 def testAddNewActions(self): |
| 188 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, | 188 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, |
| 189 new_actions=['action2']) | 189 new_actions=['action2']) |
| 190 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result) | 190 self.assertEqual(ADD_ACTION_EXPECTED_XML, xml_result) |
| 191 | 191 |
| 192 def testComment(self): | 192 def testComment(self): |
| 193 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, | 193 xml_result = self._GetProcessedAction(TWO_OWNERS, DESCRIPTION, NO_VALUE, |
| 194 comment=COMMENT) | 194 comment=COMMENT) |
| 195 self.assertEqual(COMMENT_EXPECTED_XML, xml_result) | 195 self.assertEqual(COMMENT_EXPECTED_XML, xml_result) |
| 196 | 196 |
| 197 def testUserMetricsActionSpanningTwoLines(self): |
| 198 code = 'base::UserMetricsAction(\n"Foo.Bar"));' |
| 199 finder = extract_actions.ActionNameFinder('dummy', code) |
| 200 self.assertEqual('Foo.Bar', finder.FindNextAction()) |
| 201 self.assertFalse(finder.FindNextAction()) |
| 202 |
| 203 def testUserMetricsActionAsAParam(self): |
| 204 code = 'base::UserMetricsAction("Test.Foo"), "Test.Bar");' |
| 205 finder = extract_actions.ActionNameFinder('dummy', code) |
| 206 self.assertEqual('Test.Foo', finder.FindNextAction()) |
| 207 self.assertFalse(finder.FindNextAction()) |
| 208 |
| 209 def testNonLiteralUserMetricsAction(self): |
| 210 code = 'base::UserMetricsAction(FOO)' |
| 211 finder = extract_actions.ActionNameFinder('dummy', code) |
| 212 with self.assertRaises(Exception): |
| 213 finder.FindNextAction() |
| 214 |
| 215 def testTernaryUserMetricsAction(self): |
| 216 code = 'base::UserMetricsAction(foo ? "Foo.Bar" : "Bar.Foo"));' |
| 217 finder = extract_actions.ActionNameFinder('dummy', code) |
| 218 with self.assertRaises(Exception): |
| 219 finder.FindNextAction() |
| 220 |
| 221 def testTernaryUserMetricsActionWithNewLines(self): |
| 222 code = """base::UserMetricsAction( |
| 223 foo_bar ? "Bar.Foo" : |
| 224 "Foo.Car")""" |
| 225 finder = extract_actions.ActionNameFinder('dummy', code) |
| 226 with self.assertRaises(extract_actions.InvalidStatementException): |
| 227 finder.FindNextAction() |
| 228 |
| 197 | 229 |
| 198 if __name__ == '__main__': | 230 if __name__ == '__main__': |
| 199 unittest.main() | 231 unittest.main() |
| OLD | NEW |