diff options
Diffstat (limited to 'test/lisp/term-tests.el')
-rw-r--r-- | test/lisp/term-tests.el | 164 |
1 files changed, 162 insertions, 2 deletions
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el index c2b90dea604..33ed006cf8b 100644 --- a/test/lisp/term-tests.el +++ b/test/lisp/term-tests.el @@ -51,6 +51,7 @@ (buffer-substring-no-properties (point-min) (point-max)))))) (ert-deftest term-simple-lines () + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) (let ((str "\ first line\r next line\r\n")) @@ -58,12 +59,14 @@ next line\r\n")) (replace-regexp-in-string "\r" "" str))))) (ert-deftest term-carriage-return () + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) (let ((str "\ first line\r_next line\r\n")) (should (equal (term-test-screen-from-input 40 12 str) "_next line\n")))) (ert-deftest term-line-wrap () + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) (should (string-match-p ;; Don't be strict about trailing whitespace. "\\`a\\{40\\}\na\\{20\\} *\\'" @@ -75,6 +78,7 @@ first line\r_next line\r\n")) (list str str)))))) (ert-deftest term-cursor-movement () + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) ;; Absolute positioning. (should (equal "ab\ncd" (term-test-screen-from-input @@ -89,6 +93,13 @@ first line\r_next line\r\n")) "\e[2;1Hc" "\e[1;2Hb" "\e[1;1Ha") "" t)))) + (should (equal "abcde j" + (term-test-screen-from-input + 10 12 '("abcdefghij" + "\e[H" ;move back to point-min + "abcde" + " j")))) + ;; Relative positioning. (should (equal "ab\ncd" (term-test-screen-from-input @@ -98,6 +109,7 @@ first line\r_next line\r\n")) "\e[D\e[Da"))))) (ert-deftest term-scrolling-region () + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) (should (equal "\ line3 line4 @@ -112,9 +124,144 @@ line3\r line4\r line5\r line6\r -")))) +"))) + + ;; test reverse scrolling + (should (equal "line1 +line7 +line6 +line2 +line5" + (term-test-screen-from-input 40 5 + '("\e[0;0H" + "\e[J" + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[2;4r" + "\e[2;0H" + "\e[2;0H" + "\eMline6" + "\e[2;0H" + "\eMline7")))) + + ;; test scrolling down + (should (equal "line1 +line3 +line4 +line7 +line5" + (term-test-screen-from-input 40 5 + '("\e[0;0H" + "\e[J" + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[2;4r" + "\e[2;0H" + "\e[4;5H" + "\n\rline7")))) + + ;; setting the scroll region end beyond the max height should not + ;; turn on term-scroll-with-delete + (should (equal "line1 +line2 +line3 +line4 +line5 +line6 +line7" + (term-test-screen-from-input 40 5 + '("\e[1;10r" + "line1\r +line2\r +line3\r +line4\r +line5\r +line6\r +line7")))) + + + ;; resetting the terminal should set the scroll region end to (1- term-height). + (should (equal " +line1 +line2 +line3 +line4 +" + (term-test-screen-from-input 40 5 + '("\e[1;10r" + "\ec" ;reset + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[1;1H" + "\e[L")))) + + ;; scroll region should be limited to the (1- term-height). Note, + ;; this fixes an off by one error when comparing the scroll region + ;; end with term-height. + (should (equal " +line1 +line2 +line3 +line4 +" + (term-test-screen-from-input 40 5 + '("\e[1;6r" + "line1\r +line2\r +line3\r +line4\r +line5" + "\e[1;1H" ;go back to home + "\e[L" ;insert a new line at the top + )))) + + ;; setting the scroll region to the entire height should not turn on + ;; term-scroll-with-delete + (should (equal "line1 +line2 +line3 +line4 +line5 +line6" + (term-test-screen-from-input 40 5 + '("\e[1;5r" + "line1\r +line2\r +line3\r +line4\r +line5\r +line6")))) + + ;; reset should reset term-scroll-with-delete + (should (equal "line1 +line2 +line3 +line4 +line5 +line6 +line7" + (term-test-screen-from-input 40 5 + '("\e[2;5r" ;set the region + "\ec" ;reset + "line1\r +line2\r +line3\r +line4\r +line5\r +line6\r +line7"))))) (ert-deftest term-set-directory () + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) (let ((term-ansi-at-user (user-real-login-name))) (should (equal (term-test-screen-from-input 40 12 "\eAnSiTc /foo/\n" 'default-directory) @@ -124,9 +271,23 @@ line6\r 40 12 (list "\eAnSiTc /f" "oo/\n") 'default-directory) "/foo/")))) +(ert-deftest term-line-wrapping-then-motion () + "Make sure we reset the line-wrapping state after moving cursor. +A real-life example is the default zsh prompt which writes spaces +to the end of line (triggering line-wrapping state), and then +sends a carriage return followed by another space to overwrite +the first character of the line." + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) + (let* ((width 10) + (strs (list "x" (make-string (1- width) ?_) + "\r_"))) + (should (equal (term-test-screen-from-input width 12 strs) + (make-string width ?_))))) + (ert-deftest term-to-margin () "Test cursor movement at the scroll margin. This is a reduced example from GNU nano's initial screen." + (skip-unless (not (memq system-type '(windows-nt ms-dos)))) (let* ((width 10) (x (make-string width ?x)) (y (make-string width ?y))) @@ -144,7 +305,6 @@ This is a reduced example from GNU nano's initial screen." `("\e[1;3r" "\e[2;1H" ,x "\r\e[1A" ,y)) (concat y "\n" x))))) - (provide 'term-tests) ;;; term-tests.el ends here |