grizzly-rb 1.0.0

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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +58 -0
  3. data/.gitignore +13 -0
  4. data/.rubocop.yml +23 -0
  5. data/Gemfile +10 -0
  6. data/Gemfile.lock +56 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +192 -0
  9. data/Rakefile +16 -0
  10. data/benchmark.rb +59 -0
  11. data/benchmark.txt +73 -0
  12. data/bin/console +22 -0
  13. data/bin/convert +15 -0
  14. data/bin/setup +11 -0
  15. data/bin/spec/convert +27 -0
  16. data/bin/spec/reset +9 -0
  17. data/bin/spec/setup +20 -0
  18. data/bin/test +38 -0
  19. data/config/mspec_override.rb +44 -0
  20. data/config/skipped_tests.yml +104 -0
  21. data/conversion/Gemfile +7 -0
  22. data/conversion/Gemfile.lock +53 -0
  23. data/conversion/bin/rspec +27 -0
  24. data/conversion/lib/cops/array_initialization.rb +95 -0
  25. data/conversion/lib/cops/enumerator_initialization.rb +56 -0
  26. data/conversion/lib/cops/grep_implementation.rb +36 -0
  27. data/conversion/lib/cops/instance_of_array.rb +24 -0
  28. data/conversion/lib/cops/subclass_initialization.rb +47 -0
  29. data/conversion/lib/cops.rb +6 -0
  30. data/conversion/spec/.DS_Store +0 -0
  31. data/conversion/spec/cops/array_initialization_spec.rb +154 -0
  32. data/conversion/spec/cops/enumerator_initialization_spec.rb +105 -0
  33. data/conversion/spec/cops/grep_implementation_spec.rb +57 -0
  34. data/conversion/spec/cops/instance_of_array_spec.rb +38 -0
  35. data/conversion/spec/cops/subclass_initialization_spec.rb +26 -0
  36. data/conversion/spec/spec_helper.rb +104 -0
  37. data/examples/transactions.rb +278 -0
  38. data/grizzly-group.gemspec +28 -0
  39. data/lib/grizzly/collection.rb +77 -0
  40. data/lib/grizzly/enumerable.rb +120 -0
  41. data/lib/grizzly/enumerator-backup.rb +114 -0
  42. data/lib/grizzly/enumerator.rb +63 -0
  43. data/lib/grizzly/lazy_enumerator.rb +40 -0
  44. data/lib/grizzly/version.rb +3 -0
  45. data/lib/grizzly.rb +8 -0
  46. metadata +89 -0
