File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class Analyze < ExerciseAnalyzer
33 include Mandate
44
55 def analyze!
6- if solution . uses_method_chain? || solution . uses_scan?
6+ if solution . uses_method_chain? || solution . uses_scan? || solution . uses_split?
77 self . status = :approve
88
99 raise FinishedFlowControlException
Original file line number Diff line number Diff line change @@ -39,6 +39,34 @@ def uses_scan?
3939 all? { |node , i | node_matches? ( node , matchers [ i ] ) }
4040 end
4141
42+ def uses_split?
43+ matchers = [
44+ {
45+ method_name : :upcase ,
46+ } ,
47+ {
48+ method_name : :join ,
49+ chained? : true
50+ } ,
51+ {
52+ method_name : :map ,
53+ chained? : true ,
54+ arguments : [ { to_ast : s ( :block_pass , s ( :sym , :chr ) ) } ]
55+ } ,
56+ {
57+ method_name : :split ,
58+ receiver : s ( :lvar , :words ) ,
59+ arguments : [ { type : :regexp } ]
60+ }
61+ ]
62+
63+ target_method .
64+ body .
65+ each_node ( :send ) .
66+ with_index .
67+ all? { |node , i | node_matches? ( node , matchers [ i ] ) }
68+ end
69+
4270 private
4371 memoize
4472 def target_method
Original file line number Diff line number Diff line change @@ -27,4 +27,17 @@ def self.abbreviate(words)
2727 assert_equal :approve , results [ :status ]
2828 assert_equal [ ] , results [ :comments ]
2929 end
30+
31+ def test_split_with_any_regex_passes
32+ source = %q{
33+ class Acronym
34+ def self.abbreviate(words)
35+ words.split(/[ -]/).map(&:chr).join.upcase
36+ end
37+ end
38+ }
39+ results = Acronym ::Analyze . ( source )
40+ assert_equal :approve , results [ :status ]
41+ assert_equal [ ] , results [ :comments ]
42+ end
3043end
You can’t perform that action at this time.
0 commit comments