@@ -313,6 +313,46 @@ myReverse xs = revAcc [] xs where
313
313
(delete-directory mock-directory-name t )
314
314
(idris-quit))))
315
315
316
+ (ert-deftest idris-test-idris-filename-to-load ()
317
+ " Test that `idris-filename-to-load' returns expected data structure."
318
+ (cl-flet ((idris-ipkg-find-src-dir-stub () src-dir)
319
+ (idris-find-file-upwards-stub (_ex) ipkg-files)
320
+ (buffer-file-name-stub () " /some/path/to/idris-project/src/Component/Foo.idr" ))
321
+ (advice-add 'idris-ipkg-find-src-dir :override #'idris-ipkg-find-src-dir-stub )
322
+ (advice-add 'idris-find-file-upwards :override #'idris-find-file-upwards-stub )
323
+ (advice-add 'buffer-file-name :override #'buffer-file-name-stub )
324
+ (let* ((default-directory " /some/path/to/idris-project/src/Component" )
325
+ ipkg-files
326
+ src-dir)
327
+ (unwind-protect
328
+ (progn
329
+ (let ((result (idris-filename-to-load)))
330
+ (should (equal default-directory (car result)))
331
+ (should (equal " Foo.idr" (cdr result))))
332
+
333
+ ; ; When ipkg sourcedir value is set
334
+ ; ; Then return combination of source directory
335
+ ; ; and relative path of the file to the source directory
336
+ (let* ((src-dir " /some/path/to/idris-project/src" )
337
+ (result (idris-filename-to-load)))
338
+ (should (equal src-dir (car result)))
339
+ (should (equal " Component/Foo.idr" (cdr result))))
340
+
341
+ ; ; When ipkg sourcedir value is set
342
+ ; ; and idris-protocol-version is greater than 1
343
+ ; ; Then return combination of work directory
344
+ ; ; (Directory containing the first found ipkg file)
345
+ ; ; and relative path of the file to the work directory
346
+ (let* ((ipkg-files '(" /some/path/to/idris-project/baz.ipkg" ))
347
+ (idris-protocol-version 2 )
348
+ (result (idris-filename-to-load)))
349
+ (should (equal " /some/path/to/idris-project" (car result)))
350
+ (should (equal " src/Component/Foo.idr" (cdr result)))))
351
+
352
+ (advice-remove 'idris-ipkg-find-src-dir #'idris-ipkg-find-src-dir-stub )
353
+ (advice-remove 'idris-find-file-upwards #'idris-find-file-upwards-stub )
354
+ (advice-remove 'buffer-file-name #'buffer-file-name-stub )))))
355
+
316
356
; ; Tests by Yasuhiko Watanabe
317
357
; ; https://github.com/idris-hackers/idris-mode/pull/537/files
318
358
(idris-ert-command-action " test-data/CaseSplit.idr" idris-case-split idris-test-eq-buffer)
0 commit comments