branch: externals/matlab-mode
commit 8eef70d975e35335b21040d504928126d8b6672d
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: add forward-page/backward-page test
---
matlab-ts-mode.el | 1 +
tests/t-utils.el | 7 +-
tests/test-matlab-ts-mode-page-files/page_basic.m | 16 +++++
.../page_basic_expected.org | 79 ++++++++++++++++++++++
tests/test-matlab-ts-mode-page.el | 58 ++++++++++++++++
5 files changed, 159 insertions(+), 2 deletions(-)
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index 53bfff6128..41458dba3c 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -692,6 +692,7 @@ expression."
(setq-local comment-start-skip "%\\s-+")
;; Setup `forward-page' and `backward-page' to use ^L or "%% heading"
comments
+ ;; See: ./tests/test-matlab-ts-mode-page.el
(setq-local page-delimiter "^\\(\f\\|%%\\(\\s-\\|\n\\)\\)")
;; Setup `fill-paragraph'
diff --git a/tests/t-utils.el b/tests/t-utils.el
index a81bc02095..dc210fe888 100644
--- a/tests/t-utils.el
+++ b/tests/t-utils.el
@@ -378,8 +378,11 @@ for this example is:
(condition-case err
(progn
(eval-last-sexp nil)
- (setq got (concat got t-utils--xr-impl-result)))
- (error (setq t-utils--xr-impl-result-active nil)
+ (setq got (concat got t-utils--xr-impl-result)
+ t-utils--xr-impl-result-active nil
+ t-utils--xr-impl-result nil))
+ (error (setq t-utils--xr-impl-result-active nil
+ t-utils--xr-impl-result nil)
(signal (car err) (cdr err))))
;; look for next (t-utils-xr COMMANDS)
(goto-char xr-end-point)))
diff --git a/tests/test-matlab-ts-mode-page-files/page_basic.m
b/tests/test-matlab-ts-mode-page-files/page_basic.m
new file mode 100644
index 0000000000..0e66af0b8a
--- /dev/null
+++ b/tests/test-matlab-ts-mode-page-files/page_basic.m
@@ -0,0 +1,16 @@
+% -*- matlab-ts -*-
+% Test forward/backward page keybindings:
+% (t-utils-xr (goto-char (point-min)) "C-x ]" "C-x ]" "C-x [" "C-x [")
+
+% Do similar using the underlying functions:
+% (t-utils-xr (goto-char (point-min)) (forward-page) (forward-page)
(backward-page) (backward-page))
+
+%% Section 1
+
+x = 1;
+y = 2;
+
+%% Section 2
+
+z = x+y;
+
diff --git a/tests/test-matlab-ts-mode-page-files/page_basic_expected.org
b/tests/test-matlab-ts-mode-page-files/page_basic_expected.org
new file mode 100644
index 0000000000..a8c0954826
--- /dev/null
+++ b/tests/test-matlab-ts-mode-page-files/page_basic_expected.org
@@ -0,0 +1,79 @@
+#+startup: showall
+
+* Executing commands from page_basic.m:3:2:
+
+ (t-utils-xr (goto-char (point-min)) "C-x ]" "C-x ]" "C-x [" "C-x [")
+
+- Invoking : (goto-char (point-min))
+ Start point : 133
+ Moved to point: 1
+ : 1:0: % -*- matlab-ts -*-
+ : ^
+ No buffer modifications
+
+- Invoking : "C-x ]" = forward-page
+ Start point : 1
+ Moved to point: 285
+ : 8:3: %% Section 1
+ : ^
+ No buffer modifications
+
+- Invoking : "C-x ]" = forward-page
+ Start point : 285
+ Moved to point: 314
+ : 13:3: %% Section 2
+ : ^
+ No buffer modifications
+
+- Invoking : "C-x [" = backward-page
+ Start point : 314
+ Moved to point: 285
+ : 8:3: %% Section 1
+ : ^
+ No buffer modifications
+
+- Invoking : "C-x [" = backward-page
+ Start point : 285
+ Moved to point: 1
+ : 1:0: % -*- matlab-ts -*-
+ : ^
+ No buffer modifications
+
+* Executing commands from page_basic.m:6:2:
+
+ (t-utils-xr (goto-char (point-min)) (forward-page) (forward-page)
(backward-page) (backward-page))
+
+- Invoking : (goto-char (point-min))
+ Start point : 280
+ Moved to point: 1
+ : 1:0: % -*- matlab-ts -*-
+ : ^
+ No buffer modifications
+
+- Invoking : (forward-page)
+ Start point : 1
+ Moved to point: 285
+ : 8:3: %% Section 1
+ : ^
+ No buffer modifications
+
+- Invoking : (forward-page)
+ Start point : 285
+ Moved to point: 314
+ : 13:3: %% Section 2
+ : ^
+ No buffer modifications
+
+- Invoking : (backward-page)
+ Start point : 314
+ Moved to point: 285
+ : 8:3: %% Section 1
+ : ^
+ No buffer modifications
+
+- Invoking : (backward-page)
+ Start point : 285
+ Moved to point: 1
+ : 1:0: % -*- matlab-ts -*-
+ : ^
+ No buffer modifications
diff --git a/tests/test-matlab-ts-mode-page.el
b/tests/test-matlab-ts-mode-page.el
new file mode 100644
index 0000000000..9d5e6eef81
--- /dev/null
+++ b/tests/test-matlab-ts-mode-page.el
@@ -0,0 +1,58 @@
+;;; test-matlab-ts-mode-page.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-page-files/NAME.m comparing against
+;; ./test-matlab-ts-mode-page-files/NAME_expected.org
+;;
+
+;;; Code:
+
+(require 't-utils)
+(require 'matlab-ts-mode)
+
+(cl-defun test-matlab-ts-mode-page (&optional m-file)
+ "Test defun movement using ./test-matlab-ts-mode-page-files/NAME.m.
+Using ./test-matlab-ts-mode-page-files/NAME.m, compare comment
+keybindings against
+./test-matlab-ts-mode-page-files/NAME_expected.org. If M-FILE is
+not provided, loop comparing all
+./test-matlab-ts-mode-page-files/NAME.m files.
+
+To add a test, create
+ ./test-matlab-ts-mode-page-files/NAME.m
+and run this function. The baseline is saved for you as
+ ./test-matlab-ts-mode-page-files/NAME_expected.org~
+after validating it, rename it to
+ ./test-matlab-ts-mode-page-files/NAME_expected.org"
+
+ (let ((test-name "test-matlab-ts-mode-page"))
+
+ (when (not (t-utils-is-treesit-available 'matlab test-name))
+ (cl-return-from test-matlab-ts-mode-font-lock))
+
+ (let ((m-files (t-utils-get-files (concat test-name "-files") "\\.m$" nil
m-file)))
+ (t-utils-test-xr test-name m-files)))
+ "success")
+
+(provide 'test-matlab-ts-mode-page)
+;;; test-matlab-ts-mode-page.el ends here