Skip to content

Commit ab4eb1c

Browse files
authored
Add Emacs Lisp language (#67)
* Add Emacs Lisp language * Stop after first LOC
1 parent 4c74815 commit ab4eb1c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

lib/languages/emacs-lisp.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!e stop_at_first_loc
2+
;\p
3+
(require\p

test/languages/emacs_lisp_test.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require "test_helper"
2+
3+
module SnippetExtractor
4+
module Languages
5+
class EmacsLispTest < Minitest::Test
6+
def test_full_example
7+
# rubocop:disable Layout/TrailingWhitespace
8+
code = <<~CODE
9+
;;; sublist.el --- Sublist (exercism) -*- lexical-binding: t; -*-
10+
11+
;;; Commentary:
12+
13+
;;; Code:
14+
15+
(require 'cl-lib)
16+
17+
(defun list--partition (list cell-size)
18+
(cl-loop for index from 0
19+
;; we can ignore the rest because this can never contain our sublist
20+
while (<= index (- (length list) cell-size))
21+
collect (cl-subseq list index (+ index cell-size))))
22+
23+
(defun list-sublist (list1 list2)
24+
(cl-some (lambda (partition)
25+
(equal list1 partition))
26+
(list--partition list2 (length list1))))
27+
28+
(defun list-classify (list1 list2)
29+
(cond ((equal list1 list2) :equal)
30+
((list-sublist list2 list1) :superlist)
31+
((list-sublist list1 list2) :sublist)
32+
('t :unequal)))
33+
34+
(provide 'sublist)
35+
;;; sublist.el ends here
36+
CODE
37+
38+
expected = <<~CODE
39+
(defun list--partition (list cell-size)
40+
(cl-loop for index from 0
41+
;; we can ignore the rest because this can never contain our sublist
42+
while (<= index (- (length list) cell-size))
43+
collect (cl-subseq list index (+ index cell-size))))
44+
45+
(defun list-sublist (list1 list2)
46+
(cl-some (lambda (partition)
47+
(equal list1 partition))
48+
(list--partition list2 (length list1))))
49+
CODE
50+
# rubocop:enable Layout/TrailingWhitespace
51+
52+
assert_equal expected, ExtractSnippet.(code, 'emacs-lisp')
53+
end
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)