@@ -466,6 +466,59 @@ closeDistance s1 s2 = closeDistance_rhs s1 s2"
466
466
(advice-remove 'idris-load-file-sync #'idris-load-file-sync-stub )
467
467
(advice-remove 'idris-eval #'idris-eval-stub ))))
468
468
469
+ (defmacro idris-generate-mock-read (clauses &optional default )
470
+ " Generate a function with cond expression from CLAUSES and optional DEFAULT."
471
+ `(lambda (prompt &optional &rest _)
472
+ (cond
473
+ ,@(mapcar (lambda (clause )
474
+ `((string-match-p ,(if (symbolp (car clause))
475
+ ; ; Convert symbol to string and
476
+ ; ; remove leading colon and
477
+ ; ; replace dashes with a space
478
+ (replace-regexp-in-string
479
+ " ^\\ :" " "
480
+ (string-replace " -" " " (symbol-name (car clause))))
481
+ (car clause))
482
+ prompt)
483
+ ,(cdr clause)))
484
+ clauses)
485
+ (t (or , default " " )))))
486
+
487
+ (when (string-match-p " idris2$" idris-interpreter-path)
488
+ (ert-deftest idris-start-idris2-project ()
489
+ " Test `idris-start-idris2-project' creating a project."
490
+ (cl-flet ((read-string-stub (idris-generate-mock-read ((:project-name . " Idris2 Test Project" )
491
+ (:author . " Joe Doe" )
492
+ (:source-dir . " mysrc" )
493
+ (:options . " --some-option" ))))
494
+ (read-dir-stub
495
+ (idris-generate-mock-read
496
+ ((:create-in . (idris-file-name-concat " test-data" " Idris2TestProject" ))))))
497
+ (advice-add 'read-string :override #'read-string-stub )
498
+ (advice-add 'read-directory-name :override #'read-dir-stub )
499
+ (unwind-protect
500
+ (progn
501
+ (idris-start-idris2-project t )
502
+ (let* ((ipkg-file-path (idris-file-name-concat " test-data"
503
+ " Idris2TestProject"
504
+ " idris2_test_project.ipkg" ))
505
+ (ipkg-buffer (find-file-noselect ipkg-file-path))
506
+ (ipkg-content (with-current-buffer ipkg-buffer
507
+ (buffer-substring-no-properties (point-min ) (point-max )))))
508
+
509
+ (should (string-match-p " -- Idris2 Test Project" ipkg-content))
510
+ (should (string-match-p " package Idris2TestProject" ipkg-content))
511
+ (should (string-match-p " authors = \" Joe Doe\" " ipkg-content))
512
+ (should (string-match-p " opts = \" --some-option\" " ipkg-content))
513
+ (should (string-match-p " sourcedir = \" mysrc\" " ipkg-content)))
514
+
515
+ (should (file-exists-p (idris-file-name-concat " test-data"
516
+ " Idris2TestProject"
517
+ " mysrc" ))))
518
+ (advice-remove 'read-string #'read-string-stub )
519
+ (advice-remove 'read-directory-name #'read-dir-stub )
520
+ (delete-directory (idris-file-name-concat " test-data" " Idris2TestProject" ) t )))))
521
+
469
522
; ; Tests by Yasuhiko Watanabe
470
523
; ; https://github.com/idris-hackers/idris-mode/pull/537/files
471
524
(idris-ert-command-action " test-data/CaseSplit.idr" idris-case-split idris-test-eq-buffer)
0 commit comments