data/bin/test ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+
3
+ mspec/bin/mspec ruby-spec/core/array
4
+ RETURN1=$?
5
+
6
+ echo
7
+ echo
8
+
9
+ mspec/bin/mspec ruby-spec/core/enumerable
10
+ RETURN2=$?
11
+
12
+ echo
13
+ echo
14
+
15
+ mspec/bin/mspec ruby-spec/core/enumerator
16
+ RETURN3=$?
17
+
18
+ echo
19
+ echo
20
+
21
+ mspec/bin/mspec spec/enumerator
22
+ RETURN4=$?
23
+
24
+ echo
25
+ echo
26
+
27
+ mspec/bin/mspec spec/skipped_tests/core/array/
28
+ RETURN5=$?
29
+
30
+ RETURN=$(($RETURN1 + $RETURN2 + $RETURN3 + $RETURN4 + $RETURN5))
31
+
32
+ echo $RETURN
33
+
34
+ if [ $RETURN -gt "0" ]; then
35
+ echo "Tests failed"
36
+ exit 1
37
+ fi
38
+ exit 0
@@ -0,0 +1,44 @@
1
+ require "yaml"
2
+ require "singleton"
3
+ require "byebug"
4
+ require_relative "../lib/grizzly"
5
+
6
+ class MyCollectionArray < Grizzly::Collection; end
7
+
8
+ class SkippedTests
9
+ include Singleton
10
+
11
+ attr_accessor :source
12
+
13
+ def tests
14
+ YAML.load(File.read(source))["tests"]
15
+ end
16
+
17
+ def skip?(block_details)
18
+ tests.any? { |t| block_details.include?(t) }
19
+ end
20
+ end
21
+
22
+ file_path = File.expand_path(File.dirname(__FILE__))
23
+ SkippedTests.instance.source = File.join(file_path, "skipped_tests.yml")
24
+
25
+ module MSpec
26
+ def self.protect(location, &block)
27
+ begin
28
+ @env.instance_exec(&block)
29
+ return true
30
+ rescue SystemExit => e
31
+ raise e
32
+ rescue SkippedSpecError => e
33
+ @skips << [e, block]
34
+ return false
35
+ rescue Object => exc
36
+ return true if SkippedTests.instance.skip?(block.to_s)
37
+ # File.open("failed-specs.txt", "a") { |f| f.write "#{block.to_s}\n"}
38
+
39
+ actions :exception, ExceptionState.new(current && current.state, location, exc)
40
+ register_exit 1
41
+ return false
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,104 @@
1
+ tests:
2
+ # Enumerator
3
+ - core/enumerator/initialize_spec.rb:27
4
+ - shared/enumerator/enum_for.rb:6
5
+ # Array
6
+ - core/array/allocate_spec.rb:4
7
+ - core/array/flatten_spec.rb:79
8
+ - core/array/flatten_spec.rb:89
9
+ - core/array/flatten_spec.rb:248
10
+ - core/array/pack/buffer_spec.rb:26
11
+ - core/array/partition_spec.rb:37
12
+ - core/array/to_a_spec.rb:5
13
+ - core/array/to_a_spec.rb:11
14
+ - core/array/zip_spec.rb:62
15
+
16
+ todo:
17
+
18
+
19
+ unskipped_enumerables:
20
+ - core/enumerable/group_by_spec.rb:28
21
+ - core/enumerable/group_by_spec.rb:6
22
+ - core/enumerable/minmax_by_spec.rb:10
23
+ - core/enumerable/minmax_by_spec.rb:14
24
+ - core/enumerable/minmax_by_spec.rb:19
25
+ - core/enumerable/minmax_by_spec.rb:26
26
+ - core/enumerable/minmax_by_spec.rb:33
27
+ - core/enumerable/minmax_by_spec.rb:38
28
+ - core/enumerable/minmax_spec.rb:16
29
+ - core/enumerable/partition_spec.rb:14
30
+ - core/enumerable/partition_spec.rb:6
31
+ - core/enumerable/reject_spec.rb:19
32
+ - core/enumerable/reject_spec.rb:6
33
+ - core/enumerable/shared/find_all.rb:10
34
+ - core/enumerable/shared/find_all.rb:25
35
+ - core/enumerable/shared/take.rb:7
36
+ - core/enumerable/shared/take.rb:12
37
+ - core/enumerable/shared/take.rb:19
38
+ - core/enumerable/shared/take.rb:23
39
+ - core/enumerable/shared/take.rb:31
40
+ - core/enumerable/shared/take.rb:36
41
+ - core/enumerable/shared/take.rb:50
42
+ - core/enumerable/shared/take.rb:55
43
+ - core/enumerable/sort_by_spec.rb:6
44
+ - core/enumerable/sort_by_spec.rb:25
45
+ - core/enumerable/sort_by_spec.rb:30
46
+ - core/enumerable/sort_by_spec.rb:35
47
+ - core/enumerable/sort_spec.rb:5
48
+ - core/enumerable/sort_spec.rb:11
49
+ - core/enumerable/sort_spec.rb:22
50
+ - core/enumerable/sort_spec.rb:31
51
+ - core/enumerable/sort_spec.rb:46
52
+ - core/enumerable/sort_spec.rb:51
53
+ - core/enumerable/zip_spec.rb:6
54
+ - core/enumerable/zip_spec.rb:36
55
+ - shared/enumerable/minmax.rb:2
56
+ - shared/enumerable/minmax.rb:7
57
+ - shared/enumerable/minmax.rb:12
58
+
59
+ unskipped_array:
60
+ - core/array/compact_spec.rb:21
61
+ - core/array/difference_spec.rb:14
62
+ - core/array/drop_spec.rb:60
63
+ - core/array/drop_while_spec.rb:24
64
+ - core/array/first_spec.rb:76
65
+ - core/array/flatten_spec.rb:79
66
+ - core/array/last_spec.rb:70
67
+ - core/array/max_spec.rb:4
68
+ - core/array/min_spec.rb:4
69
+ - core/array/multiply_spec.rb:88
70
+ - core/array/permutation_spec.rb:26
71
+ - core/array/permutation_spec.rb:35
72
+ - core/array/plus_spec.rb:34
73
+ - core/array/pop_spec.rb:115
74
+ - core/array/reject_spec.rb:36
75
+ - core/array/reverse_spec.rb:18
76
+ - core/array/rotate_spec.rb:63
77
+ - core/array/sample_spec.rb:69
78
+ - core/array/shared/collect.rb:11
79
+ - core/array/shared/difference.rb:33
80
+ - core/array/shared/intersection.rb:67
81
+ - core/array/shared/select.rb:19
82
+ - core/array/shared/slice.rb:427
83
+ - core/array/shared/slice.rb:431
84
+ - core/array/shared/slice.rb:435
85
+ - core/array/shared/slice.rb:439
86
+ - core/array/shared/slice.rb:443
87
+ - core/array/shared/slice.rb:447
88
+ - core/array/shared/union.rb:62
89
+ - core/array/shift_spec.rb:116
90
+ - core/array/shuffle_spec.rb:24
91
+ - core/array/slice_spec.rb:217
92
+ - core/array/slice_spec.rb:221
93
+ - core/array/slice_spec.rb:225
94
+ - core/array/slice_spec.rb:229
95
+ - core/array/slice_spec.rb:233
96
+ - core/array/slice_spec.rb:237
97
+ - core/array/sort_spec.rb:167
98
+ - core/array/take_spec.rb:36
99
+ - core/array/take_while_spec.rb:24
100
+ - core/array/transpose_spec.rb:47
101
+ - core/array/union_spec.rb:17
102
+ - core/array/uniq_spec.rb:94
103
+ - core/array/values_at_spec.rb:61
104
+
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop"
6
+ gem "rspec"
7
+ gem "byebug"
@@ -0,0 +1,53 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ast (2.4.2)
5
+ byebug (11.1.3)
6
+ diff-lcs (1.5.0)
7
+ json (2.6.2)
8
+ parallel (1.22.1)
9
+ parser (3.1.2.1)
10
+ ast (~> 2.4.1)
11
+ rainbow (3.1.1)
12
+ regexp_parser (2.6.0)
13
+ rexml (3.2.5)
14
+ rspec (3.11.0)
15
+ rspec-core (~> 3.11.0)
16
+ rspec-expectations (~> 3.11.0)
17
+ rspec-mocks (~> 3.11.0)
18
+ rspec-core (3.11.0)
19
+ rspec-support (~> 3.11.0)
20
+ rspec-expectations (3.11.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.11.0)
23
+ rspec-mocks (3.11.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.11.0)
26
+ rspec-support (3.11.1)
27
+ rubocop (1.36.0)
28
+ json (~> 2.3)
29
+ parallel (~> 1.10)
30
+ parser (>= 3.1.2.1)
31
+ rainbow (>= 2.2.2, < 4.0)
32
+ regexp_parser (>= 1.8, < 3.0)
33
+ rexml (>= 3.2.5, < 4.0)
34
+ rubocop-ast (>= 1.20.1, < 2.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (>= 1.4.0, < 3.0)
37
+ rubocop-ast (1.21.0)
38
+ parser (>= 3.1.1.0)
39
+ ruby-progressbar (1.11.0)
40
+ unicode-display_width (2.3.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+ x86_64-darwin-20
45
+ x86_64-darwin-21
46
+
47
+ DEPENDENCIES
48
+ byebug
49
+ rspec
50
+ rubocop
51
+
52
+ BUNDLED WITH
53
+ 2.3.22
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,95 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Style
4
+ class ArrayInitialization < Base
5
+ extend RuboCop::Cop::AutoCorrector
6
+
7
+ ERROR_MSG_LITERAL = "an Array should not be initialized with the literal constructor []"
8
+ ERROR_MSG_NEW = "an Array should not be initialized with .new"
9
+ ERROR_MSG_TO_A = "an Array should not be initialized with #to_a"
10
+
11
+ def_node_matcher :array_literal, <<~PATTERN
12
+ (array $...)
13
+ PATTERN
14
+
15
+ def_node_matcher :array_create, <<~PATTERN
16
+ (send (const ...) :new (array ...))
17
+ PATTERN
18
+
19
+ def_node_matcher :array_spec_matched, <<~PATTERN
20
+ (send (send ...) :== (array ...))
21
+ PATTERN
22
+
23
+ def_node_matcher :generic_array_initialization, <<~PATTERN
24
+ (send (const nil? :Array) :new $...)
25
+ PATTERN
26
+
27
+ def_node_matcher :to_a_initialization, <<~PATTERN
28
+ (send (...) :to_a)
29
+ PATTERN
30
+
31
+ def_node_matcher :to_a_already_parsed, <<~PATTERN
32
+ (send $(...) :new (...))
33
+ PATTERN
34
+
35
+ def on_send(node)
36
+ on_send_generic_initialization(node)
37
+ on_send_to_a_initialization(node)
38
+ end
39
+
40
+ def on_send_generic_initialization(node)
41
+ return unless (expression = generic_array_initialization(node))
42
+
43
+ add_offense(node, message: ERROR_MSG_NEW) do |corrector|
44
+ a, b = expression.map(&:source)
45
+ corrector.replace node, format_correction(first: a , second: b)
46
+ end
47
+ end
48
+
49
+ def on_send_to_a_initialization(node)
50
+ return if to_a_already_parsed(node.parent)&.source == cop_config['InitializeArrayWith']
51
+ return unless to_a_initialization(node)
52
+
53
+ add_offense(node, message: ERROR_MSG_TO_A) do |corrector|
54
+ corrector.replace node, format_correction(first: node.source)
55
+ end
56
+ end
57
+
58
+ def on_array(node)
59
+ return if array_create(node.parent)
60
+ return if array_spec_matched(node.parent)
61
+ return unless (expression = array_literal(node))
62
+
63
+ add_offense(node, message: ERROR_MSG_LITERAL) do |corrector|
64
+ corrector.replace node, format_correction(first: expression_to_string(expression))
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def expression_to_string(expression)
71
+ expression.map do |node|
72
+ case node.type
73
+ when :int
74
+ node.value
75
+ when :true
76
+ true
77
+ when :false
78
+ false
79
+ else
80
+ node.value
81
+ end
82
+ end
83
+ end
84
+
85
+ def format_correction(first: nil, second: nil, constant: cop_config['InitializeArrayWith'])
86
+ result = "#{constant}.new(#{first})"
87
+ if second
88
+ result = %Q{#{constant}.new(#{first}, #{second})}
89
+ end
90
+ result
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,56 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Style
4
+ class EnumeratorInitialization < Base
5
+ extend RuboCop::Cop::AutoCorrector
6
+
7
+ ERROR_MSG_TO_ENUM = "#to_enum initialization needs to be wrapped"
8
+ ERROR_MSG_NEW = "#new Enumerator initialization needs to be wrapped"
9
+
10
+ def_node_matcher :already_wrapped, <<~PATTERN
11
+ (send $(...) :new (...))
12
+ PATTERN
13
+
14
+ def_node_matcher :to_enum_initialization, <<~PATTERN
15
+ (send (...) :to_enum ...)
16
+ PATTERN
17
+
18
+
19
+ def_node_matcher :new_initialization, <<~PATTERN
20
+ (send (const nil? :Enumerator) :new ...)
21
+ PATTERN
22
+
23
+ def_node_matcher :new_block_initialization, <<~PATTERN
24
+ (block (send (const nil? :Enumerator) :new ...) ...)
25
+ PATTERN
26
+
27
+ def on_send(node)
28
+ return if already_wrapped(node.parent)&.source == cop_config['InitializeEnumeratorWith']
29
+ return if new_block_initialization(node.parent)
30
+
31
+ error = case
32
+ when to_enum_initialization(node) then ERROR_MSG_TO_ENUM
33
+ when new_initialization(node) then ERROR_MSG_NEW
34
+ end
35
+
36
+ return unless error
37
+
38
+ add_offense(node, message: error) do |corrector|
39
+ constant = cop_config['InitializeEnumeratorWith']
40
+ corrector.replace node, "#{constant}.new(#{node.source})"
41
+ end
42
+ end
43
+
44
+ def on_block(node)
45
+ return if already_wrapped(node.parent)&.source == cop_config['InitializeEnumeratorWith']
46
+ return unless new_block_initialization(node)
47
+
48
+ add_offense(node, message: ERROR_MSG_NEW) do |corrector|
49
+ constant = cop_config['InitializeEnumeratorWith']
50
+ corrector.replace node, "#{constant}.new(#{node.source})"
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,36 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Style
4
+ class GrepImplementation < Base
5
+ extend RuboCop::Cop::AutoCorrector
6
+
7
+ ERROR_MSG = "#grep and grep_v cannot be implemented"
8
+
9
+ def_node_matcher :enumerable_grep_spec, <<~PATTERN
10
+ (block (send nil? :describe (str "Enumerable#grep")) ...)
11
+ PATTERN
12
+
13
+ def_node_matcher :enumerable_grep_v_spec, <<~PATTERN
14
+ (block (send nil? :describe (str "Enumerable#grep_v")) ...)
15
+ PATTERN
16
+
17
+ def_node_matcher :grep_spec_already_skipped, <<~PATTERN
18
+ (block (send nil? :ruby_bug ...) ...)
19
+ PATTERN
20
+
21
+ def on_block(node)
22
+ return if grep_spec_already_skipped(node.parent)
23
+ return unless (expression = enumerable_grep_spec(node) || enumerable_grep_v_spec(node))
24
+
25
+ add_offense(node, message: ERROR_MSG) do |corrector|
26
+ corrector.replace node, <<~RUBY
27
+ ruby_bug '#11808', ''...'#{cop_config['GrepSupportRubyVersion']}' do
28
+ #{node.source}
29
+ end
30
+ RUBY
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Style
4
+ class InstanceOfArray < Base
5
+ extend RuboCop::Cop::AutoCorrector
6
+
7
+ ERROR_MSG = "instance_of should not be of Array"
8
+
9
+ def_node_matcher :instance_of_literal, <<~PATTERN
10
+ (send nil? :be_an_instance_of (const nil? :Array))
11
+ PATTERN
12
+
13
+ def on_send(node)
14
+ return unless instance_of_literal(node)
15
+
16
+ add_offense(node, message: ERROR_MSG) do |corrector|
17
+ constant_to_replace = cop_config['NewInstanceOf']
18
+ corrector.replace(node, "be_an_instance_of(#{constant_to_replace})")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,47 @@
1
+ require "rubocop"
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ class SubclassInitialization < Base
7
+ extend RuboCop::Cop::AutoCorrector
8
+
9
+ ERROR_MSG = "instance_of should not be of Array"
10
+
11
+ def_node_matcher :sublclass_literal, <<~PATTERN
12
+ (send (const (const ... ) :MyArray ) :[] $...)
13
+ PATTERN
14
+
15
+ def on_send(node)
16
+ return unless (expression = sublclass_literal(node))
17
+
18
+ add_offense(node, message: ERROR_MSG) do |corrector|
19
+ constant_to_replace = cop_config['InitializeArrayWith']
20
+ corrector.replace(node, "#{constant_to_replace}.new(#{expression.map(&:value)})")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ # (index
30
+ # (const
31
+ # (const nil :ArraySpecs) :MyArray)
32
+ # (int 1)
33
+ # (int 2)
34
+ # (int 3)
35
+ # (int 4)
36
+ # (int 5)))
37
+
38
+
39
+ # s(:ivasgn, :@array,
40
+ # s(:send,
41
+ # s(:const,
42
+ # s(:const, nil, :ArraySpecs), :MyArray), :[],
43
+ # s(:int, 1),
44
+ # s(:int, 2),
45
+ # s(:int, 3),
46
+ # s(:int, 4),
47
+ # s(:int, 5)))
@@ -0,0 +1,6 @@
1
+ require "rubocop"
2
+ require_relative "cops/array_initialization"
3
+ require_relative "cops/instance_of_array"
4
+ require_relative "cops/subclass_initialization"
5
+ require_relative "cops/grep_implementation"
6
+ require_relative "cops/enumerator_initialization"
Binary file