Skip to content

Commit 527ec1a

Browse files
committed
Don't fail on missing language
1 parent 4d7b459 commit 527ec1a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/snippet_extractor/extract_snippet.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ class ExtractSnippet
55
initialize_with :code, :language
66

77
def call
8+
processed_lines[0...10].join
9+
end
10+
11+
private
12+
def processed_lines
813
lines.drop_while do |line|
914
naked_line = line.strip
1015
next true if naked_line.empty?
1116
next true if ignore_list.any? { |ignore| naked_line.start_with?(ignore) }
1217

1318
false
14-
end[0...10].join
19+
end
20+
rescue Errno::ENOENT
21+
lines
1522
end
1623

1724
def lines

test/extract_snippet_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,38 @@
33
module SnippetExtractor
44
module Languages
55
class RubyTest < Minitest::Test
6+
def test_returns_first_10_loc_on_missing_language
7+
code = <<~CODE
8+
Loc 1
9+
Loc 2
10+
Loc 3
11+
Loc 4
12+
Loc 5
13+
Loc 6
14+
Loc 6
15+
Loc 8
16+
Loc 9
17+
Loc 10
18+
Loc 11
19+
Loc 12
20+
CODE
21+
22+
expected = <<~CODE
23+
Loc 1
24+
Loc 2
25+
Loc 3
26+
Loc 4
27+
Loc 5
28+
Loc 6
29+
Loc 6
30+
Loc 8
31+
Loc 9
32+
Loc 10
33+
CODE
34+
35+
assert_equal expected, ExtractSnippet.(code, :foobar)
36+
end
37+
638
def test_strips_correctly
739
code = <<~CODE
840
# This is a file

0 commit comments

Comments
 (0)