Coverage for phml\nodes\point.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-08 16:33 -0600

1from typing import Optional 

2 

3 

4class Point: 

5 """Represents one place in a source file. 

6 

7 The line field (1-indexed integer) represents a line in a source file. The column field 

8 (1-indexed integer) represents a column in a source file. The offset field (0-indexed integer) 

9 represents a character in a source file. 

10 """ 

11 

12 def __init__(self, line: int, column: int, offset: Optional[int] = None): 

13 if line < 0: 

14 raise IndexError(f"Point.line must be >= 0 but was {line}") 

15 

16 self.line = line 

17 

18 if column < 0: 

19 raise IndexError(f"Point.column must be >= 0 but was {column}") 

20 

21 self.column = column 

22 

23 if offset is not None and offset < 0: 

24 raise IndexError(f"Point.offset must be >= 0 or None but was {line}") 

25 

26 self.offset = offset 

27 

28 def __eq__(self, obj) -> bool: 

29 return bool( 

30 obj is not None 

31 and isinstance(obj, self.__class__) 

32 and self.line == obj.line 

33 and self.column == obj.column 

34 ) 

35 

36 def __repr__(self) -> str: 

37 return f"point(line: {self.line}, column: {self.column}, offset: {self.offset})" 

38 

39 def __str__(self) -> str: 

40 return f"{self.line}:{self.column}"