def expand(self, file_contents): """ Passes a new SourceRange that covers the same area of a file as this one would. All values of None get replaced with absolute values. values of None will be interpreted as follows: self.start.line is None: -> 1 self.start.column is None: -> 1 self.end.line is None: -> last line of file self.end.column is None: -> last column of self.end.line :param file_contents: File contents of the applicable file :return: TextRange with absolute values """ tr = TextRange.expand(self, file_contents) return SourceRange.from_values(self.file, tr.start.line, tr.start.column, tr.end.line, tr.end.column)
def test_expand_none(self): start_position = TextPosition(2, 2) end_position = TextPosition(3, 2) file = ["abc\n", "def\n", "ghi\n"] text_range = TextRange(start_position, end_position) self.assertEqual(text_range.expand(file), text_range)
def test_expand_full(self): empty_position = TextPosition() file = ["abc\n", "def\n", "ghi\n"] empty_range = TextRange(empty_position, empty_position) full_range = TextRange.from_values(1, 1, 3, 4) self.assertEqual(empty_range.expand(file), full_range)