1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
|
;;; f90-tests.el --- tests for progmodes/f90.el -*- lexical-binding:t -*-
;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
;; Author: Glenn Morris <rgm@gnu.org>
;; Maintainer: emacs-devel@gnu.org
;; 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/>.
;;; 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 ."
: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 ."
(with-temp-buffer
(f90-mode)
(insert "a" )
(move-to-column 68 t)
(insert "(/ x /)")
(f90-do-auto-fill)
(beginning-of-line)
(skip-chars-forward " \t")
(should (equal "&(/" (buffer-substring (point) (+ 3 (point)))))))
;; TODO bug#5593
(ert-deftest f90-test-bug8691 ()
"Test for https://debbugs.gnu.org/8691 ."
(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 ."
(with-temp-buffer
(f90-mode)
(should (eq (char-syntax ?%) (string-to-char ".")))))
(ert-deftest f90-test-bug9553a ()
"Test for https://debbugs.gnu.org/9553 ."
(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 ."
(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 ."
(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)))))
(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"
(buffer-substring (point) (pos-eol))))
(goto-char (point-max))
(insert "\nmodule subroutine bar(x)
real :: x
end")
(f90-indent-line)
(should (equal " subroutine bar"
(buffer-substring (point) (pos-eol))))))
;;; f90-tests.el ends here
|