branch: externals/matlab-mode
commit 0d16f274fe7b48315c2216c61e0256f99d5eddb2
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    matlab-ts-mode: add tests/test-matlab-ts-mode-mfile-type.el
---
 .../mfile_type_classdef.m                          | 10 ++++
 .../mfile_type_classdef_expected.org               | 14 +++++
 .../mfile_type_empty.m                             |  4 ++
 .../mfile_type_empty_expected.org                  | 14 +++++
 .../mfile_type_function.m                          |  7 +++
 .../mfile_type_function_expected.org               | 14 +++++
 .../mfile_type_script.m                            | 10 ++++
 .../mfile_type_script_expected.org                 | 14 +++++
 tests/test-matlab-ts-mode-mfile-type.el            | 68 ++++++++++++++++++++++
 9 files changed, 155 insertions(+)

diff --git a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_classdef.m 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_classdef.m
new file mode 100644
index 0000000000..49f6cb06f4
--- /dev/null
+++ b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_classdef.m
@@ -0,0 +1,10 @@
+% -*- matlab-ts -*-
+
+% (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
+classdef mfile_type_classdef
+    properties
+        p1
+        p2
+    end
+end
diff --git 
a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_classdef_expected.org 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_classdef_expected.org
new file mode 100644
index 0000000000..0d66184a1d
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_classdef_expected.org
@@ -0,0 +1,14 @@
+#+startup: showall
+
+* Executing commands from mfile_type_classdef.m:3:2:
+
+  (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
+- Invoking      : (print (format "mfile-type: %S" 
(matlab-ts-mode--mfile-type)))
+  Start point   :   99
+  No point movement
+  standard-output:
+  #+begin_example
+mfile-type: class
+  #+end_example
+  No buffer modifications
diff --git a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_empty.m 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_empty.m
new file mode 100644
index 0000000000..e765acdd0e
--- /dev/null
+++ b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_empty.m
@@ -0,0 +1,4 @@
+% -*- matlab-ts -*-
+
+% (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
diff --git 
a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_empty_expected.org 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_empty_expected.org
new file mode 100644
index 0000000000..839ea72300
--- /dev/null
+++ b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_empty_expected.org
@@ -0,0 +1,14 @@
+#+startup: showall
+
+* Executing commands from mfile_type_empty.m:3:2:
+
+  (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
+- Invoking      : (print (format "mfile-type: %S" 
(matlab-ts-mode--mfile-type)))
+  Start point   :   99
+  No point movement
+  standard-output:
+  #+begin_example
+mfile-type: empty
+  #+end_example
+  No buffer modifications
diff --git a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_function.m 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_function.m
new file mode 100644
index 0000000000..ea97362f5a
--- /dev/null
+++ b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_function.m
@@ -0,0 +1,7 @@
+% -*- matlab-ts -*-
+
+% (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
+function mfile_type_function(a)
+    disp(a);
+end
diff --git 
a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_function_expected.org 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_function_expected.org
new file mode 100644
index 0000000000..7c573948c8
--- /dev/null
+++ 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_function_expected.org
@@ -0,0 +1,14 @@
+#+startup: showall
+
+* Executing commands from mfile_type_function.m:3:2:
+
+  (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
+- Invoking      : (print (format "mfile-type: %S" 
(matlab-ts-mode--mfile-type)))
+  Start point   :   99
+  No point movement
+  standard-output:
+  #+begin_example
+mfile-type: function
+  #+end_example
+  No buffer modifications
diff --git a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_script.m 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_script.m
new file mode 100644
index 0000000000..429769ec6d
--- /dev/null
+++ b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_script.m
@@ -0,0 +1,10 @@
+% -*- matlab-ts -*-
+
+% (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
+a = 1;
+b = myfcn(a);
+
+function y=myfcn(x)
+    y = 2 * x;
+end  
diff --git 
a/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_script_expected.org 
b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_script_expected.org
new file mode 100644
index 0000000000..cce88cc13c
--- /dev/null
+++ b/tests/test-matlab-ts-mode-mfile-type-files/mfile_type_script_expected.org
@@ -0,0 +1,14 @@
+#+startup: showall
+
+* Executing commands from mfile_type_script.m:3:2:
+
+  (t-utils-xr (print (format "mfile-type: %S" (matlab-ts-mode--mfile-type))))
+
+- Invoking      : (print (format "mfile-type: %S" 
(matlab-ts-mode--mfile-type)))
+  Start point   :   99
+  No point movement
+  standard-output:
+  #+begin_example
+mfile-type: script
+  #+end_example
+  No buffer modifications
diff --git a/tests/test-matlab-ts-mode-mfile-type.el 
b/tests/test-matlab-ts-mode-mfile-type.el
new file mode 100644
index 0000000000..6133a228c6
--- /dev/null
+++ b/tests/test-matlab-ts-mode-mfile-type.el
@@ -0,0 +1,68 @@
+;;; test-matlab-ts-mode-mfile-type.el --- -*- lexical-binding: t -*-
+;;
+;; Copyright 2025 Free Software Foundation, Inc.
+;;
+;; This program 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, or (at your option)
+;; any later version.
+;;
+;; This program 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; see the file COPYING.  If not, write to
+;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;;
+
+;;; Commentary:
+;;
+;; Validate matlab-ts-mode indent.
+;; Load ../matlab-ts-mode.el via require and run indent tests using
+;; ./test-matlab-ts-mode-mfile-type-files/NAME.m comparing against
+;; ./test-matlab-ts-mode-mfile-type-files/NAME_expected.org
+;;
+
+;;; Code:
+
+(require 't-utils)
+(require 'matlab-ts-mode)
+
+(defvar test-matlab-ts-mode-mfile-type--file nil)
+
+(defun test-matlab-ts-mode-mfile-type--file (m-file)
+  "Test an individual M-FILE.
+This is provided for debugging.
+  M-: (test-matlab-ts-mode-mfile-type--file
+      \"test-matlab-ts-mode-mfile-type-files/M-FILE\")"
+  (let ((test-matlab-ts-mode-mfile-type--file m-file))
+    (ert-run-tests-interactively "test-matlab-ts-mode-mfile-type")))
+
+(ert-deftest test-matlab-ts-mode-mfile-type ()
+  "Test `matlab-ts-mode--mfile-type'.
+Using ./test-matlab-ts-mode-mfile-type-files/NAME.m, which contain
+`t-utils-xr' commands in comments that run `matlab-ts-mode--mfile-type'
+to get the mfile type.  This is compared against baselines:
+./test-matlab-ts-mode-mfile-type-files/NAME_expected.org.  This loops on
+all ./test-matlab-ts-mode-mfile-type-files/NAME.m files.
+
+To add a test, create
+  ./test-matlab-ts-mode-mfile-type-files/NAME.m
+and run this function.  The baseline is saved for you as
+  ./test-matlab-ts-mode-mfile-type-files/NAME_expected.org~
+after validating it, rename it to
+  ./test-matlab-ts-mode-mfile-type-files/NAME_expected.org"
+
+  (let* ((test-name "test-matlab-ts-mode-mfile-type")
+         (m-files (t-utils-get-files
+                   test-name
+                   (rx ".m" eos)
+                   nil
+                   test-matlab-ts-mode-mfile-type--file)))
+    (t-utils-error-if-no-treesit-for 'matlab test-name)
+    (t-utils-test-xr test-name m-files)))
+
+(provide 'test-matlab-ts-mode-mfile-type)
+;;; test-matlab-ts-mode-mfile-type.el ends here

Reply via email to