test_util.py 632 B

123456789101112131415
  1. # Copyright 2015 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. def GetHighlight(line, error):
  5. """Returns the substring of |line| that is highlighted in |error|."""
  6. error_lines = error.split('\n')
  7. # TODO(dschuyler): Splitting the error on \n will prevent index(line)
  8. # from finding the line. As a workaround, return the whole, unfiltered
  9. # line.
  10. if line not in error_lines:
  11. return line
  12. highlight = error_lines[error_lines.index(line) + 1]
  13. return ''.join(ch1 for (ch1, ch2) in zip(line, highlight) if ch2 == '^')