Skip to content

Commit

Permalink
dumb-jump-go-no-rules-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktasia committed Jan 15, 2016
1 parent 335f34f commit d9f2f02
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
17 changes: 10 additions & 7 deletions dumb-jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
(:type "variable" :language "elisp"
:regex "\\\(setq\\b\\s*JJJ\\b\\s*" :tests ("(setq test 123)"))
(:type "variable" :language "elisp"
:regex "\\\(JJJ\\b\\s*" :tests ("(let ((test 123)))"))
:regex "\\\(JJJ\\b\\s*" :tests ("(let ((test 123)))")) ; TODO: just \\s+?

;; python
(:type "variable" :language "python"
Expand Down Expand Up @@ -115,8 +115,8 @@ and type to use for generating the grep command"
(:language "javascript" :type "variable" :right "." :left nil)
(:language "javascript" :type "variable" :right ";" :left nil)

(:language "elisp" :type "variable" :right ")" :left " ")
(:language "elisp" :type "function" :right " " :left "("))
(:language "elisp" :type "function" :right " " :left "(")
(:language "elisp" :type "variable" :right ")" :left " "))

"List of under points contexts for each language. This helps limit
the number of regular expressions we use if we know that if there's a '('
Expand Down Expand Up @@ -219,7 +219,7 @@ If not found, then return dumb-jump-default-profile"
dumb-jump-language-file-exts)))
(if result
(plist-get (car result) :language)
nil)))
(format ".%s file" (f-ext filename)))))

(defun dumb-jump-fetch-results ()
(let* ((cur-file (buffer-file-name))
Expand Down Expand Up @@ -250,19 +250,21 @@ If not found, then return dumb-jump-default-profile"
(interactive)
(let* ((info (dumb-jump-fetch-results))
(results (plist-get info :results))
(lang (plist-get info :lang))
(result-count (length results)))
; (message-prin1 "lang:%s type:%s results: %s" lang ctx-type results)
(cond
((and (not (listp results)) (s-blank? results))
(message "Could not find rules for language '%s'." (plist-get info :lang)))
; ((and (not (listp results)) (s-blank? results))
((s-ends-with? " file" lang)
(message "Could not find rules for '%s'." lang))
((= result-count 1)
(dumb-jump-result-follow (car results)))
((> result-count 1)
;; multiple results so let the user pick from a list
;; unless the match is in the current file
(dumb-jump-handle-results results (plist-get info :file) (plist-get info :root) (plist-get info :ctx-type) (plist-get info :symbol)))
((= result-count 0)
(message "'%s' %s %s declaration not found." (plist-get info :symbol) (plist-get info :lang) (plist-get info :ctx-type)))
(message "'%s' %s %s declaration not found." (plist-get info :symbol) lang (plist-get info :ctx-type)))
(t
(message "Un-handled results: %s " (prin1-to-string results))))))

Expand Down Expand Up @@ -378,6 +380,7 @@ If not found, then return dumb-jump-default-profile"
(lambda (r)
(format "'%s'" (plist-get r ':regex)))
rules)))
; (message-prin1 "%s %s %s %s" raw-rules ctx-rules rules regexes)
regexes))

(defun dumb-jump-generate-command (look-for proj regexes include-args exclude-args)
Expand Down
3 changes: 3 additions & 0 deletions test/data/proj1/src/js/nocode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
this is a
file with
no code
9 changes: 9 additions & 0 deletions test/dumb-jump-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@
(should (string= arg1 "console"))))
(dumb-jump-go)))))

(ert-deftest dumb-jump-go-no-rules-test ()
(let ((txt-file (f-join test-data-dir-proj1 "src" "js" "nocode.txt")))
(with-current-buffer (find-file-noselect txt-file t)
(forward-char 0)
(noflet ((message (input arg1)
(should (string= input "Could not find rules for '%s'."))
(should (string= arg1 ".txt file"))))
(dumb-jump-go)))))

(ert-deftest dumb-jump-message-handle-results-test ()
(noflet ((dumb-jump-result-follow (result)
(should (= (plist-get result :line) 62))))
Expand Down

0 comments on commit d9f2f02

Please sign in to comment.