@@ -7,7 +7,7 @@ class CommentsTest < TestCase
7
7
def test_comment_inline
8
8
source = "# comment"
9
9
10
- assert_comment source , :inline , 0 .. 9
10
+ assert_comment source , :inline , [ 0 , 9 , 1 , 1 , 0 , 9 ]
11
11
assert_equal [ 0 ] , Debug . newlines ( source )
12
12
end
13
13
@@ -18,7 +18,7 @@ def foo
18
18
end
19
19
RUBY
20
20
21
- assert_comment source , :inline , 10 .. 22
21
+ assert_comment source , :inline , [ 10 , 21 , 2 , 2 , 2 , 13 ]
22
22
end
23
23
24
24
def test_comment___END__
@@ -27,13 +27,13 @@ def test_comment___END__
27
27
comment
28
28
RUBY
29
29
30
- assert_comment source , :__END__ , 0 .. 16
30
+ assert_comment source , :__END__ , [ 0 , 16 , 1 , 2 , 0 , 0 ]
31
31
end
32
32
33
33
def test_comment___END__crlf
34
34
source = "__END__\r \n comment\r \n "
35
35
36
- assert_comment source , :__END__ , 0 .. 18
36
+ assert_comment source , :__END__ , [ 0 , 18 , 1 , 2 , 0 , 0 ]
37
37
end
38
38
39
39
def test_comment_embedded_document
@@ -43,7 +43,7 @@ def test_comment_embedded_document
43
43
=end
44
44
RUBY
45
45
46
- assert_comment source , :embdoc , 0 .. 20
46
+ assert_comment source , :embdoc , [ 0 , 20 , 1 , 3 , 0 , 0 ]
47
47
end
48
48
49
49
def test_comment_embedded_document_with_content_on_same_line
@@ -52,7 +52,7 @@ def test_comment_embedded_document_with_content_on_same_line
52
52
=end
53
53
RUBY
54
54
55
- assert_comment source , :embdoc , 0 .. 24
55
+ assert_comment source , :embdoc , [ 0 , 24 , 1 , 2 , 0 , 0 ]
56
56
end
57
57
58
58
def test_attaching_comments
@@ -74,19 +74,40 @@ def bar
74
74
method_node = class_node . body . body . first
75
75
call_node = method_node . body . body . first
76
76
77
- assert_equal ( "# Foo class\n # Foo end\n " , class_node . location . comments . map { |c | c . location . slice } . join )
78
- assert_equal ( "# bar method\n # bar end\n " , method_node . location . comments . map { |c | c . location . slice } . join )
79
- assert_equal ( "# baz invocation\n " , call_node . location . comments . map { |c | c . location . slice } . join )
77
+ assert_equal ( "# Foo class\n # Foo end" , class_node . location . comments . map { |c | c . location . slice } . join ( " \n " ) )
78
+ assert_equal ( "# bar method\n # bar end" , method_node . location . comments . map { |c | c . location . slice } . join ( " \n " ) )
79
+ assert_equal ( "# baz invocation" , call_node . location . comments . map { |c | c . location . slice } . join ( " \n " ) )
80
80
end
81
81
82
82
private
83
83
84
- def assert_comment ( source , type , location )
84
+ def assert_comment ( source , type , locations )
85
+ start_offset , end_offset , start_line , end_line , start_column , end_column = locations
86
+ expected = {
87
+ start_offset : start_offset ,
88
+ end_offset : end_offset ,
89
+ start_line : start_line ,
90
+ end_line : end_line ,
91
+ start_column : start_column ,
92
+ end_column : end_column
93
+ }
94
+
85
95
result = YARP . parse ( source )
86
96
assert result . errors . empty? , result . errors . map ( &:message ) . join ( "\n " )
87
- assert_equal result . comments . first . type , type
88
- assert_equal result . comments . first . location . start_offset , location . begin
89
- assert_equal result . comments . first . location . end_offset , location . end
97
+ assert_equal type , result . comments . first . type
98
+
99
+ first_comment_location = result . comments . first . location
100
+
101
+ actual = {
102
+ start_offset : first_comment_location . start_offset ,
103
+ end_offset : first_comment_location . end_offset ,
104
+ start_line : first_comment_location . start_line ,
105
+ end_line : first_comment_location . end_line ,
106
+ start_column : first_comment_location . start_column ,
107
+ end_column : first_comment_location . end_column
108
+ }
109
+
110
+ assert_equal expected , actual
90
111
end
91
112
end
92
113
end
0 commit comments