parser 2.0.0.beta5 → 2.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +3 -4
- data/doc/AST_FORMAT.md +37 -8
- data/lib/parser/ast/processor.rb +20 -68
- data/lib/parser/builders/default.rb +71 -25
- data/lib/parser/lexer.rl +4 -4
- data/lib/parser/ruby18.y +8 -5
- data/lib/parser/ruby19.y +11 -8
- data/lib/parser/ruby20.y +11 -8
- data/lib/parser/ruby21.y +11 -8
- data/lib/parser/runner/ruby_parse.rb +5 -9
- data/lib/parser/source/comment/associator.rb +2 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -1
- data/test/test_lexer.rb +8 -0
- data/test/test_parser.rb +204 -92
- data/test/test_source_comment_associator.rb +23 -5
- metadata +4 -4
@@ -2,11 +2,20 @@ require 'helper'
|
|
2
2
|
require 'parser/ruby18'
|
3
3
|
|
4
4
|
class TestSourceCommentAssociator < Minitest::Test
|
5
|
-
def
|
5
|
+
def associate(code)
|
6
6
|
parser = Parser::Ruby18.new
|
7
7
|
|
8
8
|
buffer = Parser::Source::Buffer.new('(comments)')
|
9
|
-
buffer.source =
|
9
|
+
buffer.source = code
|
10
|
+
|
11
|
+
ast, comments = parser.parse_with_comments(buffer)
|
12
|
+
associations = Parser::Source::Comment.associate(ast, comments)
|
13
|
+
|
14
|
+
[ ast, associations ]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_associate
|
18
|
+
ast, associations = associate(<<-END)
|
10
19
|
# Class comment
|
11
20
|
# another class comment
|
12
21
|
class Foo
|
@@ -23,9 +32,6 @@ class Foo
|
|
23
32
|
end
|
24
33
|
END
|
25
34
|
|
26
|
-
ast, comments = parser.parse_with_comments(buffer)
|
27
|
-
associations = Parser::Source::Comment.associate(ast, comments)
|
28
|
-
|
29
35
|
klass_node = ast
|
30
36
|
attr_accessor_node = ast.children[2].children[0]
|
31
37
|
method_node = ast.children[2].children[1]
|
@@ -45,4 +51,16 @@ end
|
|
45
51
|
associations[intermediate_node].map(&:text)
|
46
52
|
end
|
47
53
|
|
54
|
+
def test_associate_no_body
|
55
|
+
ast, associations = associate(<<-END)
|
56
|
+
# foo
|
57
|
+
class Foo
|
58
|
+
end
|
59
|
+
END
|
60
|
+
|
61
|
+
assert_equal 1, associations.size
|
62
|
+
assert_equal ['# foo'],
|
63
|
+
associations[ast].map(&:text)
|
64
|
+
end
|
65
|
+
|
48
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.beta6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: slop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|