matlab.el:
(matlab-lattr-block-close): After narrowing buffer, got to eol, not max - as we had to expand the narrowed region to handle special syntax chars on eol. metest.el: (metest-all-syntax-tests): Add ... (metest-end-detect-test): New test (met-end-dect-files): New Var (metest-comment-string-syntax-test) (metest-sexp-counting-test, metest-sexp-traversal-test) (metest-indents-test, metest-parse-test): Use new `metest-find-file' for loading in files. (met-indents-files): Add mfuncends.m tests/empty.m: tests/mfuncends.m: tests/mfuncnoend.m: New test files tests/stringtest.m: tests/mclass.m: Add end-detect expected value cookies.
This commit is contained in:
parent
6fe7a322d6
commit
134800317a
7 changed files with 89 additions and 8 deletions
|
@ -2459,7 +2459,7 @@ Argument START is where to start searching from."
|
|||
(save-excursion
|
||||
(when start (goto-char start))
|
||||
(matlab-with-current-command
|
||||
(goto-char (point-max))
|
||||
(goto-char (point-at-eol))
|
||||
|
||||
;; If in a comment, move out of it first.
|
||||
(when (matlab-backward-up-string-or-comment)
|
||||
|
|
2
tests/empty.m
Normal file
2
tests/empty.m
Normal file
|
@ -0,0 +1,2 @@
|
|||
% Empty M file.
|
||||
% %%%empty guess
|
|
@ -1,6 +1,7 @@
|
|||
% >>1
|
||||
classdef (abstract) mclass < handle & matlab.mixin.SetGetExactNames % #7#
|
||||
% !!0
|
||||
% %%% class class
|
||||
|
||||
% >>11
|
||||
properties (Access='public') % #2#
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
|
||||
(defun metest-all-syntax-tests ()
|
||||
"Run all the syntax tests in this file."
|
||||
(metest-end-detect-test)
|
||||
(metest-comment-string-syntax-test)
|
||||
(metest-sexp-counting-test)
|
||||
(metest-sexp-traversal-test)
|
||||
|
@ -49,17 +50,47 @@
|
|||
(metest-parse-test)
|
||||
)
|
||||
|
||||
(defvar met-end-detect-files '("empty.m" "stringtest.m" "mfuncnoend.m" "mfuncends.m" "mclass.m" )
|
||||
"List of files for running end detection tests on.")
|
||||
|
||||
(defun metest-end-detect-test ()
|
||||
"Run a test to make sure we correctly detect the state of managing 'end'."
|
||||
(dolist (F met-end-detect-files)
|
||||
(let ((buf (metest-find-file F))
|
||||
(cnt 0))
|
||||
(with-current-buffer buf
|
||||
(goto-char (point-min))
|
||||
(message ">> Checking END detection in %S" (current-buffer))
|
||||
(if (re-search-forward "%%%\\s-*\\(\\w+\\)\\s-+\\(\\w+\\)$" nil t)
|
||||
(let ((st-expect (intern (match-string-no-properties 1)))
|
||||
(end-expect (intern (match-string-no-properties 2)))
|
||||
(st-actual (matlab-guess-script-type))
|
||||
(end-actual (matlab-do-functions-have-end-p)))
|
||||
(unless (eq st-actual st-expect)
|
||||
(error "Script type detection failure: Expected %s but found %s"
|
||||
st-expect st-actual))
|
||||
(unless (eq end-actual end-expect)
|
||||
(error "Script end detection failure: Expected %s but found %s"
|
||||
end-expect end-actual))
|
||||
|
||||
(message "<< Script type and end detection passed: %s, %s" st-actual end-actual)
|
||||
)
|
||||
;; No expected values found in the file.
|
||||
(error "Test file did not include expected script-type cookie")
|
||||
))))
|
||||
(message ""))
|
||||
|
||||
(defvar met-stringtest-files '("stringtest.m")
|
||||
"List of files for running string tests on.")
|
||||
|
||||
(defun metest-comment-string-syntax-test ()
|
||||
"Run a test to make sure string nd comment highlighting work."
|
||||
(dolist (F met-stringtest-files)
|
||||
(let ((buf (find-file-noselect (expand-file-name F met-testfile-path)))
|
||||
(let ((buf (metest-find-file F))
|
||||
(cnt 0))
|
||||
(with-current-buffer buf
|
||||
(goto-char (point-min))
|
||||
(message ">> Starting search loop in %S" (current-buffer))
|
||||
(message ">> Starting string/comment detect loop in %S" (current-buffer))
|
||||
(while (re-search-forward "#\\([csveb]\\)#" nil t)
|
||||
(goto-char (match-end 1))
|
||||
(let ((md (match-data))
|
||||
|
@ -100,7 +131,7 @@
|
|||
(defun metest-sexp-counting-test ()
|
||||
"Run a test to make sure string and comment highlighting work."
|
||||
(dolist (F met-sexptest-files)
|
||||
(let ((buf (find-file-noselect (expand-file-name F met-testfile-path)))
|
||||
(let ((buf (metest-find-file F))
|
||||
(cnt 0))
|
||||
(with-current-buffer buf
|
||||
(goto-char (point-min))
|
||||
|
@ -140,7 +171,7 @@
|
|||
(defun metest-sexp-traversal-test ()
|
||||
"Run a test to make sure high level block navigation works."
|
||||
(dolist (F met-sexptest-files)
|
||||
(let ((buf (find-file-noselect (expand-file-name F met-testfile-path)))
|
||||
(let ((buf (metest-find-file F))
|
||||
(cnt 0))
|
||||
(with-current-buffer buf
|
||||
(goto-char (point-min))
|
||||
|
@ -173,13 +204,13 @@
|
|||
(message ""))
|
||||
|
||||
|
||||
(defvar met-indents-files '("indents.m" "mclass.m" "blocks.m")
|
||||
(defvar met-indents-files '("indents.m" "mclass.m" "blocks.m" "mfuncends.m")
|
||||
"List of files for running syntactic indentation tests.")
|
||||
|
||||
(defun metest-indents-test ()
|
||||
"Run a test to make sure high level block navigation works."
|
||||
(dolist (F met-indents-files)
|
||||
(let ((buf (find-file-noselect (expand-file-name F met-testfile-path)))
|
||||
(let ((buf (metest-find-file F))
|
||||
(cnt 0))
|
||||
(with-current-buffer buf
|
||||
(goto-char (point-min))
|
||||
|
@ -207,7 +238,7 @@
|
|||
"Run the semantic parsing test to make sure the parse works."
|
||||
|
||||
(dolist (F met-parser-files)
|
||||
(let ((buf (find-file-noselect (expand-file-name F met-testfile-path)))
|
||||
(let ((buf (metest-find-file F))
|
||||
exp act
|
||||
(cnt 0))
|
||||
(with-current-buffer buf
|
||||
|
@ -252,6 +283,14 @@
|
|||
|
||||
)
|
||||
|
||||
(defun metest-find-file (file)
|
||||
"Read FILE into a buffer and return it.
|
||||
Do error checking to provide easier debugging."
|
||||
(let ((F (expand-file-name file met-testfile-path)))
|
||||
(unless (file-exists-p F)
|
||||
(error "Test file %s does not exist in %s" file met-testfile-path))
|
||||
(find-file-noselect F)))
|
||||
|
||||
(provide 'metest)
|
||||
|
||||
;;; metest.el ends here
|
||||
|
|
22
tests/mfuncends.m
Normal file
22
tests/mfuncends.m
Normal file
|
@ -0,0 +1,22 @@
|
|||
function mfuncends()
|
||||
% Test function that has ends for each function.
|
||||
%
|
||||
% Used with test harness to validate indentation and end detection.
|
||||
%
|
||||
% %%%function function
|
||||
|
||||
fcn_call(); %!!4
|
||||
|
||||
if condition %!!4
|
||||
fcn_call(); %!!8
|
||||
end %!!4
|
||||
|
||||
end%!!0 - also no space after end
|
||||
|
||||
function fcn_call(inp) %!!0
|
||||
|
||||
while inp > 0 %!!4
|
||||
fcn_call(inp-1); %!!8
|
||||
end %!!4
|
||||
|
||||
end %!!0
|
15
tests/mfuncnoend.m
Normal file
15
tests/mfuncnoend.m
Normal file
|
@ -0,0 +1,15 @@
|
|||
function mfuncnoend
|
||||
% A function file that does not have ends at the end of functions.
|
||||
%
|
||||
% %%% function nil
|
||||
|
||||
fcn_call(1)
|
||||
|
||||
|
||||
function fcn_call(idx)
|
||||
|
||||
if idx > 0
|
||||
fcn_call(ix-1)
|
||||
end
|
||||
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
%% Tests for char vector and string handling.
|
||||
%
|
||||
% #c#
|
||||
%
|
||||
% %%%script script
|
||||
|
||||
%% Basic strings
|
||||
|
||||
|
|
Loading…
Reference in a new issue