unparser 0.4.8 → 0.4.9

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. metadata +3 -59
  4. data/.github/workflows/ci.yml +0 -90
  5. data/.gitignore +0 -37
  6. data/.rspec +0 -4
  7. data/.rubocop.yml +0 -126
  8. data/Changelog.md +0 -162
  9. data/Gemfile +0 -9
  10. data/Gemfile.lock +0 -111
  11. data/LICENSE +0 -20
  12. data/Rakefile +0 -22
  13. data/config/devtools.yml +0 -2
  14. data/config/flay.yml +0 -3
  15. data/config/flog.yml +0 -2
  16. data/config/mutant.yml +0 -6
  17. data/config/reek.yml +0 -98
  18. data/config/yardstick.yml +0 -2
  19. data/spec/integration/unparser/corpus_spec.rb +0 -125
  20. data/spec/integrations.yml +0 -92
  21. data/spec/spec_helper.rb +0 -42
  22. data/spec/unit/unparser/buffer/append_spec.rb +0 -24
  23. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
  24. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
  25. data/spec/unit/unparser/buffer/content_spec.rb +0 -38
  26. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
  27. data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
  28. data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
  29. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
  30. data/spec/unit/unparser/color_spec.rb +0 -40
  31. data/spec/unit/unparser/comments/consume_spec.rb +0 -22
  32. data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
  33. data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
  34. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
  35. data/spec/unit/unparser/diff_spec.rb +0 -189
  36. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
  37. data/spec/unit/unparser/validation_spec.rb +0 -327
  38. data/spec/unit/unparser_spec.rb +0 -1920
  39. data/unparser.gemspec +0 -35
