@@ -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\n testf B = testf A" )))
521+ (funcall-interactively 'idris-generate-def )
522+
523+ (setq eval-result (list #'identity '(" testf A = 1\n testf 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