emacs/test/lisp/progmodes/f90-tests.el

299 lines
7.1 KiB
EmacsLisp
Raw Normal View History

;;; f90-tests.el --- tests for progmodes/f90.el -*- lexical-binding:t -*-
2011-10-15 13:56:02 -07:00
2024-01-02 09:47:10 +08:00
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
2011-10-15 13:56:02 -07:00
;; Author: Glenn Morris <rgm@gnu.org>
2020-07-31 09:09:39 -07:00
;; Maintainer: emacs-devel@gnu.org
2011-10-15 13:56:02 -07:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
2011-10-15 13:56:02 -07:00
;;; Commentary:
;;; Code:
(require 'ert)
(require 'f90)
(defconst f90-test-indent "\
!! Comment before code.
!!! Comments before code.
#preprocessor before code
program progname
implicit none
integer :: i
!! Comment.
do i = 1, 10
#preprocessor
!! Comment.
if ( i % 2 == 0 ) then
!! Comment.
cycle
else
write(*,*) i
end if
end do
!!! Comment.
end program progname
"
"Test string for F90 indentation.")
(ert-deftest f90-test-indent ()
"Test F90 indentation."
(with-temp-buffer
(f90-mode)
(insert f90-test-indent)
(indent-rigidly (point-min) (point-max) -999)
(f90-indent-region (point-min) (point-max))
(should (string-equal (buffer-string) f90-test-indent))))
(ert-deftest f90-test-bug3729 ()
"Test for https://debbugs.gnu.org/3729 ."
2011-10-15 13:56:02 -07:00
:expected-result :failed
(with-temp-buffer
(f90-mode)
(insert "!! Comment
include \"file.f90\"
subroutine test (x)
real x
x = x+1.
return
end subroutine test")
(goto-char (point-min))
(forward-line 2)
(f90-indent-subprogram)
(should (= 0 (current-indentation)))))
(ert-deftest f90-test-bug3730 ()
"Test for https://debbugs.gnu.org/3730 ."
2011-10-15 13:56:02 -07:00
(with-temp-buffer
(f90-mode)
(insert "a" )
(move-to-column 68 t)
(insert "(/ x /)")
(f90-do-auto-fill)
(beginning-of-line)
Fix more regular expression typos Problem reported by Mattias Engdegård in: https://lists.gnu.org/r/emacs-devel/2019-03/msg00548.html except that I didn’t address the issues involving Hebrew, or involving comint-prompt-regexp. * lisp/align.el (align-rules-list, align-exclude-rules-list): * lisp/auth-source-pass.el (auth-source-pass--parse-secret) (auth-source-pass--parse-data): * lisp/cedet/data-debug.el (data-debug-next) (data-debug-prev, data-debug-expand-or-contract): * lisp/comint.el (comint-within-quotes): * lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine): * lisp/emulation/viper-ex.el (ex-cmd-complete): * lisp/gnus/gnus-cite.el (gnus-message-search-citation-line): * lisp/gnus/nnir.el (nnir-imap-end-of-input): * lisp/mail/mail-extr.el (mail-extr-all-letters): * lisp/minibuffer.el (minibuffer-maybe-quote-filename): * lisp/nxml/rng-nxml.el (rng-complete-tag) (rng-complete-end-tag, rng-complete-attribute-name): * lisp/obsolete/vip.el (vip-get-ex-token, vip-get-ex-pat): * lisp/org/org-pcomplete.el (org-thing-at-point): * lisp/org/org.el (org-set-tags) (org-increase-number-at-point) (org-fill-line-break-nobreak-p): * lisp/pcomplete.el (pcomplete-parse-comint-arguments): * lisp/progmodes/ada-mode.el (ada-compile-goto-error): * lisp/progmodes/cperl-mode.el (cperl-highlight-charclass) (cperl-find-pods-heres, cperl-not-bad-style-regexp) (cperl-regext-to-level-start): * lisp/progmodes/ebnf-yac.el (ebnf-yac-skip-spaces): * lisp/progmodes/flymake-proc.el (flymake-proc-master-tex-init): * lisp/progmodes/flymake.el (flymake-diag-region): * lisp/progmodes/fortran.el (fortran-current-line-indentation): * lisp/progmodes/idlw-complete-structtag.el: (idlwave-complete-structure-tag): * lisp/progmodes/idlwave.el (idlwave-complete-sysvar-or-tag): * lisp/progmodes/prolog.el (prolog-pred-end) (prolog-clause-info): * lisp/progmodes/ruby-mode.el (ruby-forward-sexp) (ruby-backward-sexp): * lisp/progmodes/verilog-mode.el (verilog-repair-open-comma): * lisp/term.el (term-within-quotes): * lisp/textmodes/bib-mode.el (bib-capitalize-title-stop-words): * lisp/textmodes/refbib.el (r2b-capitalize-title-stop-words): * lisp/textmodes/reftex-parse.el (reftex-nth-arg): * lisp/textmodes/rst.el (rst-svn-rev): * lisp/url/url-http.el (url-http-parse-response): * test/lisp/progmodes/f90-tests.el (f90-test-bug3730): Fix regular expression typos.
2019-03-18 17:02:01 -07:00
(skip-chars-forward " \t")
2011-10-15 13:56:02 -07:00
(should (equal "&(/" (buffer-substring (point) (+ 3 (point)))))))
;; TODO bug#5593
(ert-deftest f90-test-bug8691 ()
"Test for https://debbugs.gnu.org/8691 ."
2011-10-15 13:56:02 -07:00
(with-temp-buffer
(f90-mode)
(insert "module modname
type, bind(c) :: type1
integer :: part1
end type type1
end module modname")
(f90-indent-subprogram)
(forward-line -1)
(should (= 2 (current-indentation)))))
;; TODO bug#8812
(ert-deftest f90-test-bug8820 ()
"Test for https://debbugs.gnu.org/8820 ."
2011-10-15 13:56:02 -07:00
(with-temp-buffer
(f90-mode)
(should (eq (char-syntax ?%) (string-to-char ".")))))
(ert-deftest f90-test-bug9553a ()
"Test for https://debbugs.gnu.org/9553 ."
2011-10-15 13:56:02 -07:00
(with-temp-buffer
(f90-mode)
(insert "!!!")
(dotimes (_i 20) (insert " aaaa"))
(f90-do-auto-fill)
(beginning-of-line)
;; This gives a more informative failure than looking-at.
(should (equal "!!! a" (buffer-substring (point) (+ 5 (point)))))))
(ert-deftest f90-test-bug9553b ()
"Test for https://debbugs.gnu.org/9553 ."
2011-10-15 13:56:02 -07:00
(with-temp-buffer
(f90-mode)
(insert "!!!")
(dotimes (_i 13) (insert " aaaa"))
(insert "a, aaaa")
(f90-do-auto-fill)
(beginning-of-line)
(should (equal "!!! a" (buffer-substring (point) (+ 5 (point)))))))
(ert-deftest f90-test-bug9690 ()
"Test for https://debbugs.gnu.org/9690 ."
2011-10-15 13:56:02 -07:00
(with-temp-buffer
(f90-mode)
(insert "#include \"foo.h\"")
(f90-indent-line)
(should (= 0 (current-indentation)))))
(ert-deftest f90-test-bug13138 ()
"Test for https://debbugs.gnu.org/13138 ."
(with-temp-buffer
(f90-mode)
(insert "program prog
integer :: i = &
#ifdef foo
& 1
#else
& 2
#endif
write(*,*) i
end program prog")
(goto-char (point-min))
(forward-line 2)
(f90-indent-subprogram)
(should (= 0 (current-indentation)))))
2011-10-15 13:56:02 -07:00
(ert-deftest f90-test-bug-19809 ()
"Test for https://debbugs.gnu.org/19809 ."
(with-temp-buffer
(f90-mode)
;; The Fortran standard says that continued strings should have
;; '&' at the start of continuation lines, but it seems gfortran
;; allows them to be absent (albeit with a warning).
(insert "program prog
write (*,*), '&
end program prog'
end program prog")
(goto-char (point-min))
(f90-end-of-subprogram)
(should (= (point) (point-max)))))
(ert-deftest f90-test-bug20680 ()
"Test for https://debbugs.gnu.org/20680 ."
(with-temp-buffer
(f90-mode)
(insert "module modname
type, extends ( sometype ) :: type1
integer :: part1
end type type1
end module modname")
(f90-indent-subprogram)
(forward-line -1)
(should (= 2 (current-indentation)))))
(ert-deftest f90-test-bug20680b ()
"Test for https://debbugs.gnu.org/20680 ."
(with-temp-buffer
(f90-mode)
(insert "module modname
enum, bind(c)
enumerator :: e1 = 0
end enum
end module modname")
(f90-indent-subprogram)
(forward-line -1)
(should (= 2 (current-indentation)))))
(ert-deftest f90-test-bug20969 ()
"Test for https://debbugs.gnu.org/20969 ."
(with-temp-buffer
(f90-mode)
(insert "module modname
type, extends ( sometype ), private :: type1
integer :: part1
end type type1
end module modname")
(f90-indent-subprogram)
(forward-line -1)
(should (= 2 (current-indentation)))))
(ert-deftest f90-test-bug20969b ()
"Test for https://debbugs.gnu.org/20969 ."
(with-temp-buffer
(f90-mode)
(insert "module modname
type, private, extends ( sometype ) :: type1
integer :: part1
end type type1
end module modname")
(f90-indent-subprogram)
(forward-line -1)
(should (= 2 (current-indentation)))))
(ert-deftest f90-test-bug21794 ()
"Test for https://debbugs.gnu.org/21794 ."
(with-temp-buffer
(f90-mode)
(insert "program prog
do i=1,10
associate (x => xa(i), y => ya(i))
a(x,y,i) = fun(x,y,i)
end associate
end do
end program prog")
(f90-indent-subprogram)
(forward-line -2)
(should (= 5 (current-indentation)))))
(ert-deftest f90-test-bug25039 ()
"Test for https://debbugs.gnu.org/25039 and 28786."
(with-temp-buffer
(f90-mode)
(insert "program prog
select type (a)
type is (t1)
x = 2
class is (c1)
x = 1
class default
x=3
end select
end program prog")
(f90-indent-subprogram)
(forward-line -3)
(should (= 2 (current-indentation))) ; class default
(forward-line -2)
(should (= 2 (current-indentation))) ; class is
(forward-line -2)
(should (= 2 (current-indentation))))) ; type is
(ert-deftest f90-test-bug38415 ()
"Test for https://debbugs.gnu.org/38415 ."
(with-temp-buffer
(f90-mode)
(setq-local f90-smart-end 'no-blink)
(insert "module function foo(x)
real :: x
end")
(f90-indent-line)
(should (equal " function foo"
Prefer pos-bol and pos-eol in tests * test/lisp/calendar/todo-mode-tests.el (todo-test-toggle-item-header02, todo-test-edit-item-date-month) (todo-test-multiline-item-indentation-1) (todo-test-multiline-item-indentation-2) (todo-test-multiline-item-indentation-3): * test/lisp/cedet/semantic-utest-ia.el (semantic-ia-utest-buffer) (semantic-sr-utest-buffer-refs): * test/lisp/cedet/semantic-utest.el (semantic-utest-kill-indicator) (semantic-utest-unkill-indicator): * test/lisp/dired-tests.el (dired-test-bug27968): * test/lisp/emacs-lisp/backtrace-tests.el (backtrace-tests--verify-single-and-multi-line): * test/lisp/emacs-lisp/find-func-tests.el (find-func-tests--find-library-verbose): * test/lisp/erc/erc-tests.el (erc-ring-previous-command) (erc-log-irc-protocol): * test/lisp/gnus/message-tests.el (message-mode-propertize): * test/lisp/info-xref-tests.el (info-xref-test-emacs-manuals): * test/lisp/mail/footnote-tests.el (footnote-tests-same-place): * test/lisp/progmodes/elisp-mode-tests.el (elisp-shorthand-completion-at-point): * test/lisp/progmodes/f90-tests.el (f90-test-bug38415): * test/lisp/progmodes/python-tests.el (python-indent-electric-comma-inside-multiline-string) (python-indent-electric-comma-after-multiline-string) (python-indent-electric-colon-1, python-indent-electric-colon-2) (python-indent-electric-colon-3, python-indent-electric-colon-4) (python-mark-defun-2, python-mark-defun-3, python-mark-defun-4) (python-mark-defun-5, python-nav-end-of-defun-2) (python-nav-end-of-statement-1, python-nav-end-of-block-1) (python-indent-dedent-line-backspace-2) (python-indent-dedent-line-backspace-3) (python-eldoc--get-symbol-at-point-1) (python-info-beginning-of-statement-p-1) (python-info-beginning-of-statement-p-2): * test/lisp/replace-tests.el (replace-occur-revert-bug32543) (replace-occur-revert-bug32987): * test/lisp/simple-tests.el (simple-delete-indentation-boundaries) (simple-delete-indentation-region) (line-number-at-pos-in-narrow-buffer) (line-number-at-pos-keeps-restriction): * test/lisp/textmodes/css-mode-tests.el (css-mode-test-selectors) (scss-mode-test-selectors): * test/lisp/textmodes/fill-tests.el (fill-test-unbreakable-paragraph) (fill-test-breakable-paragraph): * test/lisp/time-stamp-tests.el (time-stamp-custom-pattern): * test/src/lread-tests.el (lread-tests--last-message): * test/src/process-tests.el (set-process-filter-t): * test/src/undo-tests.el (undo-test-skip-invalidated-markers): Prefer pos-bol and pos-eol.
2022-08-21 17:33:55 +02:00
(buffer-substring (point) (pos-eol))))
(goto-char (point-max))
(insert "\nmodule subroutine bar(x)
real :: x
end")
(f90-indent-line)
(should (equal " subroutine bar"
Prefer pos-bol and pos-eol in tests * test/lisp/calendar/todo-mode-tests.el (todo-test-toggle-item-header02, todo-test-edit-item-date-month) (todo-test-multiline-item-indentation-1) (todo-test-multiline-item-indentation-2) (todo-test-multiline-item-indentation-3): * test/lisp/cedet/semantic-utest-ia.el (semantic-ia-utest-buffer) (semantic-sr-utest-buffer-refs): * test/lisp/cedet/semantic-utest.el (semantic-utest-kill-indicator) (semantic-utest-unkill-indicator): * test/lisp/dired-tests.el (dired-test-bug27968): * test/lisp/emacs-lisp/backtrace-tests.el (backtrace-tests--verify-single-and-multi-line): * test/lisp/emacs-lisp/find-func-tests.el (find-func-tests--find-library-verbose): * test/lisp/erc/erc-tests.el (erc-ring-previous-command) (erc-log-irc-protocol): * test/lisp/gnus/message-tests.el (message-mode-propertize): * test/lisp/info-xref-tests.el (info-xref-test-emacs-manuals): * test/lisp/mail/footnote-tests.el (footnote-tests-same-place): * test/lisp/progmodes/elisp-mode-tests.el (elisp-shorthand-completion-at-point): * test/lisp/progmodes/f90-tests.el (f90-test-bug38415): * test/lisp/progmodes/python-tests.el (python-indent-electric-comma-inside-multiline-string) (python-indent-electric-comma-after-multiline-string) (python-indent-electric-colon-1, python-indent-electric-colon-2) (python-indent-electric-colon-3, python-indent-electric-colon-4) (python-mark-defun-2, python-mark-defun-3, python-mark-defun-4) (python-mark-defun-5, python-nav-end-of-defun-2) (python-nav-end-of-statement-1, python-nav-end-of-block-1) (python-indent-dedent-line-backspace-2) (python-indent-dedent-line-backspace-3) (python-eldoc--get-symbol-at-point-1) (python-info-beginning-of-statement-p-1) (python-info-beginning-of-statement-p-2): * test/lisp/replace-tests.el (replace-occur-revert-bug32543) (replace-occur-revert-bug32987): * test/lisp/simple-tests.el (simple-delete-indentation-boundaries) (simple-delete-indentation-region) (line-number-at-pos-in-narrow-buffer) (line-number-at-pos-keeps-restriction): * test/lisp/textmodes/css-mode-tests.el (css-mode-test-selectors) (scss-mode-test-selectors): * test/lisp/textmodes/fill-tests.el (fill-test-unbreakable-paragraph) (fill-test-breakable-paragraph): * test/lisp/time-stamp-tests.el (time-stamp-custom-pattern): * test/src/lread-tests.el (lread-tests--last-message): * test/src/process-tests.el (set-process-filter-t): * test/src/undo-tests.el (undo-test-skip-invalidated-markers): Prefer pos-bol and pos-eol.
2022-08-21 17:33:55 +02:00
(buffer-substring (point) (pos-eol))))))
;;; f90-tests.el ends here