|
| 1 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 | +;; |
| 3 | +;; MODULE : 1002_1.scm |
| 4 | +;; DESCRIPTION : Integration tests for startup tab recent documents API |
| 5 | +;; COPYRIGHT : (C) 2026 Yuki Lu |
| 6 | +;; |
| 7 | +;; This software falls under the GNU general public license version 3 or later. |
| 8 | +;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE |
| 9 | +;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. |
| 10 | +;; |
| 11 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 12 | + |
| 13 | +(import (liii check)) |
| 14 | + |
| 15 | +(check-set-mode! 'report-failed) |
| 16 | + |
| 17 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 18 | +;; Helpers |
| 19 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 20 | + |
| 21 | +(define (save-recent-docs) |
| 22 | + (startup-tab-get-recent-docs)) |
| 23 | + |
| 24 | +(define (restore-recent-docs docs) |
| 25 | + (startup-tab-clear-all-recent) |
| 26 | + (for-each startup-tab-add-recent-doc docs)) |
| 27 | + |
| 28 | +;; 比较路径时忽略平台差异(url->system 可能在 Windows 上转换斜杠) |
| 29 | +(define (path-has-filename? path name) |
| 30 | + (let ((len-path (string-length path)) |
| 31 | + (len-name (string-length name))) |
| 32 | + (and (>= len-path len-name) |
| 33 | + (let ((start (- len-path len-name))) |
| 34 | + (and (or (== start 0) |
| 35 | + (let ((ch (string-ref path (- start 1)))) |
| 36 | + (or (== ch #\/) (== ch #\\)))) |
| 37 | + (== (substring path start len-path) name)))))) |
| 38 | + |
| 39 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 40 | +;; Tests |
| 41 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 42 | + |
| 43 | +(define (test-get-recent-docs-returns-list) |
| 44 | + (let ((docs (startup-tab-get-recent-docs))) |
| 45 | + (check (list? docs) => #t))) |
| 46 | + |
| 47 | +(define (test-add-recent-doc) |
| 48 | + (let ((original (save-recent-docs))) |
| 49 | + (startup-tab-clear-all-recent) |
| 50 | + (check (length (startup-tab-get-recent-docs)) => 0) |
| 51 | + |
| 52 | + ;; 使用简单文件名避免 url->system 的平台差异 |
| 53 | + (startup-tab-add-recent-doc "test-doc-1.tmu") |
| 54 | + (let ((docs (startup-tab-get-recent-docs))) |
| 55 | + (check (length docs) => 1) |
| 56 | + (check (path-has-filename? (car docs) "test-doc-1.tmu") => #t)) |
| 57 | + |
| 58 | + ;; 添加第二个文档 |
| 59 | + (startup-tab-add-recent-doc "test-doc-2.tmu") |
| 60 | + (let ((docs (startup-tab-get-recent-docs))) |
| 61 | + (check (length docs) => 2) |
| 62 | + ;; 最近添加的应在最前面 |
| 63 | + (check (path-has-filename? (car docs) "test-doc-2.tmu") => #t)) |
| 64 | + |
| 65 | + ;; 重新添加已有文档应将其移到最前面 |
| 66 | + (startup-tab-add-recent-doc "test-doc-1.tmu") |
| 67 | + (let ((docs (startup-tab-get-recent-docs))) |
| 68 | + (check (length docs) => 2) |
| 69 | + (check (path-has-filename? (car docs) "test-doc-1.tmu") => #t)) |
| 70 | + |
| 71 | + (restore-recent-docs original))) |
| 72 | + |
| 73 | +(define (test-clear-recent-doc) |
| 74 | + (let ((original (save-recent-docs))) |
| 75 | + (startup-tab-clear-all-recent) |
| 76 | + (startup-tab-add-recent-doc "test-doc-a.tmu") |
| 77 | + (startup-tab-add-recent-doc "test-doc-b.tmu") |
| 78 | + (startup-tab-add-recent-doc "test-doc-c.tmu") |
| 79 | + |
| 80 | + (startup-tab-clear-recent-doc "test-doc-b.tmu") |
| 81 | + (let ((docs (startup-tab-get-recent-docs))) |
| 82 | + (check (length docs) => 2) |
| 83 | + (check (path-has-filename? (car docs) "test-doc-c.tmu") => #t) |
| 84 | + (check (path-has-filename? (cadr docs) "test-doc-a.tmu") => #t)) |
| 85 | + |
| 86 | + ;; 清除不存在的文档不应崩溃 |
| 87 | + (startup-tab-clear-recent-doc "non-existent.tmu") |
| 88 | + (check (length (startup-tab-get-recent-docs)) => 2) |
| 89 | + |
| 90 | + (restore-recent-docs original))) |
| 91 | + |
| 92 | +(define (test-clear-all-recent) |
| 93 | + (let ((original (save-recent-docs))) |
| 94 | + (startup-tab-add-recent-doc "test-doc-x.tmu") |
| 95 | + (startup-tab-clear-all-recent) |
| 96 | + (check (length (startup-tab-get-recent-docs)) => 0) |
| 97 | + (restore-recent-docs original))) |
| 98 | + |
| 99 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 100 | +;; Entry point |
| 101 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 102 | + |
| 103 | +(tm-define (test_1002_1) |
| 104 | + (test-get-recent-docs-returns-list) |
| 105 | + (test-add-recent-doc) |
| 106 | + (test-clear-recent-doc) |
| 107 | + (test-clear-all-recent) |
| 108 | + (check-report)) |
0 commit comments