rubocop 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +42 -0
- data/README.md +59 -54
- data/config/default.yml +124 -95
- data/config/disabled.yml +4 -0
- data/config/enabled.yml +286 -264
- data/lib/rubocop.rb +10 -3
- data/lib/rubocop/cli.rb +10 -171
- data/lib/rubocop/cop/cop.rb +14 -11
- data/lib/rubocop/cop/lint/debugger.rb +35 -0
- data/lib/rubocop/cop/lint/syntax.rb +34 -0
- data/lib/rubocop/cop/offence.rb +15 -23
- data/lib/rubocop/cop/style/align_array.rb +1 -10
- data/lib/rubocop/cop/style/align_hash.rb +14 -2
- data/lib/rubocop/cop/style/align_parameters.rb +1 -11
- data/lib/rubocop/cop/style/and_or.rb +13 -11
- data/lib/rubocop/cop/style/attr.rb +1 -1
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +31 -6
- data/lib/rubocop/cop/style/blocks.rb +14 -6
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/class_length.rb +38 -0
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/configurable_naming.rb +47 -0
- data/lib/rubocop/cop/style/def_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +7 -3
- data/lib/rubocop/cop/style/hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/hash_syntax.rb +36 -7
- data/lib/rubocop/cop/style/lambda_call.rb +36 -11
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +41 -0
- data/lib/rubocop/cop/style/method_length.rb +2 -13
- data/lib/rubocop/cop/style/method_name.rb +42 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +4 -0
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +60 -0
- data/lib/rubocop/cop/style/redundant_exception.rb +32 -0
- data/lib/rubocop/cop/style/redundant_return.rb +14 -5
- data/lib/rubocop/cop/style/redundant_self.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +13 -4
- data/lib/rubocop/cop/style/signal_exception.rb +63 -14
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/string_help.rb +4 -1
- data/lib/rubocop/cop/style/string_literals.rb +34 -11
- data/lib/rubocop/cop/style/surrounding_space.rb +64 -17
- data/lib/rubocop/cop/style/tab.rb +1 -1
- data/lib/rubocop/cop/style/variable_name.rb +44 -0
- data/lib/rubocop/cop/style/when_then.rb +1 -1
- data/lib/rubocop/cop/style/while_until_do.rb +1 -1
- data/lib/rubocop/cop/team.rb +4 -7
- data/lib/rubocop/cop/util.rb +12 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/emacs_style_formatter.rb +5 -2
- data/lib/rubocop/formatter/json_formatter.rb +1 -0
- data/lib/rubocop/formatter/progress_formatter.rb +9 -13
- data/lib/rubocop/formatter/simple_text_formatter.rb +63 -15
- data/lib/rubocop/options.rb +184 -0
- data/lib/rubocop/processed_source.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +870 -1001
- data/spec/rubocop/config_spec.rb +13 -13
- data/spec/rubocop/config_store_spec.rb +38 -37
- data/spec/rubocop/cop/commissioner_spec.rb +42 -46
- data/spec/rubocop/cop/cop_spec.rb +72 -77
- data/spec/rubocop/cop/corrector_spec.rb +51 -55
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +100 -106
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +403 -409
- data/spec/rubocop/cop/lint/debugger_spec.rb +39 -0
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +19 -25
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +50 -56
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +20 -26
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +30 -36
- data/spec/rubocop/cop/lint/eval_spec.rb +25 -31
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +22 -28
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +51 -57
- data/spec/rubocop/cop/lint/loop_spec.rb +17 -23
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +51 -57
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +105 -111
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +230 -236
- data/spec/rubocop/cop/lint/syntax_spec.rb +33 -0
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +51 -57
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1544 -1550
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +21 -27
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +119 -125
- data/spec/rubocop/cop/lint/void_spec.rb +50 -56
- data/spec/rubocop/cop/offence_spec.rb +101 -131
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +6 -12
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +6 -12
- data/spec/rubocop/cop/rails/validation_spec.rb +13 -19
- data/spec/rubocop/cop/style/access_control_spec.rb +146 -152
- data/spec/rubocop/cop/style/alias_spec.rb +30 -36
- data/spec/rubocop/cop/style/align_array_spec.rb +57 -56
- data/spec/rubocop/cop/style/align_hash_spec.rb +256 -237
- data/spec/rubocop/cop/style/align_parameters_spec.rb +216 -202
- data/spec/rubocop/cop/style/and_or_spec.rb +51 -55
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +14 -20
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +26 -32
- data/spec/rubocop/cop/style/attr_spec.rb +11 -17
- data/spec/rubocop/cop/style/begin_block_spec.rb +6 -12
- data/spec/rubocop/cop/style/block_comments_spec.rb +13 -19
- data/spec/rubocop/cop/style/block_nesting_spec.rb +134 -140
- data/spec/rubocop/cop/style/blocks_spec.rb +81 -84
- data/spec/rubocop/cop/style/case_equality_spec.rb +5 -11
- data/spec/rubocop/cop/style/case_indentation_spec.rb +71 -77
- data/spec/rubocop/cop/style/character_literal_spec.rb +31 -37
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +31 -37
- data/spec/rubocop/cop/style/class_length_spec.rb +65 -0
- data/spec/rubocop/cop/style/class_methods_spec.rb +35 -41
- data/spec/rubocop/cop/style/class_vars_spec.rb +11 -17
- data/spec/rubocop/cop/style/collection_methods_spec.rb +41 -47
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +45 -51
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +79 -85
- data/spec/rubocop/cop/style/constant_name_spec.rb +45 -51
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +28 -34
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +23 -29
- data/spec/rubocop/cop/style/documentation_spec.rb +60 -66
- data/spec/rubocop/cop/style/dot_position_spec.rb +50 -56
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +109 -110
- data/spec/rubocop/cop/style/empty_lines_spec.rb +28 -34
- data/spec/rubocop/cop/style/empty_literal_spec.rb +80 -86
- data/spec/rubocop/cop/style/encoding_spec.rb +50 -56
- data/spec/rubocop/cop/style/end_block_spec.rb +6 -12
- data/spec/rubocop/cop/style/end_of_line_spec.rb +13 -19
- data/spec/rubocop/cop/style/even_odd_spec.rb +69 -41
- data/spec/rubocop/cop/style/favor_join_spec.rb +21 -27
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +180 -176
- data/spec/rubocop/cop/style/favor_sprintf_spec.rb +41 -47
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +63 -69
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +32 -38
- data/spec/rubocop/cop/style/final_newline_spec.rb +16 -22
- data/spec/rubocop/cop/style/for_spec.rb +18 -24
- data/spec/rubocop/cop/style/global_vars_spec.rb +23 -29
- data/spec/rubocop/cop/style/hash_methods_spec.rb +39 -45
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +93 -65
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +11 -17
- data/spec/rubocop/cop/style/indentation_width_spec.rb +377 -383
- data/spec/rubocop/cop/style/lambda_call_spec.rb +40 -22
- data/spec/rubocop/cop/style/lambda_spec.rb +30 -34
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +44 -50
- data/spec/rubocop/cop/style/line_length_spec.rb +11 -17
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +14 -20
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +60 -0
- data/spec/rubocop/cop/style/method_length_spec.rb +127 -133
- data/spec/rubocop/cop/style/method_name_spec.rb +103 -0
- data/spec/rubocop/cop/style/module_function_spec.rb +16 -22
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +64 -70
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +74 -80
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +20 -26
- data/spec/rubocop/cop/style/not_spec.rb +13 -19
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +36 -35
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +5 -11
- data/spec/rubocop/cop/style/op_method_spec.rb +61 -67
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +31 -37
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +62 -68
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +9 -15
- data/spec/rubocop/cop/style/proc_spec.rb +13 -19
- data/spec/rubocop/cop/style/raise_args_spec.rb +55 -0
- data/spec/rubocop/cop/style/reduce_arguments_spec.rb +49 -55
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +47 -53
- data/spec/rubocop/cop/style/redundant_exception_spec.rb +27 -0
- data/spec/rubocop/cop/style/redundant_return_spec.rb +164 -72
- data/spec/rubocop/cop/style/redundant_self_spec.rb +109 -115
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +57 -63
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +99 -105
- data/spec/rubocop/cop/style/semicolon_spec.rb +95 -90
- data/spec/rubocop/cop/style/signal_exception_spec.rb +248 -95
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +45 -51
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +14 -20
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +16 -22
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +48 -54
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +49 -55
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +10 -16
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +118 -50
- data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +18 -24
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +204 -210
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +36 -42
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +39 -45
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +62 -68
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +18 -24
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +40 -46
- data/spec/rubocop/cop/style/string_literals_spec.rb +148 -70
- data/spec/rubocop/cop/style/symbol_array_spec.rb +28 -34
- data/spec/rubocop/cop/style/symbol_name_spec.rb +132 -138
- data/spec/rubocop/cop/style/tab_spec.rb +9 -15
- data/spec/rubocop/cop/style/ternary_operator_spec.rb +25 -31
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +10 -16
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +14 -20
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +374 -380
- data/spec/rubocop/cop/style/unless_else_spec.rb +17 -23
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +36 -42
- data/spec/rubocop/cop/style/variable_name_spec.rb +83 -0
- data/spec/rubocop/cop/style/when_then_spec.rb +31 -37
- data/spec/rubocop/cop/style/while_until_do_spec.rb +47 -53
- data/spec/rubocop/cop/style/word_array_spec.rb +49 -55
- data/spec/rubocop/cop/team_spec.rb +125 -127
- data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +176 -180
- data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +580 -586
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +140 -146
- data/spec/rubocop/cop/variable_inspector/variable_spec.rb +52 -58
- data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +217 -223
- data/spec/rubocop/cop/variable_inspector_spec.rb +15 -19
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +35 -36
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +2 -2
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +24 -1
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/formatter_set_spec.rb +3 -3
- data/spec/rubocop/formatter/json_formatter_spec.rb +7 -2
- data/spec/rubocop/formatter/offence_count_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +55 -6
- data/spec/rubocop/options_spec.rb +233 -0
- data/spec/rubocop/processed_source_spec.rb +85 -42
- data/spec/rubocop/source_parser_spec.rb +108 -110
- data/spec/rubocop/target_finder_spec.rb +125 -127
- data/spec/rubocop/token_spec.rb +15 -17
- metadata +32 -8
- data/lib/rubocop/backports/bsearch.rb +0 -39
- data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +0 -77
- data/spec/rubocop/cop/style/method_and_variable_snake_case_spec.rb +0 -102
@@ -2,738 +2,732 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
describe Locatable do
|
9
|
-
include ASTHelper
|
10
|
-
include AST::Sexp
|
5
|
+
describe Rubocop::Cop::VariableInspector::Locatable do
|
6
|
+
include ASTHelper
|
7
|
+
include AST::Sexp
|
11
8
|
|
12
|
-
|
13
|
-
|
9
|
+
class LocatableObject
|
10
|
+
include Rubocop::Cop::VariableInspector::Locatable
|
14
11
|
|
15
|
-
|
12
|
+
attr_reader :node, :scope
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def initialize(node, scope)
|
15
|
+
@node = node
|
16
|
+
@scope = scope
|
17
|
+
end
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
let(:ast) do
|
21
|
+
processed_source = Rubocop::SourceParser.parse(source)
|
22
|
+
processed_source.ast
|
23
|
+
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
let(:def_node) do
|
26
|
+
found_node = scan_node(ast, include_origin_node: true) do |node|
|
27
|
+
break node if node.type == :def
|
28
|
+
end
|
29
|
+
fail 'No def node found!' unless found_node
|
30
|
+
found_node
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
let(:lvasgn_node) do
|
34
|
+
found_node = scan_node(ast) do |node|
|
35
|
+
break node if node.type == :lvasgn
|
36
|
+
end
|
37
|
+
fail 'No lvasgn node found!' unless found_node
|
38
|
+
found_node
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
41
|
+
let(:scope) { Rubocop::Cop::VariableInspector::Scope.new(def_node) }
|
42
|
+
let(:assignment) { LocatableObject.new(lvasgn_node, scope) }
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
describe '#ancestor_nodes_in_scope' do
|
45
|
+
let(:source) do
|
46
|
+
<<-END
|
47
|
+
class SomeClass
|
48
|
+
def some_method(flag)
|
49
|
+
puts 'Hello World!'
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
59
|
-
END
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns its ancestor nodes in the scope excluding scope node' do
|
63
|
-
ancestor_types = assignment.ancestor_nodes_in_scope.map(&:type)
|
64
|
-
expect(ancestor_types).to eq([:begin, :if])
|
51
|
+
if flag > 0
|
52
|
+
foo = 1
|
53
|
+
end
|
65
54
|
end
|
66
55
|
end
|
56
|
+
END
|
57
|
+
end
|
67
58
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
foo = 1
|
74
|
-
end
|
75
|
-
END
|
76
|
-
end
|
59
|
+
it 'returns its ancestor nodes in the scope excluding scope node' do
|
60
|
+
ancestor_types = assignment.ancestor_nodes_in_scope.map(&:type)
|
61
|
+
expect(ancestor_types).to eq([:begin, :if])
|
62
|
+
end
|
63
|
+
end
|
77
64
|
|
78
|
-
|
79
|
-
|
80
|
-
|
65
|
+
describe '#branch_point_node' do
|
66
|
+
context 'when it is not in branch' do
|
67
|
+
let(:source) do
|
68
|
+
<<-END
|
69
|
+
def some_method(flag)
|
70
|
+
foo = 1
|
81
71
|
end
|
72
|
+
END
|
73
|
+
end
|
82
74
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if flag
|
88
|
-
foo = 1
|
89
|
-
end
|
90
|
-
end
|
91
|
-
END
|
92
|
-
end
|
75
|
+
it 'returns nil' do
|
76
|
+
expect(assignment.branch_point_node).to be_nil
|
77
|
+
end
|
78
|
+
end
|
93
79
|
|
94
|
-
|
95
|
-
|
80
|
+
context 'when it is inside of if' do
|
81
|
+
let(:source) do
|
82
|
+
<<-END
|
83
|
+
def some_method(flag)
|
84
|
+
if flag
|
85
|
+
foo = 1
|
96
86
|
end
|
97
87
|
end
|
88
|
+
END
|
89
|
+
end
|
98
90
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
if flag
|
104
|
-
else
|
105
|
-
foo = 1
|
106
|
-
end
|
107
|
-
end
|
108
|
-
END
|
109
|
-
end
|
91
|
+
it 'returns the if node' do
|
92
|
+
expect(assignment.branch_point_node.type).to eq(:if)
|
93
|
+
end
|
94
|
+
end
|
110
95
|
|
111
|
-
|
112
|
-
|
96
|
+
context 'when it is inside of else of if' do
|
97
|
+
let(:source) do
|
98
|
+
<<-END
|
99
|
+
def some_method(flag)
|
100
|
+
if flag
|
101
|
+
else
|
102
|
+
foo = 1
|
113
103
|
end
|
114
104
|
end
|
105
|
+
END
|
106
|
+
end
|
115
107
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
if foo = 1
|
121
|
-
do_something
|
122
|
-
end
|
123
|
-
end
|
124
|
-
END
|
125
|
-
end
|
108
|
+
it 'returns the if node' do
|
109
|
+
expect(assignment.branch_point_node.type).to eq(:if)
|
110
|
+
end
|
111
|
+
end
|
126
112
|
|
127
|
-
|
128
|
-
|
113
|
+
context 'when it is inside of if condition' do
|
114
|
+
let(:source) do
|
115
|
+
<<-END
|
116
|
+
def some_method(flag)
|
117
|
+
if foo = 1
|
118
|
+
do_something
|
129
119
|
end
|
130
120
|
end
|
121
|
+
END
|
122
|
+
end
|
131
123
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
def some_method(a, b)
|
137
|
-
if a
|
138
|
-
if b
|
139
|
-
foo = 1
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
END
|
144
|
-
end
|
124
|
+
it 'returns nil' do
|
125
|
+
expect(assignment.branch_point_node).to be_nil
|
126
|
+
end
|
127
|
+
end
|
145
128
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
129
|
+
context 'when multiple if are nested' do
|
130
|
+
context 'and it is inside of inner if' do
|
131
|
+
let(:source) do
|
132
|
+
<<-END
|
133
|
+
def some_method(a, b)
|
134
|
+
if a
|
135
|
+
if b
|
136
|
+
foo = 1
|
137
|
+
end
|
151
138
|
end
|
152
139
|
end
|
140
|
+
END
|
141
|
+
end
|
153
142
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
END
|
165
|
-
end
|
143
|
+
it 'returns inner if node' do
|
144
|
+
if_node = assignment.branch_point_node
|
145
|
+
expect(if_node.type).to eq(:if)
|
146
|
+
condition_node = if_node.children.first
|
147
|
+
expect(condition_node).to eq(s(:lvar, :b))
|
148
|
+
end
|
149
|
+
end
|
166
150
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
151
|
+
context 'and it is inside of inner if condition' do
|
152
|
+
let(:source) do
|
153
|
+
<<-END
|
154
|
+
def some_method(a, b)
|
155
|
+
if a
|
156
|
+
if foo = 1
|
157
|
+
do_something
|
158
|
+
end
|
172
159
|
end
|
173
160
|
end
|
174
|
-
|
161
|
+
END
|
162
|
+
end
|
175
163
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
185
|
-
END
|
186
|
-
end
|
164
|
+
it 'returns the next outer if node' do
|
165
|
+
if_node = assignment.branch_point_node
|
166
|
+
expect(if_node.type).to eq(:if)
|
167
|
+
condition_node = if_node.children.first
|
168
|
+
expect(condition_node).to eq(s(:lvar, :a))
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
187
172
|
|
188
|
-
|
189
|
-
|
173
|
+
context 'when it is inside of when of case' do
|
174
|
+
let(:source) do
|
175
|
+
<<-END
|
176
|
+
def some_method(flag)
|
177
|
+
case flag
|
178
|
+
when 1
|
179
|
+
foo = 1
|
190
180
|
end
|
191
181
|
end
|
182
|
+
END
|
183
|
+
end
|
192
184
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
(foo = 1) && do_something
|
198
|
-
end
|
199
|
-
END
|
200
|
-
end
|
185
|
+
it 'returns the case node' do
|
186
|
+
expect(assignment.branch_point_node.type).to eq(:case)
|
187
|
+
end
|
188
|
+
end
|
201
189
|
|
202
|
-
|
203
|
-
|
204
|
-
|
190
|
+
context 'when it is on the left side of &&' do
|
191
|
+
let(:source) do
|
192
|
+
<<-END
|
193
|
+
def some_method
|
194
|
+
(foo = 1) && do_something
|
205
195
|
end
|
196
|
+
END
|
197
|
+
end
|
206
198
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
do_something && (foo = 1)
|
212
|
-
end
|
213
|
-
END
|
214
|
-
end
|
199
|
+
it 'returns nil' do
|
200
|
+
expect(assignment.branch_point_node).to be_nil
|
201
|
+
end
|
202
|
+
end
|
215
203
|
|
216
|
-
|
217
|
-
|
218
|
-
|
204
|
+
context 'when it is on the right side of &&' do
|
205
|
+
let(:source) do
|
206
|
+
<<-END
|
207
|
+
def some_method
|
208
|
+
do_something && (foo = 1)
|
219
209
|
end
|
210
|
+
END
|
211
|
+
end
|
220
212
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
(foo = 1) || do_something
|
226
|
-
end
|
227
|
-
END
|
228
|
-
end
|
213
|
+
it 'returns the and node' do
|
214
|
+
expect(assignment.branch_point_node.type).to eq(:and)
|
215
|
+
end
|
216
|
+
end
|
229
217
|
|
230
|
-
|
231
|
-
|
232
|
-
|
218
|
+
context 'when it is on the left side of ||' do
|
219
|
+
let(:source) do
|
220
|
+
<<-END
|
221
|
+
def some_method
|
222
|
+
(foo = 1) || do_something
|
233
223
|
end
|
224
|
+
END
|
225
|
+
end
|
234
226
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
do_something || (foo = 1)
|
240
|
-
end
|
241
|
-
END
|
242
|
-
end
|
227
|
+
it 'returns nil' do
|
228
|
+
expect(assignment.branch_point_node).to be_nil
|
229
|
+
end
|
230
|
+
end
|
243
231
|
|
244
|
-
|
245
|
-
|
246
|
-
|
232
|
+
context 'when it is on the right side of ||' do
|
233
|
+
let(:source) do
|
234
|
+
<<-END
|
235
|
+
def some_method
|
236
|
+
do_something || (foo = 1)
|
247
237
|
end
|
238
|
+
END
|
239
|
+
end
|
248
240
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
def some_method
|
254
|
-
do_something && do_anything && (foo = 1)
|
255
|
-
end
|
256
|
-
END
|
257
|
-
end
|
241
|
+
it 'returns the or node' do
|
242
|
+
expect(assignment.branch_point_node.type).to eq(:or)
|
243
|
+
end
|
244
|
+
end
|
258
245
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
246
|
+
context 'when multiple && are chained' do
|
247
|
+
context 'and it is on the right side of the right &&' do
|
248
|
+
let(:source) do
|
249
|
+
<<-END
|
250
|
+
def some_method
|
251
|
+
do_something && do_anything && (foo = 1)
|
265
252
|
end
|
253
|
+
END
|
254
|
+
end
|
266
255
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
end
|
256
|
+
it 'returns the right and node' do
|
257
|
+
and_node = assignment.branch_point_node
|
258
|
+
expect(and_node.type).to eq(:and)
|
259
|
+
right_side_node = and_node.children[1]
|
260
|
+
expect(right_side_node.type).to eq(:begin)
|
261
|
+
end
|
262
|
+
end
|
275
263
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
264
|
+
context 'and it is on the right side of the left &&' do
|
265
|
+
let(:source) do
|
266
|
+
<<-END
|
267
|
+
def some_method
|
268
|
+
do_something && (foo = 1) && do_anything
|
282
269
|
end
|
283
|
-
|
270
|
+
END
|
271
|
+
end
|
284
272
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
end
|
294
|
-
end
|
295
|
-
END
|
296
|
-
end
|
273
|
+
it 'returns the left and node' do
|
274
|
+
and_node = assignment.branch_point_node
|
275
|
+
expect(and_node.type).to eq(:and)
|
276
|
+
right_side_node = and_node.children[1]
|
277
|
+
expect(right_side_node.type).to eq(:begin)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
297
281
|
|
298
|
-
|
299
|
-
|
282
|
+
context 'when it is inside of begin with rescue' do
|
283
|
+
let(:source) do
|
284
|
+
<<-END
|
285
|
+
def some_method(flag)
|
286
|
+
begin
|
287
|
+
foo = 1
|
288
|
+
rescue
|
289
|
+
do_something
|
300
290
|
end
|
301
291
|
end
|
292
|
+
END
|
293
|
+
end
|
302
294
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
begin
|
308
|
-
do_something
|
309
|
-
rescue
|
310
|
-
foo = 1
|
311
|
-
end
|
312
|
-
end
|
313
|
-
END
|
314
|
-
end
|
295
|
+
it 'returns the rescue node' do
|
296
|
+
expect(assignment.branch_point_node.type).to eq(:rescue)
|
297
|
+
end
|
298
|
+
end
|
315
299
|
|
316
|
-
|
317
|
-
|
300
|
+
context 'when it is inside of rescue' do
|
301
|
+
let(:source) do
|
302
|
+
<<-END
|
303
|
+
def some_method(flag)
|
304
|
+
begin
|
305
|
+
do_something
|
306
|
+
rescue
|
307
|
+
foo = 1
|
318
308
|
end
|
319
309
|
end
|
310
|
+
END
|
311
|
+
end
|
320
312
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
begin
|
326
|
-
foo = 1
|
327
|
-
ensure
|
328
|
-
do_something
|
329
|
-
end
|
330
|
-
end
|
331
|
-
END
|
332
|
-
end
|
313
|
+
it 'returns the rescue node' do
|
314
|
+
expect(assignment.branch_point_node.type).to eq(:rescue)
|
315
|
+
end
|
316
|
+
end
|
333
317
|
|
334
|
-
|
335
|
-
|
318
|
+
context 'when it is inside of begin with ensure' do
|
319
|
+
let(:source) do
|
320
|
+
<<-END
|
321
|
+
def some_method(flag)
|
322
|
+
begin
|
323
|
+
foo = 1
|
324
|
+
ensure
|
325
|
+
do_something
|
336
326
|
end
|
337
327
|
end
|
328
|
+
END
|
329
|
+
end
|
338
330
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
begin
|
344
|
-
do_something
|
345
|
-
ensure
|
346
|
-
foo = 1
|
347
|
-
end
|
348
|
-
end
|
349
|
-
END
|
350
|
-
end
|
331
|
+
it 'returns the ensure node' do
|
332
|
+
expect(assignment.branch_point_node.type).to eq(:ensure)
|
333
|
+
end
|
334
|
+
end
|
351
335
|
|
352
|
-
|
353
|
-
|
336
|
+
context 'when it is inside of ensure' do
|
337
|
+
let(:source) do
|
338
|
+
<<-END
|
339
|
+
def some_method(flag)
|
340
|
+
begin
|
341
|
+
do_something
|
342
|
+
ensure
|
343
|
+
foo = 1
|
354
344
|
end
|
355
345
|
end
|
346
|
+
END
|
347
|
+
end
|
356
348
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
begin
|
362
|
-
foo = 1
|
363
|
-
end
|
364
|
-
end
|
365
|
-
END
|
366
|
-
end
|
349
|
+
it 'returns nil' do
|
350
|
+
expect(assignment.branch_point_node).to be_nil
|
351
|
+
end
|
352
|
+
end
|
367
353
|
|
368
|
-
|
369
|
-
|
354
|
+
context 'when it is inside of begin without rescue' do
|
355
|
+
let(:source) do
|
356
|
+
<<-END
|
357
|
+
def some_method(flag)
|
358
|
+
begin
|
359
|
+
foo = 1
|
370
360
|
end
|
371
361
|
end
|
372
|
-
|
362
|
+
END
|
363
|
+
end
|
373
364
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
foo = 1
|
380
|
-
end
|
381
|
-
END
|
382
|
-
end
|
365
|
+
it 'returns nil' do
|
366
|
+
expect(assignment.branch_point_node).to be_nil
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
383
370
|
|
384
|
-
|
385
|
-
|
386
|
-
|
371
|
+
describe '#branch_body_node' do
|
372
|
+
context 'when it is not in branch' do
|
373
|
+
let(:source) do
|
374
|
+
<<-END
|
375
|
+
def some_method(flag)
|
376
|
+
foo = 1
|
387
377
|
end
|
378
|
+
END
|
379
|
+
end
|
388
380
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
if flag
|
394
|
-
foo = 1
|
395
|
-
puts foo
|
396
|
-
end
|
397
|
-
end
|
398
|
-
END
|
399
|
-
end
|
381
|
+
it 'returns nil' do
|
382
|
+
expect(assignment.branch_body_node).to be_nil
|
383
|
+
end
|
384
|
+
end
|
400
385
|
|
401
|
-
|
402
|
-
|
386
|
+
context 'when it is inside body of if' do
|
387
|
+
let(:source) do
|
388
|
+
<<-END
|
389
|
+
def some_method(flag)
|
390
|
+
if flag
|
391
|
+
foo = 1
|
392
|
+
puts foo
|
403
393
|
end
|
404
394
|
end
|
395
|
+
END
|
396
|
+
end
|
405
397
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
if flag
|
411
|
-
do_something
|
412
|
-
else
|
413
|
-
foo = 1
|
414
|
-
puts foo
|
415
|
-
end
|
416
|
-
end
|
417
|
-
END
|
418
|
-
end
|
398
|
+
it 'returns the body node' do
|
399
|
+
expect(assignment.branch_body_node.type).to eq(:begin)
|
400
|
+
end
|
401
|
+
end
|
419
402
|
|
420
|
-
|
421
|
-
|
403
|
+
context 'when it is inside body of else of if' do
|
404
|
+
let(:source) do
|
405
|
+
<<-END
|
406
|
+
def some_method(flag)
|
407
|
+
if flag
|
408
|
+
do_something
|
409
|
+
else
|
410
|
+
foo = 1
|
411
|
+
puts foo
|
422
412
|
end
|
423
413
|
end
|
414
|
+
END
|
415
|
+
end
|
424
416
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
do_something && (foo = 1)
|
430
|
-
end
|
431
|
-
END
|
432
|
-
end
|
417
|
+
it 'returns the body node' do
|
418
|
+
expect(assignment.branch_body_node.type).to eq(:begin)
|
419
|
+
end
|
420
|
+
end
|
433
421
|
|
434
|
-
|
435
|
-
|
436
|
-
|
422
|
+
context 'when it is on the right side of &&' do
|
423
|
+
let(:source) do
|
424
|
+
<<-END
|
425
|
+
def some_method
|
426
|
+
do_something && (foo = 1)
|
437
427
|
end
|
428
|
+
END
|
429
|
+
end
|
438
430
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
do_something || (foo = 1)
|
444
|
-
end
|
445
|
-
END
|
446
|
-
end
|
431
|
+
it 'returns the right side node' do
|
432
|
+
expect(assignment.branch_body_node.type).to eq(:begin)
|
433
|
+
end
|
434
|
+
end
|
447
435
|
|
448
|
-
|
449
|
-
|
450
|
-
|
436
|
+
context 'when it is on the right side of ||' do
|
437
|
+
let(:source) do
|
438
|
+
<<-END
|
439
|
+
def some_method
|
440
|
+
do_something || (foo = 1)
|
451
441
|
end
|
442
|
+
END
|
443
|
+
end
|
452
444
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
begin
|
458
|
-
foo = 1
|
459
|
-
rescue
|
460
|
-
do_something
|
461
|
-
end
|
462
|
-
end
|
463
|
-
END
|
464
|
-
end
|
445
|
+
it 'returns the right side node' do
|
446
|
+
expect(assignment.branch_body_node.type).to eq(:begin)
|
447
|
+
end
|
448
|
+
end
|
465
449
|
|
466
|
-
|
467
|
-
|
450
|
+
context 'when it is inside of begin with rescue' do
|
451
|
+
let(:source) do
|
452
|
+
<<-END
|
453
|
+
def some_method(flag)
|
454
|
+
begin
|
455
|
+
foo = 1
|
456
|
+
rescue
|
457
|
+
do_something
|
468
458
|
end
|
469
459
|
end
|
460
|
+
END
|
461
|
+
end
|
470
462
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
begin
|
476
|
-
do_something
|
477
|
-
rescue
|
478
|
-
foo = 1
|
479
|
-
end
|
480
|
-
end
|
481
|
-
END
|
482
|
-
end
|
463
|
+
it 'returns the body node' do
|
464
|
+
expect(assignment.branch_body_node.type).to eq(:lvasgn)
|
465
|
+
end
|
466
|
+
end
|
483
467
|
|
484
|
-
|
485
|
-
|
468
|
+
context 'when it is inside of rescue' do
|
469
|
+
let(:source) do
|
470
|
+
<<-END
|
471
|
+
def some_method(flag)
|
472
|
+
begin
|
473
|
+
do_something
|
474
|
+
rescue
|
475
|
+
foo = 1
|
486
476
|
end
|
487
477
|
end
|
478
|
+
END
|
479
|
+
end
|
488
480
|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
begin
|
494
|
-
foo = 1
|
495
|
-
ensure
|
496
|
-
do_something
|
497
|
-
end
|
498
|
-
end
|
499
|
-
END
|
500
|
-
end
|
481
|
+
it 'returns the resbody node' do
|
482
|
+
expect(assignment.branch_body_node.type).to eq(:resbody)
|
483
|
+
end
|
484
|
+
end
|
501
485
|
|
502
|
-
|
503
|
-
|
486
|
+
context 'when it is inside of begin with ensure' do
|
487
|
+
let(:source) do
|
488
|
+
<<-END
|
489
|
+
def some_method(flag)
|
490
|
+
begin
|
491
|
+
foo = 1
|
492
|
+
ensure
|
493
|
+
do_something
|
504
494
|
end
|
505
495
|
end
|
506
|
-
|
496
|
+
END
|
497
|
+
end
|
507
498
|
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
foo = 1
|
514
|
-
end
|
515
|
-
END
|
516
|
-
end
|
499
|
+
it 'returns the body node' do
|
500
|
+
expect(assignment.branch_body_node.type).to eq(:lvasgn)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
end
|
517
504
|
|
518
|
-
|
519
|
-
|
520
|
-
|
505
|
+
describe '#branch_id' do
|
506
|
+
context 'when it is not in branch' do
|
507
|
+
let(:source) do
|
508
|
+
<<-END
|
509
|
+
def some_method(flag)
|
510
|
+
foo = 1
|
521
511
|
end
|
512
|
+
END
|
513
|
+
end
|
522
514
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
if flag
|
528
|
-
foo = 1
|
529
|
-
puts foo
|
530
|
-
end
|
531
|
-
end
|
532
|
-
END
|
533
|
-
end
|
515
|
+
it 'returns nil' do
|
516
|
+
expect(assignment.branch_id).to be_nil
|
517
|
+
end
|
518
|
+
end
|
534
519
|
|
535
|
-
|
536
|
-
|
520
|
+
context 'when it is inside body of if' do
|
521
|
+
let(:source) do
|
522
|
+
<<-END
|
523
|
+
def some_method(flag)
|
524
|
+
if flag
|
525
|
+
foo = 1
|
526
|
+
puts foo
|
537
527
|
end
|
538
528
|
end
|
529
|
+
END
|
530
|
+
end
|
539
531
|
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
if flag
|
545
|
-
do_something
|
546
|
-
else
|
547
|
-
foo = 1
|
548
|
-
puts foo
|
549
|
-
end
|
550
|
-
end
|
551
|
-
END
|
552
|
-
end
|
532
|
+
it 'returns BRANCHNODEID_if_true' do
|
533
|
+
expect(assignment.branch_id).to match(/^\d+_if_true/)
|
534
|
+
end
|
535
|
+
end
|
553
536
|
|
554
|
-
|
555
|
-
|
537
|
+
context 'when it is inside body of else of if' do
|
538
|
+
let(:source) do
|
539
|
+
<<-END
|
540
|
+
def some_method(flag)
|
541
|
+
if flag
|
542
|
+
do_something
|
543
|
+
else
|
544
|
+
foo = 1
|
545
|
+
puts foo
|
556
546
|
end
|
557
547
|
end
|
548
|
+
END
|
549
|
+
end
|
558
550
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
case flag
|
564
|
-
when first
|
565
|
-
do_something
|
566
|
-
when second
|
567
|
-
foo = 1
|
568
|
-
puts foo
|
569
|
-
else
|
570
|
-
do_something
|
571
|
-
end
|
572
|
-
end
|
573
|
-
END
|
574
|
-
end
|
551
|
+
it 'returns BRANCHNODEID_if_false' do
|
552
|
+
expect(assignment.branch_id).to match(/^\d+_if_false/)
|
553
|
+
end
|
554
|
+
end
|
575
555
|
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
556
|
+
context 'when it is inside body of when of case' do
|
557
|
+
let(:source) do
|
558
|
+
<<-END
|
559
|
+
def some_method(flag)
|
560
|
+
case flag
|
561
|
+
when first
|
562
|
+
do_something
|
563
|
+
when second
|
564
|
+
foo = 1
|
565
|
+
puts foo
|
566
|
+
else
|
567
|
+
do_something
|
568
|
+
end
|
569
|
+
end
|
570
|
+
END
|
571
|
+
end
|
580
572
|
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
case flag
|
586
|
-
when first
|
587
|
-
do_something
|
588
|
-
when second
|
589
|
-
do_something
|
590
|
-
else
|
591
|
-
foo = 1
|
592
|
-
puts foo
|
593
|
-
end
|
594
|
-
end
|
595
|
-
END
|
596
|
-
end
|
573
|
+
it 'returns BRANCHNODEID_case_whenINDEX' do
|
574
|
+
expect(assignment.branch_id).to match(/^\d+_case_when1/)
|
575
|
+
end
|
576
|
+
end
|
597
577
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
578
|
+
context 'when it is inside body of when of case' do
|
579
|
+
let(:source) do
|
580
|
+
<<-END
|
581
|
+
def some_method(flag)
|
582
|
+
case flag
|
583
|
+
when first
|
584
|
+
do_something
|
585
|
+
when second
|
586
|
+
do_something
|
587
|
+
else
|
588
|
+
foo = 1
|
589
|
+
puts foo
|
590
|
+
end
|
591
|
+
end
|
592
|
+
END
|
593
|
+
end
|
602
594
|
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
(foo = 1) && do_something
|
608
|
-
end
|
609
|
-
END
|
610
|
-
end
|
595
|
+
it 'returns BRANCHNODEID_case_else' do
|
596
|
+
expect(assignment.branch_id).to match(/^\d+_case_else/)
|
597
|
+
end
|
598
|
+
end
|
611
599
|
|
612
|
-
|
613
|
-
|
614
|
-
|
600
|
+
context 'when it is on the left side of &&' do
|
601
|
+
let(:source) do
|
602
|
+
<<-END
|
603
|
+
def some_method
|
604
|
+
(foo = 1) && do_something
|
615
605
|
end
|
606
|
+
END
|
607
|
+
end
|
616
608
|
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
do_something && (foo = 1)
|
622
|
-
end
|
623
|
-
END
|
624
|
-
end
|
609
|
+
it 'returns nil' do
|
610
|
+
expect(assignment.branch_id).to be_nil
|
611
|
+
end
|
612
|
+
end
|
625
613
|
|
626
|
-
|
627
|
-
|
628
|
-
|
614
|
+
context 'when it is on the right side of &&' do
|
615
|
+
let(:source) do
|
616
|
+
<<-END
|
617
|
+
def some_method
|
618
|
+
do_something && (foo = 1)
|
629
619
|
end
|
620
|
+
END
|
621
|
+
end
|
630
622
|
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
(foo = 1) || do_something
|
636
|
-
end
|
637
|
-
END
|
638
|
-
end
|
623
|
+
it 'returns BRANCHNODEID_and_right' do
|
624
|
+
expect(assignment.branch_id).to match(/^\d+_and_right/)
|
625
|
+
end
|
626
|
+
end
|
639
627
|
|
640
|
-
|
641
|
-
|
642
|
-
|
628
|
+
context 'when it is on the left side of ||' do
|
629
|
+
let(:source) do
|
630
|
+
<<-END
|
631
|
+
def some_method
|
632
|
+
(foo = 1) || do_something
|
643
633
|
end
|
634
|
+
END
|
635
|
+
end
|
644
636
|
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
do_something || (foo = 1)
|
650
|
-
end
|
651
|
-
END
|
652
|
-
end
|
637
|
+
it 'returns nil' do
|
638
|
+
expect(assignment.branch_id).to be_nil
|
639
|
+
end
|
640
|
+
end
|
653
641
|
|
654
|
-
|
655
|
-
|
656
|
-
|
642
|
+
context 'when it is on the right side of ||' do
|
643
|
+
let(:source) do
|
644
|
+
<<-END
|
645
|
+
def some_method
|
646
|
+
do_something || (foo = 1)
|
657
647
|
end
|
648
|
+
END
|
649
|
+
end
|
658
650
|
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
begin
|
664
|
-
foo = 1
|
665
|
-
rescue
|
666
|
-
do_something
|
667
|
-
end
|
668
|
-
end
|
669
|
-
END
|
670
|
-
end
|
651
|
+
it 'returns BRANCHNODEID_or_right' do
|
652
|
+
expect(assignment.branch_id).to match(/^\d+_or_right/)
|
653
|
+
end
|
654
|
+
end
|
671
655
|
|
672
|
-
|
673
|
-
|
656
|
+
context 'when it is inside of begin with rescue' do
|
657
|
+
let(:source) do
|
658
|
+
<<-END
|
659
|
+
def some_method(flag)
|
660
|
+
begin
|
661
|
+
foo = 1
|
662
|
+
rescue
|
663
|
+
do_something
|
674
664
|
end
|
675
665
|
end
|
666
|
+
END
|
667
|
+
end
|
676
668
|
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
begin
|
682
|
-
do_something
|
683
|
-
rescue FirstError
|
684
|
-
do_something
|
685
|
-
rescue SecondError
|
686
|
-
foo = 1
|
687
|
-
end
|
688
|
-
end
|
689
|
-
END
|
690
|
-
end
|
669
|
+
it 'returns BRANCHNODEID_rescue_main' do
|
670
|
+
expect(assignment.branch_id).to match(/^\d+_rescue_main/)
|
671
|
+
end
|
672
|
+
end
|
691
673
|
|
692
|
-
|
693
|
-
|
674
|
+
context 'when it is inside of rescue' do
|
675
|
+
let(:source) do
|
676
|
+
<<-END
|
677
|
+
def some_method(flag)
|
678
|
+
begin
|
679
|
+
do_something
|
680
|
+
rescue FirstError
|
681
|
+
do_something
|
682
|
+
rescue SecondError
|
683
|
+
foo = 1
|
694
684
|
end
|
695
685
|
end
|
686
|
+
END
|
687
|
+
end
|
696
688
|
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
begin
|
702
|
-
do_something
|
703
|
-
rescue FirstError
|
704
|
-
do_something
|
705
|
-
rescue SecondError
|
706
|
-
do_something
|
707
|
-
else
|
708
|
-
foo = 1
|
709
|
-
end
|
710
|
-
end
|
711
|
-
END
|
712
|
-
end
|
689
|
+
it 'returns BRANCHNODEID_rescue_rescueINDEX' do
|
690
|
+
expect(assignment.branch_id).to match(/^\d+_rescue_rescue1/)
|
691
|
+
end
|
692
|
+
end
|
713
693
|
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
694
|
+
context 'when it is inside of else of rescue' do
|
695
|
+
let(:source) do
|
696
|
+
<<-END
|
697
|
+
def some_method(flag)
|
698
|
+
begin
|
699
|
+
do_something
|
700
|
+
rescue FirstError
|
701
|
+
do_something
|
702
|
+
rescue SecondError
|
703
|
+
do_something
|
704
|
+
else
|
705
|
+
foo = 1
|
706
|
+
end
|
707
|
+
end
|
708
|
+
END
|
709
|
+
end
|
718
710
|
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
begin
|
724
|
-
foo = 1
|
725
|
-
ensure
|
726
|
-
do_something
|
727
|
-
end
|
728
|
-
end
|
729
|
-
END
|
730
|
-
end
|
711
|
+
it 'returns BRANCHNODEID_rescue_else' do
|
712
|
+
expect(assignment.branch_id).to match(/^\d+_rescue_else/)
|
713
|
+
end
|
714
|
+
end
|
731
715
|
|
732
|
-
|
733
|
-
|
716
|
+
context 'when it is inside of begin with ensure' do
|
717
|
+
let(:source) do
|
718
|
+
<<-END
|
719
|
+
def some_method(flag)
|
720
|
+
begin
|
721
|
+
foo = 1
|
722
|
+
ensure
|
723
|
+
do_something
|
734
724
|
end
|
735
725
|
end
|
736
|
-
|
726
|
+
END
|
727
|
+
end
|
728
|
+
|
729
|
+
it 'returns BRANCHNODEID_ensure_main' do
|
730
|
+
expect(assignment.branch_id).to match(/^\d+_ensure_main/)
|
737
731
|
end
|
738
732
|
end
|
739
733
|
end
|