branch: externals/matlab-mode
commit 564e8e12baded7e81d451328c1545372ef4d564a
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: add test that exercises end statements
---
tests/t-utils.el | 9 ++-
.../indent_lots_of_end_words.m | 69 ++++++++++++++++++++++
.../indent_lots_of_end_words_expected.m | 69 ++++++++++++++++++++++
.../indent_lots_of_end_words_expected_msgs.m | 69 ++++++++++++++++++++++
4 files changed, 215 insertions(+), 1 deletion(-)
diff --git a/tests/t-utils.el b/tests/t-utils.el
index 6077915193..076d6b63d6 100644
--- a/tests/t-utils.el
+++ b/tests/t-utils.el
@@ -1374,14 +1374,21 @@ See `t-utils-test-indent' for LINE-MANIPULATOR."
(set-buffer-file-coding-system 'utf-8-unix)
(funcall lang-file-mode)
- ;; Insert lines one a time and indent via newline (C-m)
+ ;; tree-sitter requires a terminating newline to get parse tree right
+ (insert "\n")
+ (goto-char (point-min))
+ ;; Insert lines one a time and indent via newline (C-m)
(dolist (line lines)
(setq line (string-trim line))
(when (not (string= line ""))
(insert line))
(call-interactively #'newline))
+ ;; Remove the newline we inserted at start
+ (goto-char (point-max))
+ (delete-char -1)
+
(let ((typing-got (buffer-substring (point-min) (point-max)))
error-msg)
(set-buffer-modified-p nil)
diff --git a/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words.m
b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words.m
new file mode 100644
index 0000000000..b27f4895ec
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words.m
@@ -0,0 +1,69 @@
+% -*- matlab-ts -*-
+
+function a=indent_lots_of_end_words
+ a=bar();
+end % end foo_end_comment
+
+function B=bar
+
+ if foo
+ A = 1;
+ end % end of iff
+
+ B = A(1:end); %#ok
+
+ if foo
+ C = "this is the end of the line";
+
+ end; D = "string end string";
+
+ E = [ D C];
+
+ if bar
+
+ A = E;
+
+ end; B = A(1:end);
+
+ E = B;
+
+ if baz
+
+ A = C;
+
+ end; B = [ 1 2 ... is this the end?
+ 3 4 ];
+
+ if foo
+
+ A = E;
+
+ end ... the other end
+
+ B = [ B A ];
+
+ % Multi-ends
+
+ if foo %#ok
+ if bar %#ok
+ if baz
+
+ A = B;
+
+ else
+
+ end; end; end % comment end thing
+
+ B = goo(A);
+
+end
+
+function result = goo(b)
+
+ result=1;
+ % see xyz function
+ % foobar
+ for x = 1:length(b)
+ result = x + result;
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected.m
b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected.m
new file mode 100644
index 0000000000..b27f4895ec
--- /dev/null
+++ b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected.m
@@ -0,0 +1,69 @@
+% -*- matlab-ts -*-
+
+function a=indent_lots_of_end_words
+ a=bar();
+end % end foo_end_comment
+
+function B=bar
+
+ if foo
+ A = 1;
+ end % end of iff
+
+ B = A(1:end); %#ok
+
+ if foo
+ C = "this is the end of the line";
+
+ end; D = "string end string";
+
+ E = [ D C];
+
+ if bar
+
+ A = E;
+
+ end; B = A(1:end);
+
+ E = B;
+
+ if baz
+
+ A = C;
+
+ end; B = [ 1 2 ... is this the end?
+ 3 4 ];
+
+ if foo
+
+ A = E;
+
+ end ... the other end
+
+ B = [ B A ];
+
+ % Multi-ends
+
+ if foo %#ok
+ if bar %#ok
+ if baz
+
+ A = B;
+
+ else
+
+ end; end; end % comment end thing
+
+ B = goo(A);
+
+end
+
+function result = goo(b)
+
+ result=1;
+ % see xyz function
+ % foobar
+ for x = 1:length(b)
+ result = x + result;
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected_msgs.m
b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected_msgs.m
new file mode 100644
index 0000000000..536020cba0
--- /dev/null
+++
b/tests/test-matlab-ts-mode-indent-files/indent_lots_of_end_words_expected_msgs.m
@@ -0,0 +1,69 @@
+% -*- matlab-ts -*- % <{Matched rule: ((lambda (node parent _bol &rest _)
(and node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+function a=indent_lots_of_end_words % <{Matched rule: ((lambda (node parent
_bol &rest _) (and node (not (string= (treesit-node-type node)
"line_continuation")) (equal (treesit-node-type parent) "source_file")))
(lambda (_node _parent bol &rest _) (save-excursion (goto-char bol)
(line-beginning-position))) 0)}>
+ a=bar(); % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
+end % end foo_end_comment % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function B=bar % <{Matched rule: ((lambda (node parent _bol &rest _) (and
node (not (string= (treesit-node-type node) "line_continuation")) (equal
(treesit-node-type parent) "source_file"))) (lambda (_node _parent bol &rest _)
(save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+ if foo % <{Matched rule: ((parent-is "\\`function_definition\\'") parent
matlab-ts-mode--set-function-indent-level-for-gp)}>
+ A = 1; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ end % end of iff % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+ B = A(1:end); %#ok % <{Matched rule: ((parent-is "\\`block\\'") parent
0)}>
+
+ if foo % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+ C = "this is the end of the line"; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+
+ end; D = "string end string"; % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+ E = [ D C]; % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+ if bar % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+ A = E; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+
+ end; B = A(1:end); % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+ E = B; % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+ if baz % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+ A = C; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+
+ end; B = [ 1 2 ... is this the end? % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+ 3 4 ]; % <{Matched rule: ((parent-is
"\\`\\(?:function_output\\|row\\)\\'") parent 0)}>
+
+ if foo % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+ A = E; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+
+ end ... the other end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+ B = [ B A ]; % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+ % Multi-ends % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+ if foo %#ok % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+ if bar %#ok % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ if baz % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+
+ A = B; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+
+ else % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+ end; end; end % comment end thing % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+ B = goo(A); % <{Matched rule: ((parent-is "\\`block\\'") parent 0)}>
+
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+
+function result = goo(b) % <{Matched rule: ((lambda (node parent _bol &rest
_) (and node (not (string= (treesit-node-type node) "line_continuation"))
(equal (treesit-node-type parent) "source_file"))) (lambda (_node _parent bol
&rest _) (save-excursion (goto-char bol) (line-beginning-position))) 0)}>
+
+ result=1; % <{Matched rule: ((parent-is "\\`function_definition\\'")
parent matlab-ts-mode--set-function-indent-level-for-gp)}>
+ % see xyz function % <{Matched rule: ((parent-is "\\`block\\'") parent
0)}>
+ % foobar % <{Matched rule: (matlab-ts-mode--i-block-comment-end-matcher
parent 0)}>
+ for x = 1:length(b) % <{Matched rule: ((parent-is "\\`block\\'") parent
0)}>
+ result = x + result; % <{Matched rule: ((node-is
"\\`\\(?:arguments_statement\\|block\\|e\\(?:num\\(?:eration\\)?\\|vents\\)\\|function_definition\\|methods\\|propert\\(?:ies\\|y\\)\\)\\'")
parent 4)}>
+ end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>
+end % <{Matched rule: ((node-is
"\\`\\(?:catch_clause\\|e\\(?:lse\\(?:\\(?:if\\)?_clause\\)\\|nd\\)\\)\\'")
parent 0)}>