From 92926b70f9ff26e1266641f8239db4c6bf74841d 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: Sat, 16 Jan 2016 23:16:22 +0500 Subject: [PATCH 1/4] Untabify file --- tests/haskell-utils-tests.el | 120 +++++++++++++++++------------------ 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/tests/haskell-utils-tests.el b/tests/haskell-utils-tests.el index faad5ea70..3b1af79cc 100644 --- a/tests/haskell-utils-tests.el +++ b/tests/haskell-utils-tests.el @@ -7,96 +7,96 @@ (ert-deftest simple-import-parse () (should (equal "A.B.C" - (with-temp-buffer - (insert-lines "import A.B.C") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import A.B.C") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest qualified-import-parse () (should (equal "A.B.C" - (with-temp-buffer - (insert-lines "import qualified A.B.C") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import qualified A.B.C") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest qualified-as-import-parse () (should (equal "AAA.Bc.Cx" - (with-temp-buffer - (insert-lines "import qualified AAA.Bc.Cx as Something") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import qualified AAA.Bc.Cx as Something") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest international-characters-import-parse () (should (equal "Żółć" - (with-temp-buffer - (insert-lines "import Żółć") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import Żółć") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest commented-out-import-parse () (should (equal nil - (with-temp-buffer - (insert-lines "-- import Nothing") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "-- import Nothing") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest non-import-import-parse () (should (equal nil - (with-temp-buffer - (insert-lines "something import Nothing") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "something import Nothing") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest many-spaces-import-parse () (should (equal "M" - (with-temp-buffer - (insert-lines "\t import\t qualified \t\tM\tas G") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "\t import\t qualified \t\tM\tas G") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest using-underscores-import-parse () (should (equal "Module_1.S_3_3_" - (with-temp-buffer - (insert-lines "import Module_1.S_3_3_") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import Module_1.S_3_3_") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest slightly-malformed-import-parse () (should (equal "q.Module...qwerqwe..." - (with-temp-buffer - (insert-lines "import q.Module...qwerqwe...") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import q.Module...qwerqwe...") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest package-import-parse () (should (equal "B" - (with-temp-buffer - (insert-lines "import \"package-1.2.3\" B") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import \"package-1.2.3\" B") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest safe-haskell-import-parse () (should (equal "B" - (with-temp-buffer - (insert-lines "import safe B") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import safe B") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) (ert-deftest full-import-parse () (should (equal "Data.Char.Unicode_v_7" - (with-temp-buffer - (insert-lines "import safe qualified \"unicode-7.0\" Data.Char.Unicode_v_7 as U (func)") - (goto-char (point-min)) - (forward-line 0) - (haskell-utils-parse-import-statement-at-point))))) + (with-temp-buffer + (insert-lines "import safe qualified \"unicode-7.0\" Data.Char.Unicode_v_7 as U (func)") + (goto-char (point-min)) + (forward-line 0) + (haskell-utils-parse-import-statement-at-point))))) From 6f828c13411e2aab797389c796c0bc0f17425716 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: Sun, 17 Jan 2016 00:03:40 +0500 Subject: [PATCH 2/4] Add proper package biolerplate wrap --- tests/haskell-utils-tests.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/haskell-utils-tests.el b/tests/haskell-utils-tests.el index 3b1af79cc..f91c63199 100644 --- a/tests/haskell-utils-tests.el +++ b/tests/haskell-utils-tests.el @@ -1,3 +1,32 @@ +;;; haskell-utils-tests.el --- Tests for Haskell utilities package + +;; Copyright © 2016 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-utils package. + +;;; Code: + (require 'ert) (require 'haskell-utils) @@ -100,3 +129,5 @@ (goto-char (point-min)) (forward-line 0) (haskell-utils-parse-import-statement-at-point))))) + +;;; haskell-utils-tests.el ends here From 6f335a2a1a7f9d7160e4084c59c8951287fc50e0 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: Sun, 17 Jan 2016 00:17:42 +0500 Subject: [PATCH 3/4] Document insert-lines (get rid of warinings) --- tests/haskell-utils-tests.el | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/haskell-utils-tests.el b/tests/haskell-utils-tests.el index f91c63199..d6069f2bd 100644 --- a/tests/haskell-utils-tests.el +++ b/tests/haskell-utils-tests.el @@ -31,6 +31,7 @@ (require 'haskell-utils) (defun insert-lines (&rest lines) + "Insert all LINES in current buffer." (dolist (line lines) (insert (concat line "\n")))) From 8504a49c29b4653eeb7095e1623a58523a57ae42 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: Sun, 17 Jan 2016 01:43:48 +0500 Subject: [PATCH 4/4] Define `haskell-utils-compose-type-at-command` test --- tests/haskell-utils-tests.el | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/haskell-utils-tests.el b/tests/haskell-utils-tests.el index d6069f2bd..acffda417 100644 --- a/tests/haskell-utils-tests.el +++ b/tests/haskell-utils-tests.el @@ -131,4 +131,49 @@ (forward-line 0) (haskell-utils-parse-import-statement-at-point))))) +(ert-deftest type-at-command-composition () + "Test haskell-utils-compose-type-at-command. +Test only position conversion to line and column numbers, do not +test last string compontent, it is used in `:type-at` command to +provide user friendly output only and could be any string, even +empty one. Very likely the way how its composed for multilne +strings will change in future." + (with-temp-buffer + (insert-lines "module A where" + "" + "int :: Int" + "int = 369" + "" + "act =" + " do print int" + " return int") + (goto-char (point-min)) + (let (test-a-points + test-b-points + test-a-result + test-b-result) + ;; go to third line, e.g. `int` definition + (forward-line 3) + (setq test-a-points (point)) + ;; go to at the end of `int` definition, i.e. point stands at whitespace + (forward-char 3) + (setq test-a-points `(,test-a-points . ,(point))) + (goto-char (line-beginning-position)) + ;; go to do-block line + (forward-line 3) + ;; go to `do` keyword beginning + (forward-char 2) + (setq test-b-points (point)) + ;; go to the end of do-block + (goto-char (point-max)) + ;; note `insert-line' inserts one extra newline, go up one line + (forward-line -1) + (goto-char (line-end-position)) + (setq test-b-points `(,test-b-points . ,(point))) + (setq test-a-result + (haskell-utils-compose-type-at-command test-a-points)) + (setq test-b-result + (haskell-utils-compose-type-at-command test-b-points)) + (should (string-prefix-p ":type-at nil 4 1 4 4" test-a-result)) + (should (string-prefix-p ":type-at nil 7 3 8 16" test-b-result))))) ;;; haskell-utils-tests.el ends here