Skip to content

Commit 49c6f38

Browse files
authored
Merge pull request #647 from keram/generate-def-simpl
Simplify `idris-generate-def`, remove commented out code and add test for `idris-generate-def-next`
2 parents b45ddda + dde834f commit 49c6f38

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

idris-commands.el

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,10 @@ Idris 2 only."
806806
(prefix (idris-line-indentation-for what)))
807807
(if (string= result "")
808808
(error "Nothing found")
809-
(goto-char (line-beginning-position))
809+
(beginning-of-line)
810810
(forward-line)
811811
(while (and (not (eobp))
812-
(progn (goto-char (line-beginning-position))
812+
(progn (beginning-of-line)
813813
(looking-at-p (concat prefix "\\s-+"))))
814814
(forward-line))
815815
(insert prefix)
@@ -818,13 +818,7 @@ Idris 2 only."
818818
(insert result)
819819
(setq def-region-end (point))
820820
(newline)
821-
(goto-char final-point)
822-
; (save-excursion
823-
; (forward-line 1)
824-
; (setq def-region-start (point))
825-
; (insert result)
826-
; (setq def-region-end (point)))
827-
)))))
821+
(goto-char final-point))))))
828822

829823
(defun idris-generate-def-next ()
830824
"Replace the previous generated definition with next definition, if it exists.

test/idris-commands-test.el

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,50 @@ closeDistance s1 s2 = closeDistance_rhs s1 s2"
500500
(should (equal "/some/path/to/idris-project" (car result)))
501501
(should (equal "src/Component/Foo.idr" (cdr result)))))))
502502

503+
(ert-deftest idris-generate-def-next ()
504+
"Test `idris-generate-def-next'."
505+
(skip-unless (string-match-p "idris2$" idris-interpreter-path))
506+
(let (eval-result)
507+
(cl-flet ((idris-load-file-sync-stub () nil)
508+
(idris-eval-stub (sexp &optional no-errors)
509+
(apply #'funcall eval-result)))
510+
(advice-add 'idris-load-file-sync :override #'idris-load-file-sync-stub)
511+
(advice-add 'idris-eval :override #'idris-eval-stub)
512+
(unwind-protect
513+
(with-temp-buffer
514+
(insert "data Foo = A | B
515+
516+
testf : Foo -> Int
517+
")
518+
(goto-char (point-min))
519+
(re-search-forward "test")
520+
(setq eval-result (list #'identity '("testf A = testf B\ntestf B = testf A")))
521+
(funcall-interactively 'idris-generate-def)
522+
523+
(setq eval-result (list #'identity '("testf A = 1\ntestf B = 2")))
524+
(funcall-interactively 'idris-generate-def-next)
525+
(should (string= "data Foo = A | B
526+
527+
testf : Foo -> Int
528+
testf A = 1
529+
testf B = 2
530+
"
531+
(buffer-substring-no-properties (point-min) (point-max))))
532+
(setq eval-result (list #'identity '("third definition")))
533+
(funcall-interactively 'idris-generate-def-next)
534+
(message "%s" (buffer-substring-no-properties (point-min) (point-max)))
535+
(should (string= "data Foo = A | B
536+
537+
testf : Foo -> Int
538+
third definition
539+
"
540+
(buffer-substring-no-properties (point-min) (point-max))))
541+
(setq eval-result (list #'error "%s (synchronous Idris evaluation failed)" "No more results"))
542+
(should-error (funcall-interactively 'idris-generate-def-next)))
543+
544+
(advice-remove 'idris-load-file-sync #'idris-load-file-sync-stub)
545+
(advice-remove 'idris-eval #'idris-eval-stub)))))
546+
503547
;; Tests by Yasuhiko Watanabe
504548
;; https://github.com/idris-hackers/idris-mode/pull/537/files
505549
(idris-ert-command-action "test-data/CaseSplit.idr" idris-case-split idris-test-eq-buffer)

0 commit comments

Comments
 (0)