unparser 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +4 -0
- data/config/rubocop.yml +3 -0
- data/lib/unparser/comments.rb +1 -1
- data/spec/unit/unparser/comments/take_before_spec.rb +34 -12
- data/unparser.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b6b34a335d81e60393e168fed525e222b2c5300
|
4
|
+
data.tar.gz: dafb68722a32c72bd1200db7b92a1a6477f54c95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77fda7c1b4c35dfad959a0a9c47bc9f5cdaae335fb3d302bb4b3f0e683c9733e6c6005ffe2495f0c91c0bf5d39e1b173bf99e1c918d13ef6f622d73079e4c534
|
7
|
+
data.tar.gz: b0252bbfb29b1c29b7e1de2fc7dd3719288c5b8227684558e7db7bc2c2cb347863123a10131a52c8ea6c2261a88879d6d64aec347189f68b09a7356a8e03531d
|
data/Changelog.md
CHANGED
data/config/rubocop.yml
CHANGED
@@ -41,6 +41,9 @@ AccessControl:
|
|
41
41
|
LineLength:
|
42
42
|
Max: 113 # TODO: lower to 79 once the rubocop branch in shared/Gemfile is removed
|
43
43
|
|
44
|
+
ClassLength:
|
45
|
+
Max: 196
|
46
|
+
|
44
47
|
# Disabled because of indenting with private keyword in class bodies.
|
45
48
|
IndentationWidth:
|
46
49
|
Enabled: false
|
data/lib/unparser/comments.rb
CHANGED
@@ -67,7 +67,7 @@ module Unparser
|
|
67
67
|
#
|
68
68
|
def take_before(node, source_part)
|
69
69
|
location = node.location
|
70
|
-
if location
|
70
|
+
if location.respond_to?(source_part)
|
71
71
|
range = location.public_send(source_part)
|
72
72
|
take_while { |comment| comment.location.expression.end_pos <= range.begin_pos }
|
73
73
|
else
|
@@ -3,23 +3,45 @@ require 'parser/current'
|
|
3
3
|
|
4
4
|
describe Unparser::Comments, '#take_before' do
|
5
5
|
|
6
|
-
let(:ast_and_comments) do
|
7
|
-
Parser::CurrentRuby.parse_with_comments(<<-RUBY)
|
8
|
-
def hi # EOL 1
|
9
|
-
# comment
|
10
|
-
end # EOL 2
|
11
|
-
RUBY
|
12
|
-
end
|
13
6
|
let(:ast) { ast_and_comments[0] }
|
14
7
|
let(:comments) { ast_and_comments[1] }
|
15
8
|
let(:object) { described_class.new(comments) }
|
16
9
|
|
17
|
-
|
18
|
-
|
10
|
+
context 'usual case' do
|
11
|
+
|
12
|
+
let(:ast_and_comments) do
|
13
|
+
Parser::CurrentRuby.parse_with_comments(<<-RUBY)
|
14
|
+
def hi # EOL 1
|
15
|
+
# comment
|
16
|
+
end # EOL 2
|
17
|
+
RUBY
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return no comments none are before the node' do
|
21
|
+
expect(object.take_before(ast, :expression)).to eql([])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should only the comments that are before the specified part of the node' do
|
25
|
+
expect(object.take_before(ast, :end)).to eql(comments.first(2))
|
26
|
+
expect(object.take_all).to eql([comments[2]])
|
27
|
+
end
|
19
28
|
end
|
20
29
|
|
21
|
-
|
22
|
-
|
23
|
-
|
30
|
+
context 'when node does not respond to source part' do
|
31
|
+
|
32
|
+
let(:ast_and_comments) do
|
33
|
+
Parser::CurrentRuby.parse_with_comments(<<-RUBY)
|
34
|
+
expression ? :foo : :bar # EOL 1
|
35
|
+
# EOL 2
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should return no comments none are before the node' do
|
40
|
+
expect(object.take_before(ast, :expression)).to eql([])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should only the comments that are before the specified part of the node' do
|
44
|
+
expect(object.take_before(ast, :end)).to eql([])
|
45
|
+
end
|
24
46
|
end
|
25
47
|
end
|
data/unparser.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|