Exemple #1
0
    def __str__(self) -> str:
        output = '{} at {}'.format(self.__message, self.__span)
        if self.__span is None:
            return output

        lines = highlight(self.__span)
        return '{}\n{}'.format(output, lines)
Exemple #2
0
    def test_highlight_partial_three_lines(self):
        source = 'hello\ngreen\nworld'
        span = SourceSpan(source, Position(0, 1, 3),
                          Position(len(source) - 3, 3, 4))

        result = highlight(span)

        assert result == '1. hello\n     ~~~\n2. green\n   ~~~~~\n3. world\n   ~~~'
Exemple #3
0
    def test_highlight_two_lines(self):
        source = 'hello\nworld'
        span = SourceSpan(source, Position.initial(),
                          Position(len(source) - 1, 2, 6))

        result = highlight(span)

        assert result == '1. hello\n   ~~~~~\n2. world\n   ~~~~~'
Exemple #4
0
    def test_highlight_single_line(self):
        source = 'hello world'
        span = SourceSpan(source, Position.initial(),
                          Position(len(source) - 1, 1,
                                   len(source) + 1))

        result = highlight(span)

        assert result == '1. hello world\n   ~~~~~~~~~~~'
Exemple #5
0
    def test_highlight_partial_single_line(self):
        source = 'hello world'
        span = SourceSpan(source, Position(0, 1, 4),
                          Position(len(source) - 3, 1,
                                   len(source) - 1))

        result = highlight(span)

        assert result == '1. hello world\n      ~~~~~~'
Exemple #6
0
 def __str__(self) -> str:
     return '{} (expected {} but got {} at {})\n{}'.format(self.__message, self.__expected_type, self.token.type, self.token.span, highlight(self.token.span))
Exemple #7
0
 def __str__(self) -> str:
     return '{} ({} at {})\n{}'.format(self.__message, self.__token.type, self.token.span, highlight(self.token.span))