]> code.delx.au - gnu-emacs-elpa/blob - packages/company/test/transformers-tests.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / company / test / transformers-tests.el
1 ;;; transformers-tests.el --- company-mode tests -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Author: Dmitry Gutov
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 (require 'company-tests)
23
24 (ert-deftest company-occurrence-prefer-closest-above ()
25 (with-temp-buffer
26 (save-window-excursion
27 (set-window-buffer nil (current-buffer))
28 (insert "foo0
29 foo1
30 ")
31 (save-excursion
32 (insert "
33 foo3
34 foo2"))
35 (let ((company-backend 'company-dabbrev)
36 (company-occurrence-weight-function
37 'company-occurrence-prefer-closest-above))
38 (should (equal '("foo1" "foo0" "foo3" "foo2" "foo4")
39 (company-sort-by-occurrence
40 '("foo0" "foo1" "foo2" "foo3" "foo4"))))))))
41
42 (ert-deftest company-occurrence-prefer-any-closest ()
43 (with-temp-buffer
44 (save-window-excursion
45 (set-window-buffer nil (current-buffer))
46 (insert "foo0
47 foo1
48 ")
49 (save-excursion
50 (insert "
51 foo3
52 foo2"))
53 (let ((company-backend 'company-dabbrev)
54 (company-occurrence-weight-function
55 'company-occurrence-prefer-any-closest))
56 (should (equal '("foo1" "foo3" "foo0" "foo2" "foo4")
57 (company-sort-by-occurrence
58 '("foo0" "foo1" "foo2" "foo3" "foo4"))))))))