File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed
lib/rspec/parameterized/core Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -33,10 +33,34 @@ def self.to_raw_source_with_parser(obj)
3333 # @param obj [Object]
3434 # @return [String]
3535 def self . to_raw_source_with_prism ( obj )
36- # TODO: Impl
37- raise "TODO: Impl"
36+ return obj . inspect unless obj . is_a? ( Proc )
37+
38+ filename , linenum = obj . source_location
39+ ast = parse_with_prism ( filename , linenum )
40+
41+ return "" unless ast
42+
43+ ast . source . source . strip
3844 end
3945 private_class_method :to_raw_source_with_prism
46+
47+ # @param filename [String]
48+ # @param linenum [Integer]
49+ #
50+ # @return [Prism::ParseResult,nil]
51+ def self . parse_with_prism ( filename , linenum )
52+ buf = [ ]
53+ File . open ( filename , "rb" ) . each_with_index do |line , index |
54+ next if index < linenum - 1
55+ buf << line
56+
57+ ret = Prism . parse ( buf . join ( "\n " ) )
58+ return ret if ret . success?
59+ end
60+
61+ nil
62+ end
63+ private_class_method :parse_with_prism
4064 end
4165 end
4266 end
You can’t perform that action at this time.
0 commit comments