1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# frozen_string_literal: true
require_relative "test_helper"
return if Prism::BACKEND == :FFI
module Prism
class FormatErrorsTest < TestCase
def test_basic
expected = <<~ERROR
> 1 | <>
| ^ unexpected '<', ignoring it
| ^ unexpected '>', ignoring it
ERROR
assert_equal expected, Debug.format_errors("<>", false)
end
def test_multiple
expected = <<~ERROR
> 1 | "%W"\\u"
| ^ unexpected backslash, ignoring it
| ^ unexpected local variable or method, expecting end-of-input
| ^ unterminated string meets end of file
ERROR
assert_equal expected, Debug.format_errors('"%W"\u"', false)
end
def test_truncate_start
expected = <<~ERROR
> 1 | ... <>
| ^ unexpected '<', ignoring it
| ^ unexpected '>', ignoring it
ERROR
assert_equal expected, Debug.format_errors("#{" " * 30}<>", false)
end
def test_truncate_end
expected = <<~ERROR
> 1 | <#{" " * 30} ...
| ^ unexpected '<', ignoring it
ERROR
assert_equal expected, Debug.format_errors("<#{" " * 30}a", false)
end
def test_truncate_both
expected = <<~ERROR
> 1 | ... <#{" " * 30} ...
| ^ unexpected '<', ignoring it
ERROR
assert_equal expected, Debug.format_errors("#{" " * 30}<#{" " * 30}a", false)
end
end
end
|