|
| 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