f90.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ;;; f90.el --- tests for progmodes/f90.el
  2. ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
  3. ;; Author: Glenn Morris <rgm@gnu.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This file does not have "test" in the name, because it lives under
  17. ;; a test/ directory, so that would be superfluous.
  18. ;;; Code:
  19. (require 'ert)
  20. (require 'f90)
  21. (defconst f90-test-indent "\
  22. !! Comment before code.
  23. !!! Comments before code.
  24. #preprocessor before code
  25. program progname
  26. implicit none
  27. integer :: i
  28. !! Comment.
  29. do i = 1, 10
  30. #preprocessor
  31. !! Comment.
  32. if ( i % 2 == 0 ) then
  33. !! Comment.
  34. cycle
  35. else
  36. write(*,*) i
  37. end if
  38. end do
  39. !!! Comment.
  40. end program progname
  41. "
  42. "Test string for F90 indentation.")
  43. (ert-deftest f90-test-indent ()
  44. "Test F90 indentation."
  45. (with-temp-buffer
  46. (f90-mode)
  47. (insert f90-test-indent)
  48. (indent-rigidly (point-min) (point-max) -999)
  49. (f90-indent-region (point-min) (point-max))
  50. (should (string-equal (buffer-string) f90-test-indent))))
  51. (ert-deftest f90-test-bug3729 ()
  52. "Test for http://debbugs.gnu.org/3729 ."
  53. :expected-result :failed
  54. (with-temp-buffer
  55. (f90-mode)
  56. (insert "!! Comment
  57. include \"file.f90\"
  58. subroutine test (x)
  59. real x
  60. x = x+1.
  61. return
  62. end subroutine test")
  63. (goto-char (point-min))
  64. (forward-line 2)
  65. (f90-indent-subprogram)
  66. (should (= 0 (current-indentation)))))
  67. (ert-deftest f90-test-bug3730 ()
  68. "Test for http://debbugs.gnu.org/3730 ."
  69. (with-temp-buffer
  70. (f90-mode)
  71. (insert "a" )
  72. (move-to-column 68 t)
  73. (insert "(/ x /)")
  74. (f90-do-auto-fill)
  75. (beginning-of-line)
  76. (skip-chars-forward "[ \t]")
  77. (should (equal "&(/" (buffer-substring (point) (+ 3 (point)))))))
  78. ;; TODO bug#5593
  79. (ert-deftest f90-test-bug8691 ()
  80. "Test for http://debbugs.gnu.org/8691 ."
  81. (with-temp-buffer
  82. (f90-mode)
  83. (insert "module modname
  84. type, bind(c) :: type1
  85. integer :: part1
  86. end type type1
  87. end module modname")
  88. (f90-indent-subprogram)
  89. (forward-line -1)
  90. (should (= 2 (current-indentation)))))
  91. ;; TODO bug#8812
  92. (ert-deftest f90-test-bug8820 ()
  93. "Test for http://debbugs.gnu.org/8820 ."
  94. (with-temp-buffer
  95. (f90-mode)
  96. (should (eq (char-syntax ?%) (string-to-char ".")))))
  97. (ert-deftest f90-test-bug9553a ()
  98. "Test for http://debbugs.gnu.org/9553 ."
  99. (with-temp-buffer
  100. (f90-mode)
  101. (insert "!!!")
  102. (dotimes (_i 20) (insert " aaaa"))
  103. (f90-do-auto-fill)
  104. (beginning-of-line)
  105. ;; This gives a more informative failure than looking-at.
  106. (should (equal "!!! a" (buffer-substring (point) (+ 5 (point)))))))
  107. (ert-deftest f90-test-bug9553b ()
  108. "Test for http://debbugs.gnu.org/9553 ."
  109. (with-temp-buffer
  110. (f90-mode)
  111. (insert "!!!")
  112. (dotimes (_i 13) (insert " aaaa"))
  113. (insert "a, aaaa")
  114. (f90-do-auto-fill)
  115. (beginning-of-line)
  116. (should (equal "!!! a" (buffer-substring (point) (+ 5 (point)))))))
  117. (ert-deftest f90-test-bug9690 ()
  118. "Test for http://debbugs.gnu.org/9690 ."
  119. (with-temp-buffer
  120. (f90-mode)
  121. (insert "#include \"foo.h\"")
  122. (f90-indent-line)
  123. (should (= 0 (current-indentation)))))
  124. ;;; f90.el ends here