unparser 0.4.4 → 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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -3
  3. data/lib/unparser.rb +21 -3
  4. data/lib/unparser/ast.rb +1 -1
  5. data/lib/unparser/ast/local_variable_scope.rb +6 -6
  6. data/lib/unparser/cli.rb +65 -45
  7. data/lib/unparser/{cli/color.rb → color.rb} +0 -10
  8. data/lib/unparser/constants.rb +1 -1
  9. data/lib/unparser/diff.rb +115 -0
  10. data/lib/unparser/dsl.rb +1 -1
  11. data/lib/unparser/emitter.rb +4 -5
  12. data/lib/unparser/emitter/argument.rb +9 -13
  13. data/lib/unparser/emitter/literal/primitive.rb +1 -1
  14. data/lib/unparser/emitter/literal/range.rb +1 -1
  15. data/lib/unparser/node_helpers.rb +4 -2
  16. data/lib/unparser/preprocessor.rb +1 -1
  17. data/lib/unparser/validation.rb +149 -0
  18. metadata +97 -78
  19. data/.circleci/config.yml +0 -41
  20. data/.gitignore +0 -37
  21. data/.rspec +0 -4
  22. data/.rubocop.yml +0 -9
  23. data/Changelog.md +0 -142
  24. data/Gemfile +0 -7
  25. data/Gemfile.lock +0 -176
  26. data/LICENSE +0 -20
  27. data/Rakefile +0 -22
  28. data/config/devtools.yml +0 -2
  29. data/config/flay.yml +0 -3
  30. data/config/flog.yml +0 -2
  31. data/config/mutant.yml +0 -6
  32. data/config/reek.yml +0 -98
  33. data/config/rubocop.yml +0 -122
  34. data/config/yardstick.yml +0 -2
  35. data/lib/unparser/cli/differ.rb +0 -152
  36. data/lib/unparser/cli/source.rb +0 -267
  37. data/spec/integration/unparser/corpus_spec.rb +0 -111
  38. data/spec/integrations.yml +0 -87
  39. data/spec/spec_helper.rb +0 -20
  40. data/spec/unit/unparser/buffer/append_spec.rb +0 -24
  41. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
  42. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
  43. data/spec/unit/unparser/buffer/content_spec.rb +0 -38
  44. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
  45. data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
  46. data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
  47. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
  48. data/spec/unit/unparser/comments/consume_spec.rb +0 -22
  49. data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
  50. data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
  51. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
  52. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
  53. data/spec/unit/unparser_spec.rb +0 -1841
  54. data/unparser.gemspec +0 -30
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
- describe 'Unparser on ruby corpus', mutant: false do
3
- ROOT = Pathname.new(__FILE__).parent.parent.parent.parent
4
-
5
- TMP = ROOT.join('tmp')
6
-
7
- class Project
8
- include Anima.new(:name, :repo_uri, :repo_ref, :exclude)
9
-
10
- # Perform verification via unparser cli
11
- #
12
- # @return [self]
13
- # if successful
14
- #
15
- # @raise [Exception]
16
- # otherwise
17
- #
18
- def verify
19
- checkout
20
- command = %W(unparser #{repo_path})
21
- exclude.each do |name|
22
- command.concat(%W(--ignore #{repo_path.join(name)}))
23
- end
24
- system(command) do
25
- raise "Verifing #{name} failed!"
26
- end
27
- self
28
- end
29
-
30
- # Checkout repository
31
- #
32
- # @return [self]
33
- #
34
- # @api private
35
- #
36
- def checkout
37
- TMP.mkdir unless TMP.directory?
38
- if repo_path.exist?
39
- Dir.chdir(repo_path) do
40
- system(%w(git pull origin master))
41
- system(%w(git clean -f -d -x))
42
- end
43
- else
44
- system(%W(git clone #{repo_uri} #{repo_path}))
45
- end
46
-
47
- Dir.chdir(repo_path) do
48
- system(%W(git checkout #{repo_ref}))
49
- system(%w(git reset --hard))
50
- system(%w(git clean -f -d -x))
51
- end
52
-
53
- self
54
- end
55
-
56
- private
57
-
58
- # Return repository path
59
- #
60
- # @return [Pathname]
61
- #
62
- # @api private
63
- #
64
- def repo_path
65
- TMP.join(name)
66
- end
67
-
68
- # Helper method to execute system commands
69
- #
70
- # @param [Array<String>] arguments
71
- #
72
- # @api private
73
- #
74
- def system(arguments)
75
- return if Kernel.system(*arguments)
76
-
77
- if block_given?
78
- yield
79
- else
80
- raise "System command #{arguments.inspect} failed!"
81
- end
82
- end
83
-
84
- LOADER = Morpher.build do
85
- s(:block,
86
- s(:guard, s(:primitive, Array)),
87
- s(:map,
88
- s(:block,
89
- s(:guard, s(:primitive, Hash)),
90
- s(:hash_transform,
91
- s(:key_symbolize, :repo_uri, s(:guard, s(:primitive, String))),
92
- s(:key_symbolize, :repo_ref, s(:guard, s(:primitive, String))),
93
- s(:key_symbolize, :name, s(:guard, s(:primitive, String))),
94
- s(:key_symbolize, :exclude, s(:map, s(:guard, s(:primitive, String))))),
95
- s(:load_attribute_hash,
96
- # NOTE: The domain param has no DSL currently!
97
- Morpher::Evaluator::Transformer::Domain::Param.new(
98
- Project,
99
- [:repo_uri, :repo_ref, :name, :exclude]
100
- )))))
101
- end
102
-
103
- ALL = LOADER.call(YAML.load_file(ROOT.join('spec', 'integrations.yml')))
104
- end
105
-
106
- Project::ALL.each do |project|
107
- specify "unparsing #{project.name}" do
108
- project.verify
109
- end
110
- end
111
- end
@@ -1,87 +0,0 @@
1
- ---
2
- - name: anima
3
- repo_uri: 'https://github.com/mbj/anima.git'
4
- repo_ref: 'origin/master'
5
- exclude: []
6
- - name: mutant
7
- repo_uri: 'https://github.com/mbj/mutant.git'
8
- repo_ref: 'origin/master'
9
- exclude: []
10
- - name: yaks
11
- repo_uri: 'https://github.com/plexus/yaks.git'
12
- repo_ref: 'origin/master'
13
- exclude: []
14
- - name: chassis
15
- repo_uri: 'https://github.com/ahawkins/chassis.git'
16
- repo_ref: 'origin/master'
17
- exclude: []
18
- - name: rubyspec
19
- repo_uri: 'https://github.com/ruby/spec.git'
20
- # Revision of rubyspec on the last CI build of unparser that passed
21
- repo_ref: 'origin/master'
22
- exclude:
23
- - command_line/fixtures/bad_syntax.rb
24
- - core/array/pack/shared/float.rb
25
- - core/array/pack/shared/integer.rb
26
- - core/array/pack/shared/string.rb
27
- - core/array/pack/{b,c,h,m}_spec.rb
28
- - core/array/pack/{u,w}_spec.rb
29
- - core/encoding/compatible_spec.rb
30
- - core/encoding/converter/convert_spec.rb
31
- - core/encoding/converter/last_error_spec.rb
32
- - core/encoding/converter/primitive_convert_spec.rb
33
- - core/encoding/converter/primitive_errinfo_spec.rb
34
- - core/encoding/converter/putback_spec.rb
35
- - core/encoding/fixtures/classes.rb
36
- - core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
37
- - core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
38
- - core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
39
- - core/encoding/replicate_spec.rb
40
- - core/env/element_reference_spec.rb
41
- - core/io/readpartial_spec.rb
42
- - core/io/shared/gets_ascii.rb
43
- - core/marshal/dump_spec.rb
44
- - core/marshal/fixtures/marshal_data.rb
45
- - core/marshal/shared/load.rb
46
- - core/random/bytes_spec.rb
47
- - core/regexp/shared/new_ascii.rb
48
- - core/regexp/shared/new_ascii_8bit.rb
49
- - core/regexp/shared/quote.rb
50
- - core/string/byteslice_spec.rb
51
- - core/string/casecmp_spec.rb
52
- - core/string/codepoints_spec.rb
53
- - core/string/count_spec.rb
54
- - core/string/shared/codepoints.rb
55
- - core/string/shared/each_codepoint_without_block.rb
56
- - core/string/shared/eql.rb
57
- - core/string/shared/succ.rb
58
- - core/string/shared/to_sym.rb
59
- - core/string/squeeze_spec.rb
60
- - core/string/unpack/shared/float.rb
61
- - core/string/unpack/shared/integer.rb
62
- - core/string/unpack/{b,c,h,m}_spec.rb
63
- - core/string/unpack/{u,w}_spec.rb
64
- - core/symbol/casecmp_spec.rb
65
- - core/time/_dump_spec.rb
66
- - core/time/_load_spec.rb
67
- - language/fixtures/binary_symbol.rb
68
- - language/fixtures/squiggly_heredoc.rb
69
- - language/for_spec.rb
70
- - language/regexp/encoding_spec.rb
71
- - language/regexp/escapes_spec.rb
72
- - language/source_encoding_spec.rb
73
- - language/string_spec.rb
74
- - library/digest/md5/shared/constants.rb
75
- - library/digest/md5/shared/sample.rb
76
- - library/digest/sha1/shared/constants.rb
77
- - library/digest/sha256/shared/constants.rb
78
- - library/digest/sha384/shared/constants.rb
79
- - library/digest/sha512/shared/constants.rb
80
- - library/openssl/shared/constants.rb
81
- - library/socket/basicsocket/recv_spec.rb
82
- - library/socket/socket/gethostbyname_spec.rb
83
- - library/stringscanner/getch_spec.rb
84
- - library/stringscanner/shared/get_byte.rb
85
- - library/zlib/inflate/set_dictionary_spec.rb
86
- - optional/capi/integer_spec.rb
87
- - security/cve_2010_1330_spec.rb
@@ -1,20 +0,0 @@
1
- require 'yaml'
2
- require 'pathname'
3
- require 'unparser'
4
- require 'anima'
5
- require 'morpher'
6
- require 'devtools/spec_helper'
7
-
8
- require 'parser/current'
9
-
10
- module SpecHelper
11
- def s(type, *children)
12
- Parser::AST::Node.new(type, children)
13
- end
14
- end
15
-
16
- RSpec.configure do |config|
17
- config.include(SpecHelper)
18
- config.extend(SpecHelper)
19
- config.raise_errors_for_deprecations!
20
- 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,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