@@ -574,6 +574,104 @@ Matrix i j = i ?hole2"
574
574
(advice-remove 'idris-load-file-sync #'idris-load-file-sync-stub )
575
575
(advice-remove 'idris-eval #'idris-eval-stub ))))
576
576
577
+ (ert-deftest idris-generate-def ()
578
+ " Test `idris-generate-def' ."
579
+ (cl-flet ((idris-load-file-sync-stub () nil )
580
+ (idris-eval-stub (sexp &optional no-errors)
581
+ (apply #'funcall eval-result)))
582
+ (advice-add 'idris-load-file-sync :override #'idris-load-file-sync-stub )
583
+ (advice-add 'idris-eval :override #'idris-eval-stub )
584
+ (unwind-protect
585
+ (progn
586
+ ; ; hapy path
587
+ (with-temp-buffer
588
+ (insert " data Foo = A | B
589
+
590
+ testf : Foo -> Int
591
+ " )
592
+ (goto-char (point-min ))
593
+ (re-search-forward " test" )
594
+ (let ((eval-result (list #'identity '(" testf A = testf B\n testf B = testf A" ))))
595
+ (funcall-interactively 'idris-generate-def ))
596
+ ; ; (message (buffer-substring-no-properties (point-min) (point-max)))
597
+ (should (string= " data Foo = A | B
598
+
599
+ testf : Foo -> Int
600
+ testf A = testf B
601
+ testf B = testf A
602
+ "
603
+ (buffer-substring-no-properties (point-min ) (point-max )))))
604
+ ; ; sad path
605
+ (with-temp-buffer
606
+ (insert " data Foo = A | B
607
+
608
+ testf : Foo -> Int
609
+ " )
610
+ (goto-char (point-min ))
611
+ (re-search-forward " test" )
612
+ (let ((eval-result (list #'identity '(" " ))))
613
+ (should-error
614
+ (funcall-interactively 'idris-generate-def ))))
615
+
616
+ ; ; sad path 2
617
+ (with-temp-buffer
618
+ (insert " data Foo = A | B
619
+
620
+ testf : Foo -> Int
621
+ " )
622
+ (goto-char (point-min ))
623
+ (re-search-forward " test" )
624
+ (let ((eval-result (list #'error " %s (synchronous Idris evaluation failed)" " Nothing found" )))
625
+ (should-error
626
+ (funcall-interactively 'idris-generate-def )))))
627
+
628
+ (advice-remove 'idris-load-file-sync #'idris-load-file-sync-stub )
629
+ (advice-remove 'idris-eval #'idris-eval-stub ))))
630
+
631
+ (ert-deftest idris-generate-def-next ()
632
+ " Test `idris-generate-def-next' ."
633
+ (skip-unless (string-match-p " idris2$" idris-interpreter-path))
634
+ (cl-flet ((idris-load-file-sync-stub () nil )
635
+ (idris-eval-stub (sexp &optional no-errors)
636
+ (apply #'funcall eval-result)))
637
+ (advice-add 'idris-load-file-sync :override #'idris-load-file-sync-stub )
638
+ (advice-add 'idris-eval :override #'idris-eval-stub )
639
+ (unwind-protect
640
+ (progn
641
+ (with-temp-buffer
642
+ (insert " data Foo = A | B
643
+
644
+ testf : Foo -> Int
645
+ " )
646
+ (goto-char (point-min ))
647
+ (re-search-forward " test" )
648
+ (let ((eval-result (list #'identity '(" testf A = testf B\n testf B = testf A" ))))
649
+ (funcall-interactively 'idris-generate-def ))
650
+
651
+ (let ((eval-result (list #'identity '(" testf A = 1\n testf B = 2" ))))
652
+ (funcall-interactively 'idris-generate-def-next ))
653
+ (should (string= " data Foo = A | B
654
+
655
+ testf : Foo -> Int
656
+ testf A = 1
657
+ testf B = 2
658
+ "
659
+ (buffer-substring-no-properties (point-min ) (point-max ))))
660
+
661
+ (let ((eval-result (list #'identity '(" third definition" ))))
662
+ (funcall-interactively 'idris-generate-def-next ))
663
+ (should (string= " data Foo = A | B
664
+
665
+ testf : Foo -> Int
666
+ third definition
667
+ "
668
+ (buffer-substring-no-properties (point-min ) (point-max ))))
669
+ (let ((eval-result (list #'error " %s (synchronous Idris evaluation failed)" " No more results" )))
670
+ (should-error (funcall-interactively 'idris-generate-def-next )))))
671
+
672
+ (advice-remove 'idris-load-file-sync #'idris-load-file-sync-stub )
673
+ (advice-remove 'idris-eval #'idris-eval-stub ))))
674
+
577
675
; ; Tests by Yasuhiko Watanabe
578
676
; ; https://github.com/idris-hackers/idris-mode/pull/537/files
579
677
(idris-ert-command-action " test-data/CaseSplit.idr" idris-case-split idris-test-eq-buffer)
0 commit comments