From 34724c7969bec230d4f86a6628d2634bdfac50b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Thu, 4 Jun 2015 23:00:24 +0500 Subject: [PATCH 1/2] Define blank completions package and completions tests package Also add haskell-completions.el to Makefile --- Makefile | 1 + haskell-completions.el | 32 ++++++++++++++++++++++++++++++ tests/haskell-completions-tests.el | 31 +++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 haskell-completions.el create mode 100644 tests/haskell-completions-tests.el diff --git a/Makefile b/Makefile index 57fc426fa..e8cb10556 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ ELFILES = \ haskell-compat.el \ haskell-compile.el \ haskell-complete-module.el \ + haskell-completions.el \ haskell-customize.el \ haskell-debug.el \ haskell-decl-scan.el \ diff --git a/haskell-completions.el b/haskell-completions.el new file mode 100644 index 000000000..45e50ac2d --- /dev/null +++ b/haskell-completions.el @@ -0,0 +1,32 @@ +;;; haskell-completions.el --- Haskell Completion package + +;; Copyright © 2015 Athur Fayzrakhmanov. All rights reserved. + +;; This file is part of haskell-mode package. +;; You can contact with authors using GitHub issue tracker: +;; https://github.com/haskell/haskell-mode/issues + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; This package provides completions related functionality for +;; Haskell Mode such grab completion prefix at point, and etc.. + +;;; Code: + +(provide 'haskell-completions) +;;; haskell-completions.el ends here diff --git a/tests/haskell-completions-tests.el b/tests/haskell-completions-tests.el new file mode 100644 index 000000000..ea0efb9ac --- /dev/null +++ b/tests/haskell-completions-tests.el @@ -0,0 +1,31 @@ +;;; haskell-completions-tests.el --- Tests for Haskell Completion package + +;; Copyright © 2015 Athur Fayzrakhmanov. All rights reserved. + +;; This file is part of haskell-mode package. +;; You can contact with authors using GitHub issue tracker: +;; https://github.com/haskell/haskell-mode/issues + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; This package provides regression tests for haskell-completions package. + +;;; Code: + +(provide 'haskell-completions-tests) +;;; haskell-completions-tests.el ends here From aa3c7ab595d730c234b7c07c1d5184c246af6603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Thu, 4 Jun 2015 23:05:18 +0500 Subject: [PATCH 2/2] Define prefix grabbing predicate and its tests --- haskell-completions.el | 14 ++++++++++ tests/haskell-completions-tests.el | 43 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/haskell-completions.el b/haskell-completions.el index 45e50ac2d..5709a9867 100644 --- a/haskell-completions.el +++ b/haskell-completions.el @@ -28,5 +28,19 @@ ;;; Code: +(defun haskell-completions-can-grab-prefix () + "Check if the case is appropriate for grabbing completion prefix. +Returns t if point is either at whitespace character, or at +punctuation, or at line end and preceeding character is not a +whitespace or new line, otherwise returns nil. + + Returns nil in presense of active region." + (when (not (region-active-p)) + (when (looking-at (rx (| space line-end punct))) + (when (not (bobp)) + (save-excursion + (backward-char) + (not (looking-at (rx (| space line-end))))))))) + (provide 'haskell-completions) ;;; haskell-completions.el ends here diff --git a/tests/haskell-completions-tests.el b/tests/haskell-completions-tests.el index ea0efb9ac..b8c40b364 100644 --- a/tests/haskell-completions-tests.el +++ b/tests/haskell-completions-tests.el @@ -27,5 +27,48 @@ ;;; Code: +(require 'ert) +(require 'haskell-mode) +(require 'haskell-completions) + + +(ert-deftest haskell-completions-can-grab-prefix-test () + "Tests the function `haskell-completions-can-grab-prefix'." + (with-temp-buffer + (haskell-mode) + (should (eql nil (haskell-completions-can-grab-prefix))) + (insert " ") + (should (eql nil (haskell-completions-can-grab-prefix))) + (insert "a") + (should (eql t (haskell-completions-can-grab-prefix))) + (save-excursion + (insert " ") + (should (eql nil (haskell-completions-can-grab-prefix))) + (insert "bc-") + (should (eql t (haskell-completions-can-grab-prefix))) + (insert "\n") + (should (eql nil (haskell-completions-can-grab-prefix))) + (insert "def:#!") + (should (eql t (haskell-completions-can-grab-prefix)))) + (should (eql t (haskell-completions-can-grab-prefix))) + ;; punctuation tests + (save-excursion (insert ")")) + (should (eql t (haskell-completions-can-grab-prefix))) + (save-excursion (insert ",")) + (should (eql t (haskell-completions-can-grab-prefix))) + (save-excursion (insert "'")) + (should (eql t (haskell-completions-can-grab-prefix))) + ;; should return nil in the middle of word + (save-excursion (insert "bcd")) + (should (eql nil (haskell-completions-can-grab-prefix))) + ;; region case + (let ((p (point))) + (goto-char (point-min)) + (push-mark) + (goto-char p) + (activate-mark) + (should (eql nil (haskell-completions-can-grab-prefix)))))) + + (provide 'haskell-completions-tests) ;;; haskell-completions-tests.el ends here