[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode c39d0f4 321/385: some hsinspect tests
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode c39d0f4 321/385: some hsinspect tests |
Date: |
Tue, 5 Oct 2021 23:59:56 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit c39d0f430807370111fcea024d2d3984eb58964e
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
some hsinspect tests
---
haskell-tng-hsinspect.el | 23 +++++++-----
haskell-tng-util.el | 33 +++++++++-------
test/data/hsinspect-0.0.7-imports.sexp.gz | Bin 0 -> 364 bytes
test/data/hsinspect-0.0.7-index.sexp.gz | Bin 0 -> 52239 bytes
test/data/hsinspect-0.0.8-imports.sexp.gz | Bin 0 -> 361 bytes
test/data/hsinspect-0.0.8-index.sexp.gz | Bin 0 -> 74636 bytes
test/haskell-tng-hsinspect-test.el | 60 ++++++++++++++++++++++++++++++
7 files changed, 94 insertions(+), 22 deletions(-)
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index b932922..1bca5aa 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -34,13 +34,12 @@ name of the symbol at point in the minibuffer.
A prefix argument ensures that caches are flushes."
(interactive "P")
(if-let* ((sym (haskell-tng--hsinspect-symbol-at-point))
- (found (seq-find
- ;; FIXME test for this
- ;; TODO add type information too
- (lambda (names) (member sym (seq-map #'cdr names)))
- (haskell-tng--hsinspect-imports nil alt))))
+ (found (haskell-tng--hsinspect-qualify
+ (haskell-tng--hsinspect-imports nil alt)
+ sym)))
;; TODO multiple hits
- (popup-tip (format "%s" (cdar (last found)))))
+ ;; TODO add type information from the index when available
+ (popup-tip (format "%s" found)))
(user-error "Not found"))
;; FIXME jump-to-definition using import + index + heuristics
@@ -71,6 +70,13 @@ A prefix argument ensures that caches are flushes."
;; TODO expand out pattern matches (function defns and cases) based on the cons
;; for a type obtained from the Index.
+(defun haskell-tng--hsinspect-qualify (imports sym)
+ (cdar
+ (last
+ (seq-find
+ (lambda (names) (member sym (seq-map #'cdr names)))
+ imports))))
+
(defun haskell-tng--hsinspect-import-popup (index sym)
(when-let ((hits (haskell-tng--hsinspect-import-candidates index sym)))
;; TODO special case one hit
@@ -78,7 +84,6 @@ A prefix argument ensures that caches are flushes."
(selected (popup-menu* entries)))
(seq-find (lambda (el) (equal (car el) selected)) hits))))
-;; FIXME this could be tested
(defun haskell-tng--hsinspect-import-candidates (index sym)
"Return a list of (module . symbol)"
;; TODO threading/do syntax
@@ -138,7 +143,7 @@ A prefix argument ensures that caches are flushes."
(defun haskell-tng--hsinspect-index (&optional flush-cache)
(when-let (ghcflags-dir
(locate-dominating-file default-directory ".ghc.flags"))
- (haskell-tng--hsinspect-cached-disk
+ (haskell-tng--util-cached-disk
(lambda () (haskell-tng--hsinspect flush-cache "index"))
(concat "hsinspect-0.0.7" (expand-file-name ghcflags-dir) "index")
nil
@@ -152,7 +157,7 @@ A prefix argument ensures that caches are flushes."
haskell-tng--compile-dominating-project)
(haskell-tng--util-locate-dominating-file
haskell-tng--compile-dominating-package)))
- (haskell-tng--hsinspect-cached-disk
+ (haskell-tng-util-cached-disk
#'haskell-tng--hsinspect-which-hsinspect
(concat "which" (expand-file-name package-dir) "hsinspect")
nil
diff --git a/haskell-tng-util.el b/haskell-tng-util.el
index bcb1cae..b501639 100644
--- a/haskell-tng-util.el
+++ b/haskell-tng-util.el
@@ -103,9 +103,9 @@ and taking a regexp."
The caller is responsible for flushing the cache. For
consistency, it is recommended that commands using this cache
flush the cache when the universal argument is provided."
- (haskell-tng--hsinspect-cached-variable
+ (haskell-tng--util-cached-variable
(lambda ()
- (haskell-tng--hsinspect-cached-disk
+ (haskell-tng-util-cached-disk
work
key
no-work
@@ -114,7 +114,7 @@ flush the cache when the universal argument is provided."
nil
reset))
-(defun haskell-tng--hsinspect-cached-variable (work sym &optional no-work
reset)
+(defun haskell-tng--util-cached-variable (work sym &optional no-work reset)
"A variable cache over a function WORK.
If the SYM reference contains a cache of a previous call, it is
@@ -141,7 +141,7 @@ RESET sets the variable to nil before doing anything."
(cached cached)))
;; TODO max-age (fallback to disk if WORK fails)
-(defun haskell-tng--hsinspect-cached-disk (work key &optional no-work reset)
+(defun haskell-tng-util-cached-disk (work key &optional no-work reset)
"A disk-based cache over a function WORK.
If the cache contains a file matching the KEY string (which must
@@ -156,22 +156,29 @@ nil return values are NOT cached.
NO-WORK skips WORK and only queries the cache.
RESET deletes the cache if it exists."
- (let (jka-compr-verbose ;; disables gzip noise
- (cache-file
+ (let ((cache-file
(concat (xdg-cache-home) "/haskell-tng/" key ".gz")))
(when (and reset (file-exists-p cache-file))
(delete-file cache-file))
(if (file-exists-p cache-file)
- (with-temp-buffer
- (insert-file-contents cache-file)
- (goto-char (point-min))
- (ignore-errors (read (current-buffer))))
+ (haskell-tng--util-read cache-file)
(unless no-work
(when-let (result (funcall work))
- (with-temp-file cache-file
- (make-directory (file-name-directory cache-file) 'create-parents)
- (prin1 result (current-buffer)))
+ (haskell-tng--util-write result cache-file)
result)))))
+(defun haskell-tng--util-read (file)
+ (let (jka-compr-verbose)
+ (with-temp-buffer
+ (insert-file-contents file)
+ (goto-char (point-min))
+ (ignore-errors (read (current-buffer))))))
+
+(defun haskell-tng--util-write (file var)
+ (let (jka-compr-verbose)
+ (with-temp-file file
+ (make-directory (file-name-directory file) 'create-parents)
+ (prin1 var (current-buffer)))))
+
(provide 'haskell-tng-util)
;;; haskell-tng-util.el ends here
diff --git a/test/data/hsinspect-0.0.7-imports.sexp.gz
b/test/data/hsinspect-0.0.7-imports.sexp.gz
new file mode 100644
index 0000000..dc6b7ac
Binary files /dev/null and b/test/data/hsinspect-0.0.7-imports.sexp.gz differ
diff --git a/test/data/hsinspect-0.0.7-index.sexp.gz
b/test/data/hsinspect-0.0.7-index.sexp.gz
new file mode 100644
index 0000000..aad2677
Binary files /dev/null and b/test/data/hsinspect-0.0.7-index.sexp.gz differ
diff --git a/test/data/hsinspect-0.0.8-imports.sexp.gz
b/test/data/hsinspect-0.0.8-imports.sexp.gz
new file mode 100644
index 0000000..8c61dc4
Binary files /dev/null and b/test/data/hsinspect-0.0.8-imports.sexp.gz differ
diff --git a/test/data/hsinspect-0.0.8-index.sexp.gz
b/test/data/hsinspect-0.0.8-index.sexp.gz
new file mode 100644
index 0000000..6e95415
Binary files /dev/null and b/test/data/hsinspect-0.0.8-index.sexp.gz differ
diff --git a/test/haskell-tng-hsinspect-test.el
b/test/haskell-tng-hsinspect-test.el
new file mode 100644
index 0000000..3bbccac
--- /dev/null
+++ b/test/haskell-tng-hsinspect-test.el
@@ -0,0 +1,60 @@
+;;; haskell-tng-hsinspect-test.el --- Tests for hsinspect features -*-
lexical-binding: t -*-
+
+;; Copyright (C) 2019 Tseen She
+;; License: GPL 3 or any later version
+
+(require 'ert)
+
+(require 'haskell-tng-mode)
+(require 'haskell-tng-hsinspect)
+
+(require 'haskell-tng-testutils
+ "test/haskell-tng-testutils.el")
+
+(ert-deftest haskell-tng-hsinspect-test-qualify-latest ()
+ (let ((imports
+ (haskell-tng--util-read
+ (testdata "data/hsinspect-0.0.8-imports.sexp.gz"))))
+
+ ;; function search
+ (should
+ (equal
+ (haskell-tng--hsinspect-qualify imports "contramap")
+ "Data.Functor.Contravariant.contramap"))
+
+ ;; operator search
+ (should
+ (equal
+ (haskell-tng--hsinspect-qualify imports ">$<")
+ "Data.Functor.Contravariant.>$<"))
+
+ ;; TODO type search
+ ;; TODO constructor search
+ ))
+
+(ert-deftest haskell-tng-hsinspect-test-import-candidates-latest ()
+ (let ((index
+ (haskell-tng--util-read
+ (testdata "data/hsinspect-0.0.8-index.sexp.gz"))))
+
+ ;; function search
+ (should
+ (equal
+ (haskell-tng--hsinspect-import-candidates index "throw")
+ '(("Control.Exception.Base" . "throw")
+ ("Control.Exception" . "throw")
+ ("GHC.Exception" . "throw"))))
+
+ ;; operator search
+ (should
+ (equal
+ (haskell-tng--hsinspect-import-candidates index ">$<")
+ '(("Data.Functor.Contravariant" . ">$<"))))
+
+ ;; TODO type search
+ ;; TODO constructor search
+ ))
+
+;; TODO tests for 0.0.7 data
+
+;;; haskell-tng-hsinspect-test.el ends here
- [nongnu] elpa/haskell-tng-mode 1d53572 243/385: bugfixes, (continued)
- [nongnu] elpa/haskell-tng-mode 1d53572 243/385: bugfixes, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d1e599a 285/385: switch formatting backend based on project config, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fd06b8f 264/385: move haskell-tng-newline into the -extra package, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8ff79e7 247/385: allow parallelism, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4e2cf00 284/385: simplify the installation of hsinspect, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1107e63 274/385: bump hsinspect, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8475578 311/385: typos, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f8d2b91 295/385: miss some false positive ghc errors, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fca5c6e 315/385: better docs and cabal-install support, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b2e19c9 318/385: document next steps, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c39d0f4 321/385: some hsinspect tests,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 5fe4cb1 359/385: cleanup test includes, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 38ed1b7 326/385: import types, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6d4e150 353/385: upgrade hsinspect version, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4f84cde 347/385: improve importing qualified symbols, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 86d9020 373/385: one hsinspect-lsp can be shared by all projects, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a98dda0 380/385: emacs 27 macro deprecations, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode aeaf363 220/385: bugfinding, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9a7534e 262/385: bugfixes for abbrev, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 356f27b 278/385: more stable hsinspect calls, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode be39ede 258/385: if/then/else indentation test, ELPA Syncer, 2021/10/06