@@ -1,42 +0,0 @@
1
- require 'anima'
2
- require 'mutant'
3
- require 'pathname'
4
- require 'timeout'
5
- require 'unparser'
6
- require 'yaml'
7
-
8
- require 'parser/current'
9
-
10
- RSpec.configuration.around(file_path: %r{spec/unit}) do |example|
11
- Timeout.timeout(0.1, &example)
12
- end
13
-
14
- RSpec.shared_examples_for 'a command method' do
15
- it 'returns self' do
16
- should equal(object)
17
- end
18
- end
19
-
20
- RSpec.shared_examples_for 'an idempotent method' do
21
- it 'is idempotent' do
22
- first = subject
23
- fail 'RSpec not configured for threadsafety' unless RSpec.configuration.threadsafe?
24
- mutex = __memoized.instance_variable_get(:@mutex)
25
- memoized = __memoized.instance_variable_get(:@memoized)
26
-
27
- mutex.synchronize { memoized.delete(:subject) }
28
- should equal(first)
29
- end
30
- end
31
-
32
- module SpecHelper
33
- def s(type, *children)
34
- Parser::AST::Node.new(type, children)
35
- end
36
- end
37
-
38
- RSpec.configure do |config|
39
- config.include(SpecHelper)
40
- config.extend(SpecHelper)
41
- config.raise_errors_for_deprecations!
42
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#append' do
4
- subject { object.append(string) }
5
-
6
- let(:object) { described_class.new }
7
- let(:string) { 'foo' }
8
-
9
- specify do
10
- expect { subject }.to change { object.content }.from('').to('foo')
11
- end
12
-
13
- # Yeah duplicate, mutant will be improved ;)
14
- it 'should prefix with indentation if line is empty' do
15
- object.append('foo')
16
- object.nl
17
- object.indent
18
- object.append('bar')
19
- object.append('baz')
20
- expect(object.content).to eql("foo\n barbaz")
21
- end
22
-
23
- it_should_behave_like 'a command method'
24
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#append_without_prefix' do
4
- subject { object.append_without_prefix(string) }
5
-
6
- let(:object) { described_class.new }
7
- let(:string) { 'foo' }
8
-
9
- specify do
10
- expect { subject }.to change { object.content }.from('').to('foo')
11
- end
12
-
13
- it 'should not prefix with indentation' do
14
- object.append_without_prefix('foo')
15
- object.nl
16
- object.indent
17
- object.append_without_prefix('bar')
18
- object.append_without_prefix('baz')
19
- expect(object.content).to eql("foo\nbarbaz")
20
- end
21
-
22
- it_should_behave_like 'a command method'
23
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#capture_content' do
4
-
5
- let(:object) { described_class.new }
6
-
7
- it 'should capture only the content appended within the block' do
8
- object.append('foo')
9
- object.nl
10
- object.indent
11
- captured = object.capture_content do
12
- object.append('bar')
13
- object.nl
14
- end
15
- expect(captured).to eql(" bar\n")
16
- end
17
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#content' do
4
- subject { object.content }
5
-
6
- let(:object) { described_class.new }
7
-
8
- shared_examples_for 'buffer content' do
9
- it 'contains expected content' do
10
- should eql(expected_content)
11
- end
12
-
13
- it { should be_frozen }
14
-
15
- it 'returns fresh string copies' do
16
- first = object.content
17
- second = object.content
18
- expect(first).to eql(second)
19
- expect(first).not_to be(second)
20
- end
21
- end
22
-
23
- context 'with empty buffer' do
24
- let(:expected_content) { '' }
25
-
26
- it_should_behave_like 'buffer content'
27
- end
28
-
29
- context 'with filled buffer' do
30
- before do
31
- object.append('foo')
32
- end
33
-
34
- let(:expected_content) { 'foo' }
35
-
36
- it_behaves_like 'buffer content'
37
- end
38
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#fresh_line?' do
4
- let(:object) { described_class.new }
5
-
6
- it 'should return true while buffer is empty' do
7
- expect(object.fresh_line?).to eql(true)
8
- end
9
-
10
- it 'should return false after content has been appended' do
11
- object.append('foo')
12
- expect(object.fresh_line?).to eql(false)
13
- end
14
-
15
- it 'should return true after a nl has been appended' do
16
- object.append('foo')
17
- object.nl
18
- expect(object.fresh_line?).to eql(true)
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#indent' do
4
- let(:object) { described_class.new }
5
-
6
- subject { object.indent }
7
-
8
- it 'should indent with two spaces' do
9
- object.append('foo')
10
- object.nl
11
- object.indent
12
- object.append('bar')
13
- object.nl
14
- object.indent
15
- object.append('baz')
16
- expect(object.content).to eql("foo\n bar\n baz")
17
- end
18
-
19
- it_should_behave_like 'a command method'
20
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#nl' do
4
- let(:object) { described_class.new }
5
-
6
- subject { object.nl }
7
-
8
- it 'writes a newline' do
9
- object.append('foo')
10
- subject
11
- object.append('bar')
12
- expect(object.content).to eql("foo\nbar")
13
- end
14
-
15
- it_should_behave_like 'a command method'
16
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Buffer, '#unindent' do
4
- let(:object) { described_class.new }
5
-
6
- subject { object.unindent }
7
-
8
- it 'unindents two chars' do
9
- object.append('foo')
10
- object.nl
11
- object.indent
12
- object.append('bar')
13
- object.nl
14
- object.unindent
15
- object.append('baz')
16
- expect(object.content).to eql("foo\n bar\nbaz")
17
- end
18
-
19
- it_should_behave_like 'a command method'
20
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Color do
4
- shared_examples 'actual color' do |code|
5
- describe '#format' do
6
-
7
- it 'returns formatted string' do
8
- expect(apply).to eql("\e[#{code}mexample-string\e[0m")
9
- end
10
- end
11
- end
12
-
13
- describe '#format' do
14
- let(:input) { 'example-string' }
15
-
16
- def apply
17
- object.format(input)
18
- end
19
-
20
- context 'RED' do
21
- let(:object) { described_class::RED }
22
-
23
- include_examples 'actual color', 31
24
- end
25
-
26
- context 'GREEN' do
27
- let(:object) { described_class::GREEN }
28
-
29
- include_examples 'actual color', 32
30
- end
31
-
32
- context 'NONE' do
33
- let(:object) { described_class::NONE }
34
-
35
- it 'returns original input' do
36
- expect(apply).to be(input)
37
- end
38
- end
39
- end
40
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Comments, '#consume' do
4
-
5
- let(:ast_and_comments) do
6
- Unparser.parse_with_comments(<<~'RUBY')
7
- def hi # EOL 1
8
- end # EOL 2
9
- RUBY
10
- end
11
- let(:ast) { ast_and_comments[0] }
12
- let(:comments) { ast_and_comments[1] }
13
- let(:object) { described_class.new(comments) }
14
-
15
- it 'should cause further EOL comments to be returned' do
16
- expect(object.take_eol_comments).to eql([])
17
- object.consume(ast, :name)
18
- expect(object.take_eol_comments).to eql([comments[0]])
19
- object.consume(ast, :end)
20
- expect(object.take_eol_comments).to eql([comments[1]])
21
- end
22
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Comments, '#take_all' do
4
-
5
- let(:ast_and_comments) do
6
- Unparser.parse_with_comments(<<~'RUBY')
7
- def hi # EOL 1
8
- end # EOL 2
9
- RUBY
10
- end
11
- let(:ast) { ast_and_comments[0] }
12
- let(:comments) { ast_and_comments[1] }
13
- let(:object) { described_class.new(comments) }
14
-
15
- it 'should take all comments' do
16
- expect(object.take_all).to eql(comments)
17
- expect(object.take_all).to eql([])
18
- end
19
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Comments, '#take_before' do
4
-
5
- let(:ast) { ast_and_comments[0] }
6
- let(:comments) { ast_and_comments[1] }
7
- let(:object) { described_class.new(comments) }
8
-
9
- context 'usual case' do
10
-
11
- let(:ast_and_comments) do
12
- Unparser.parse_with_comments(<<~'RUBY')
13
- def hi # EOL 1
14
- # comment
15
- end # EOL 2
16
- RUBY
17
- end
18
-
19
- it 'should return no comments if none are before the node' do
20
- expect(object.take_before(ast, :expression)).to eql([])
21
- end
22
-
23
- it 'should return only the comments that are before the specified part of the node' do
24
- expect(object.take_before(ast, :end)).to eql(comments.first(2))
25
- expect(object.take_all).to eql([comments[2]])
26
- end
27
- end
28
-
29
- context 'when node does not respond to source part' do
30
-
31
- let(:ast_and_comments) do
32
- Unparser.parse_with_comments(<<~'RUBY')
33
- expression ? :foo : :bar # EOL 1
34
- # EOL 2
35
- RUBY
36
- end
37
-
38
- it 'should return no comments if none are before the node' do
39
- expect(object.take_before(ast, :expression)).to eql([])
40
- end
41
-
42
- it 'should return only the comments that are before the specified part of the node' do
43
- expect(object.take_before(ast, :end)).to eql([])
44
- end
45
- end
46
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Unparser::Comments, '#take_eol_comments' do
4
-
5
- let(:ast_and_comments) do
6
- Unparser.parse_with_comments(<<~'RUBY')
7
- def hi # EOL 1
8
- =begin
9
- doc comment
10
- =end
11
- end # EOL 2
12
- RUBY
13
- end
14
- let(:ast) { ast_and_comments[0] }
15
- let(:comments) { ast_and_comments[1] }
16
- let(:object) { described_class.new(comments) }
17
-
18
- it 'should return no comments if nothing has been consumed' do
19
- expect(object.take_eol_comments).to eql([])
20
- end
21
-
22
- it 'should return comments once their line has been consumed' do
23
- object.consume(ast, :name)
24
- expect(object.take_eol_comments).to eql([comments[0]])
25
- end
26
-
27
- it 'should leave doc comments to be taken later' do
28
- object.consume(ast)
29
- expect(object.take_eol_comments).to eql([comments[0], comments[2]])
30
- expect(object.take_all).to eql([comments[1]])
31
- end
32
- end
@@ -1,189 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Unparser::Diff do
4
- let(:object) { described_class }
5
-
6
- describe '.build' do
7
-
8
- subject { object.build(old_string, new_string) }
9
-
10
- let(:old_string) { "foo\nbar" }
11
- let(:new_string) { "bar\nbaz" }
12
-
13
- it { should eql(described_class.new(%w[foo bar], %w[bar baz])) }
14
-
15
- end
16
-
17
- describe '#colorized_diff' do
18
- let(:object) { described_class.new(old, new) }
19
-
20
- subject { object.colorized_diff }
21
-
22
- context 'when there is a diff at begin of hunk' do
23
- let(:old) { %w[foo bar] }
24
- let(:new) { %w[baz bar] }
25
-
26
- let(:expectation) do
27
- [
28
- "@@ -1,3 +1,3 @@\n",
29
- Unparser::Color::RED.format("-foo\n"),
30
- Unparser::Color::GREEN.format("+baz\n"),
31
- " bar\n"
32
- ].join
33
- end
34
-
35
- it { should eql(expectation) }
36
-
37
- it_should_behave_like 'an idempotent method'
38
- end
39
-
40
- context 'when there is no diff' do
41
- let(:old) { '' }
42
- let(:new) { '' }
43
-
44
- it { should be(nil) }
45
-
46
- it_should_behave_like 'an idempotent method'
47
- end
48
- end
49
-
50
- describe '#diff' do
51
- let(:object) { described_class.new(old, new) }
52
-
53
- subject { object.diff }
54
-
55
- context 'when there is a diff at begin and end' do
56
- let(:old) { %w[foo bar foo] }
57
- let(:new) { %w[baz bar baz] }
58
-
59
- let(:expectation) do
60
- <<~STR
61
- @@ -1,4 +1,4 @@
62
- -foo
63
- +baz
64
- bar
65
- -foo
66
- +baz
67
- STR
68
- end
69
-
70
- it { should eql(expectation) }
71
-
72
- it_should_behave_like 'an idempotent method'
73
- end
74
-
75
- context 'when there is a diff at begin of hunk' do
76
- let(:old) { %w[foo bar] }
77
- let(:new) { %w[baz bar] }
78
-
79
- let(:expectation) do
80
- <<~STR
81
- @@ -1,3 +1,3 @@
82
- -foo
83
- +baz
84
- bar
85
- STR
86
- end
87
-
88
- it { should eql(expectation) }
89
-
90
- it_should_behave_like 'an idempotent method'
91
- end
92
-
93
- context 'when there is a diff NOT at begin of hunk' do
94
- let(:old) { %w[foo bar] }
95
- let(:new) { %w[foo baz bar] }
96
-
97
- let(:expectation) do
98
- <<~STR
99
- @@ -1,3 +1,4 @@
100
- foo
101
- +baz
102
- bar
103
- STR
104
- end
105
-
106
- it { should eql(expectation) }
107
-
108
- it_should_behave_like 'an idempotent method'
109
- end
110
-
111
- context 'when the diff has a long context at begin' do
112
- let(:old) { %w[foo bar baz boz a b c] }
113
- let(:new) { %w[foo bar baz boz a b c other] }
114
-
115
- let(:expectation) do
116
- <<~STR
117
- @@ -1,8 +1,9 @@
118
- foo
119
- bar
120
- baz
121
- boz
122
- a
123
- b
124
- c
125
- +other
126
- STR
127
- end
128
-
129
- it { should eql(expectation) }
130
-
131
- it_should_behave_like 'an idempotent method'
132
- end
133
-
134
- context 'when the diff has a long context at end, deleting' do
135
- let(:old) { %w[other foo bar baz boz a b c] }
136
- let(:new) { %w[foo bar baz boz a b c] }
137
-
138
- let(:expectation) do
139
- <<~STR
140
- @@ -1,9 +1,8 @@
141
- -other
142
- foo
143
- bar
144
- baz
145
- boz
146
- a
147
- b
148
- c
149
- STR
150
- end
151
-
152
- it { should eql(expectation) }
153
-
154
- it_should_behave_like 'an idempotent method'
155
- end
156
-
157
- context 'when the diff has a long context at end, inserting' do
158
- let(:old) { %w[foo bar baz boz a b c] }
159
- let(:new) { %w[other foo bar baz boz a b c] }
160
-
161
- let(:expectation) do
162
- <<~STR
163
- @@ -1,8 +1,9 @@
164
- +other
165
- foo
166
- bar
167
- baz
168
- boz
169
- a
170
- b
171
- c
172
- STR
173
- end
174
-
175
- it { should eql(expectation) }
176
-
177
- it_should_behave_like 'an idempotent method'
178
- end
179
-
180
- context 'when there is no diff' do
181
- let(:old) { '' }
182
- let(:new) { '' }
183
-
184
- it { should be(nil) }
185
-
186
- it_should_behave_like 'an idempotent method'
187
- end
188
- end
189
- end