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)
33
33
# @param obj [Object]
34
34
# @return [String]
35
35
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
38
44
end
39
45
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
40
64
end
41
65
end
42
66
end
You can’t perform that action at this time.
0 commit comments